summaryrefslogtreecommitdiff
path: root/shaders/tesseract/357.shader_test
blob: 3089694480db50655ead8e43c7eff6c7354dde32 (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
[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;
        uniform mat4 lightmatrix;
        void main(void)
        {
            gl_Position = lightmatrix * vvertex;
        }
    
[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, tex3 ;
        
        
        
            uniform vec4 lightpos[1];
            uniform vec3 lightcolor[1];
            
            
        
        
            uniform vec3 splitcenter[3];
            uniform vec3 splitbounds[3];
            uniform vec3 splitscale[3];
            uniform vec3 splitoffset[3];
        
        
        uniform vec3 camera;
        uniform mat4 worldmatrix;
        uniform vec4 fogdir;
        uniform vec3 fogcolor;
        uniform vec2 fogdensity;
        uniform vec4 radialfogscale;
        uniform vec2 shadowatlasscale;
        uniform vec4 lightscale;
        
        
        uniform vec3 gdepthscale;
        uniform vec3 gdepthunpackparams;
    
        fragdata(0, fragcolor, vec4)

        

        

        

        void main(void)
        {
            
                #define gfetch(sampler, coords) texture2DRect(sampler, coords)

                #define accumlight(light) fragcolor.rgb = light
                #define accumalpha(alpha) fragcolor.a = alpha
            

            

            
                
                    #define depthvals gfetch(tex3, gl_FragCoord.xy)
                
                
        float depth = depthvals.r;
        
                    vec4 pos = worldmatrix * vec4(gl_FragCoord.xy, depth, 1.0);
                    pos.xyz /= pos.w;
                
    
                
                
                
            

            
                vec3 light = vec3(0.0);
            

            

            
                vec3 light0dir = pos.xyz * lightpos[0].w - lightpos[0].xyz;
                float light0dist2 = dot(light0dir, light0dir);
                if(light0dist2 < 1.0)
                {
                    
                        vec4 normal = gfetch(tex1, gl_FragCoord.xy);
                        
                        normal.xyz = normal.xyz*2.0 - 1.0;
                        
                            #define glowscale normal.a
                        
                    
                    float light0facing = dot(light0dir, normal.xyz);
                    if(light0facing < 0.0)
                    {
                        float light0invdist = inversesqrt(light0dist2); 
                        
                        float light0atten = light0facing * (1.0 - light0invdist);
                        
                            float fogcoord = length(camera - pos.xyz);
                        
                        
                        
                        
                            vec4 diffuse = gfetch(tex0, gl_FragCoord.xy);
                            
                                
                                diffuse.rgb *= glowscale;
                            
                        
                        
                            
                                vec3 camdir = normalize(camera - pos.xyz);
                                float facing = 2.0*dot(normal.xyz, camdir);
                            
                            float light0spec = pow(clamp(light0invdist*(dot(camdir, light0dir) - light0facing*facing), 0.0, 1.0), 16.0) * diffuse.a;
                            light += (diffuse.rgb + light0spec) * lightcolor[0] * light0atten;
                            
                                float foglerp = clamp(exp2(fogcoord*fogdensity.x)*fogdensity.y, 0.0, 1.0);
                                light *= foglerp;
                            
                        
                        
                    }
                }
            
            
                accumlight(light);
                accumalpha(0.0);
            

            
        }