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