Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: data/branches/Shader_HS18/programs/Example/GLSLES/hdr_downscale3x3brightpass.glsles @ 12091

Last change on this file since 12091 was 12091, checked in by wiesep, 5 years ago

Updated programs and adjusted Material to work with GLSL>150

File size: 1.8 KB
Line 
1#version 100
2precision mediump int;
3precision mediump float;
4
5uniform sampler2D inRTT;
6uniform sampler2D inLum;
7uniform vec2 texelSize;
8
9varying vec2 uv;
10const vec4 BRIGHT_LIMITER = vec4(0.6, 0.6, 0.6, 0.0);
11
12const float MIDDLE_GREY = 0.72;
13const float FUDGE = 0.001;
14const float L_WHITE = 1.5;
15
16/** Tone mapping function
17@note Only affects rgb, not a
18@param inColour The HDR colour
19@param lum The scene lumninence
20@returns Tone mapped colour
21*/
22vec4 toneMap(in vec4 inColour, in float lum)
23{
24        // From Reinhard et al
25        // "Photographic Tone Reproduction for Digital Images"
26       
27        // Initial luminence scaling (equation 2)
28    inColour.rgb *= MIDDLE_GREY / (FUDGE + lum);
29
30        // Control white out (equation 4 nom)
31    inColour.rgb *= (1.0 + inColour.rgb / L_WHITE);
32
33        // Final mapping (equation 4 denom)
34        inColour.rgb /= (1.0 + inColour.rgb);
35       
36        return inColour;
37}
38
39void main(void)
40{
41    vec4 accum = vec4(0.0, 0.0, 0.0, 0.0);
42
43    accum += texture2D(inRTT, uv + texelSize * vec2(-1.0, -1.0));
44    accum += texture2D(inRTT, uv + texelSize * vec2( 0.0, -1.0));
45    accum += texture2D(inRTT, uv + texelSize * vec2( 1.0, -1.0));
46    accum += texture2D(inRTT, uv + texelSize * vec2(-1.0,  0.0));
47    accum += texture2D(inRTT, uv + texelSize * vec2( 0.0,  0.0));
48    accum += texture2D(inRTT, uv + texelSize * vec2( 1.0,  0.0));
49    accum += texture2D(inRTT, uv + texelSize * vec2(-1.0,  1.0));
50    accum += texture2D(inRTT, uv + texelSize * vec2( 0.0,  1.0));
51    accum += texture2D(inRTT, uv + texelSize * vec2( 1.0,  1.0));
52   
53        // take average of 9 samples
54        accum *= 0.1111111111111111;
55
56    // Reduce bright and clamp
57    accum = max(vec4(0.0, 0.0, 0.0, 1.0), accum - BRIGHT_LIMITER);
58
59        // Sample the luminence texture
60        vec4 lum = texture2D(inLum, vec2(0.5, 0.5));
61       
62        // Tone map result
63        gl_FragColor = toneMap(accum, lum.r);
64}
Note: See TracBrowser for help on using the repository browser.