69 lines
1.6 KiB
GLSL
69 lines
1.6 KiB
GLSL
// G BUFFER
|
|
|
|
uniform sampler2DRect positionBuffer;
|
|
// - Albedo + Roughness
|
|
uniform sampler2DRect albedoBuffer;
|
|
// - Normal buffer
|
|
uniform sampler2DRect normalBuffer;
|
|
// - Emission + Metallic
|
|
uniform sampler2DRect emissionBuffer;
|
|
|
|
// LIGHT BUFFER
|
|
|
|
uniform sampler2DRect lightBuffer;
|
|
|
|
// FOG PARAMETERS
|
|
|
|
uniform vec3 be;
|
|
uniform vec3 bi;
|
|
uniform vec3 fogColor;
|
|
|
|
// OUTPUT LIGHT
|
|
|
|
layout(location = 0)out vec4 outColor;
|
|
|
|
// FUNCTIONS
|
|
|
|
vec3 applyFog( in vec3 rgb,
|
|
in float distance)
|
|
{
|
|
vec3 extColor = vec3( exp(-distance*be.x), exp(-distance*be.y), exp(-distance*be.z) );
|
|
vec3 insColor = vec3( exp(-distance*bi.x), exp(-distance*bi.y), exp(-distance*bi.z) );
|
|
return rgb*extColor + fogColor*(1.0-insColor);
|
|
}
|
|
|
|
// MAIN PROGRAM
|
|
|
|
void main(void) {
|
|
ivec2 texCoord = ivec2(gl_FragCoord.xy);
|
|
vec3 color = texelFetch(lightBuffer, texCoord).xyz;
|
|
|
|
// gbuffer variables
|
|
/*
|
|
vec3 ambientColor = texelFetch(emissionBuffer, texCoord).rgb;
|
|
vec3 normal = texelFetch(normalBuffer, texCoord).xyz;
|
|
vec4 albedoTexel = texelFetch(albedoBuffer, texCoord);
|
|
vec3 albedo = albedoTexel.rgb;
|
|
float roughness = albedoTexel.a;
|
|
vec4 emissionTexel = texelFetch(emissionBuffer, texCoord);
|
|
vec3 emission = emissionTexel.rgb;
|
|
float metallic = emissionTexel.a;
|
|
*/
|
|
vec4 fragPos = texelFetch(positionBuffer, texCoord);
|
|
|
|
// fog
|
|
color = applyFog(color, -fragPos.z);
|
|
|
|
// HDR tonemapping
|
|
#ifdef HDR_TONEMAPPING
|
|
color = color / (color + vec3(1.0));
|
|
#endif
|
|
|
|
// gamma correct
|
|
#ifdef GAMMA_CORRECT
|
|
color = pow(color, vec3(1.0/2.2));
|
|
#endif
|
|
|
|
outColor = vec4(color, 1.0);
|
|
}
|