[390] | 1 | uniform sampler2D inRTT; |
---|
| 2 | uniform sampler2D inLum; |
---|
| 3 | uniform vec2 texelSize; |
---|
| 4 | |
---|
| 5 | varying vec2 uv; |
---|
| 6 | const vec4 BRIGHT_LIMITER = vec4(0.6, 0.6, 0.6, 0.0); |
---|
| 7 | |
---|
| 8 | // declare external function |
---|
| 9 | vec4 toneMap(in vec4 inColour, in float lum); |
---|
| 10 | |
---|
| 11 | void main(void) |
---|
| 12 | { |
---|
| 13 | vec4 accum = vec4(0.0, 0.0, 0.0, 0.0); |
---|
| 14 | |
---|
| 15 | accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, -1.0)); |
---|
| 16 | accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, -1.0)); |
---|
| 17 | accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, -1.0)); |
---|
| 18 | accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 0.0)); |
---|
| 19 | accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 0.0)); |
---|
| 20 | accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 0.0)); |
---|
| 21 | accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, 1.0)); |
---|
| 22 | accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, 1.0)); |
---|
| 23 | accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, 1.0)); |
---|
| 24 | |
---|
| 25 | // take average of 9 samples |
---|
| 26 | accum *= 0.1111111111111111; |
---|
| 27 | |
---|
| 28 | // Reduce bright and clamp |
---|
| 29 | accum = max(vec4(0.0, 0.0, 0.0, 1.0), accum - BRIGHT_LIMITER); |
---|
| 30 | |
---|
| 31 | // Sample the luminence texture |
---|
| 32 | vec4 lum = texture2D(inLum, vec2(0.5, 0.5)); |
---|
| 33 | |
---|
| 34 | // Tone map result |
---|
| 35 | gl_FragColor = toneMap(accum, lum.r); |
---|
| 36 | |
---|
| 37 | } |
---|