summaryrefslogtreecommitdiff
path: root/shaders/tesseract/142.shader_test
blob: 517256bcfd54c60d54aa4029848cf19e4feab87c (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[require]
GLSL >= 1.10

[vertex shader]
#version 120
#extension GL_ARB_texture_rectangle : enable
#define flat
#define texture2DRectOffset(sampler, coords, offset) texture2DRect(sampler, coords + vec2(offset))
#define shadow2DRectOffset(sampler, coords, offset) shadow2DRect(sampler, coords + vec2(offset))
attribute vec4 vvertex;
    attribute vec2 vtexcoord0, vtexcoord1;
    
        uniform sampler2D tex2;
    
    uniform vec4 hdrparams;
    varying vec2 texcoord0, texcoord1;
    flat varying float lumscale, lumsaturate;
    void main(void)
    {
        gl_Position = vvertex;
        texcoord0 = vtexcoord0; 
        texcoord1 = vtexcoord1;
        float avglum = 4.0 * texture2D(tex2, vec2(0.5, 0.5)).r;
        lumscale = hdrparams.x * -log2(1.0 - clamp(avglum, 0.03, 0.3))/(avglum + 1e-4);
        lumsaturate = -log2(1.0 - hdrparams.y) / lumscale;
    }
  
[fragment shader]
#version 120
#extension GL_ARB_texture_rectangle : enable
#define flat
#define texture2DRectOffset(sampler, coords, offset) texture2DRect(sampler, coords + vec2(offset))
#define shadow2DRectOffset(sampler, coords, offset) shadow2DRect(sampler, coords + vec2(offset))
#define fragdata(loc, name, type)
#define fragcolor gl_FragData[0]
uniform sampler2DRect tex0, tex1;
    
        uniform vec4 hdrparams;
        uniform vec2 hdrgamma;
        varying vec2 texcoord0, texcoord1;
        flat varying float lumscale, lumsaturate;
    
    fragdata(0, fragcolor, vec4)
    void main(void)
    {
        vec3 bloom = texture2DRect(tex1, texcoord1).rgb*hdrparams.w;
        vec3 color = texture2DRect(tex0, texcoord0).rgb*2.0;
        color += bloom;
        
        color *= color;
    
        {
        
        float lum = dot(color, vec3(0.2126, 0.7152, 0.0722));
        color = min(color, lumsaturate);
        color *= (1.0 - exp2(-lum*lumscale)) / (dot(color, vec3(0.2126, 0.7152, 0.0722)) + 1e-4);
    }
        
        color = sqrt(color);
    
        fragcolor.rgb = color;
        
        fragcolor.a = 0.0;
    }