summaryrefslogtreecommitdiffstats
path: root/src/demos/hdr/shaders/cg/tonemap.cg
blob: c3d218fd4d759298989b9221f4aed8a588996199 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Tone mapping pass

#include "hdr.cg"

half4 main(fragin In,
           uniform samplerRECT sceneTex     : TEXUNIT0,
           uniform samplerRECT blurTex      : TEXUNIT1,
           uniform sampler1D   gammaTex     : TEXUNIT2,
           uniform samplerRECT vignetteTex  : TEXUNIT3,
           uniform float       blurAmount,
           uniform float4      windowSize,
           uniform float       exposure
           ) : COLOR
{
    // sum original and blurred image
    half3 c = lerp(texRECT(sceneTex, In.tex0.xy), texRECT_bilinear(blurTex, In.tex1.xy), blurAmount).xyz;

    // exposure
    c = c * half(exposure);

    // vignette effect (makes brightness drop off with distance from center)
//    vignette(c, In.wpos, windowSize.xy, windowSize.zw);
    c = c * texRECT(vignetteTex, In.tex0.xy).rgb;

    // gamma correction
#if 0
    // use math
    c = pow(c, 1.0 / 2.2);
#else
    // use lut
    c.r = h1tex1D(gammaTex, c.r);
    c.g = h1tex1D(gammaTex, c.g);
    c.b = h1tex1D(gammaTex, c.b);
#endif

    return half4(c, 1.0);
}