Debian Codegraph @

prboom2/data/lumps/gls_fuzz.lmp

raw
1 #version 110
2
3 // Sprite texture
4 uniform sampler2D tex;
5 // Fuzz lookup texture
6 uniform sampler2D fuzz;
7 // Texture dimensions
8 uniform vec2 tex_d;
9 // Fuzz texture dimensions
10 uniform vec2 fuzz_d;
11 // Fuzz macro-pixel ratio in terms of window coordinates
12 // If 0, use texture coordinates instead
13 uniform float ratio;
14 // Random seed
15 uniform float seed;
16
17 float random(vec2 n)
18 {
19 return fract(sin(dot(n, vec2(12.9898, 78.233))) * 143758.5453);
20 }
21
22 float darkness(vec2 c)
23 {
24 // Compute random offset based on seed and x coordinate
25 float r = random(vec2(seed, c.x));
26 // Sample fuzz lookup texture at y coordinate plus random offset modulo size
27 return texture2D(fuzz, vec2(fract(c.y / fuzz_d.x + r), 0)).r;
28 }
29
30 void main()
31 {
32 // Ensure fuzz coordinate is identical for each fragment in fuzz macro-pixel
33 vec2 c;
34
35 // Use window coordinates if ratio is non-zero
36 if (ratio != 0.0)
37 // Invert y coordinate since GL convention is opposite Doom's
38 c = floor(vec2(gl_FragCoord.x / ratio, -gl_FragCoord.y / ratio));
39 else
40 // Use texture coordinates
41 c = floor(gl_TexCoord[0].xy * tex_d);
42
43 // [XA] new for 0.25: use darkness as an alpha value so the game can
44 // pass in a non-black gl_color for pain/gamma support in indexed lightmode
45 gl_FragColor = vec4(gl_Color.rgb, texture2D(tex, gl_TexCoord[0].xy).g * darkness(c));
46 }