Debian Codegraph @

Shaders/ws30-water-q1.frag

raw
1 // WS30 FRAGMENT SHADER
2
3 // -*-C++-*-
4 #version 130
5 #extension GL_EXT_texture_array : enable
6
7 varying vec3 normal;
8 varying vec4 ecPosition;
9
10 uniform sampler2D landclass;
11 uniform sampler2DArray atlas;
12 uniform sampler2D perlin;
13
14 // Passed from VPBTechnique, not the Effect
15 uniform float fg_tileWidth;
16 uniform float fg_tileHeight;
17 uniform bool fg_photoScenery;
18 uniform vec4 fg_dimensionsArray[128];
19 uniform vec4 fg_ambientArray[128];
20 uniform vec4 fg_diffuseArray[128];
21 uniform vec4 fg_specularArray[128];
22 uniform vec4 fg_textureLookup1[128];
23 uniform vec4 fg_textureLookup2[128];
24 uniform mat4 fg_zUpTransform;
25 uniform vec3 fg_modelOffset;
26
27 // See include_fog.frag
28 uniform int fogType;
29 vec3 fog_Func(vec3 color, int type);
30
31 // See Shaders/shadows-include.frag
32 float getShadowing();
33
34 // See Shaders/clustered-include.frag
35 vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
36
37 void main()
38 {
39 float NdotL, NdotHV, fogFactor;
40 vec3 lightDir = gl_LightSource[0].position.xyz;
41 vec3 halfVector = gl_LightSource[0].halfVector.xyz;
42 vec4 texel;
43 vec4 fragColor;
44 vec4 specular = vec4(0.0);
45
46 // Material properties.
47 // Material properties.
48 vec4 mat_diffuse, mat_ambient, mat_specular;
49 float mat_shininess;
50
51 // Simple water texture
52 texel = texture(landclass, gl_TexCoord[0].st);
53
54 // Color Mode is always AMBIENT_AND_DIFFUSE, which means
55 // using a base colour of white for ambient/diffuse,
56 // rather than the material color from ambientArray/diffuseArray.
57 mat_ambient = vec4(1.0,1.0,1.0,1.0);
58 mat_diffuse = vec4(1.0,1.0,1.0,1.0);
59 mat_specular = vec4(0.8,0.8,0.8,1.0);
60 mat_shininess = 1.2;
61
62
63 vec4 color = mat_ambient * (gl_LightModel.ambient + gl_LightSource[0].ambient);
64
65 // If gl_Color.a == 0, this is a back-facing polygon and the
66 // normal should be reversed.
67 vec3 n = (2.0 * gl_Color.a - 1.0) * normal;
68 n = normalize(n);
69 NdotL = dot(n, lightDir);
70
71 if (NdotL > 0.0) {
72 float shadowmap = getShadowing();
73 color += mat_diffuse * NdotL * shadowmap;
74 NdotHV = max(dot(n, halfVector), 0.0);
75 if (mat_shininess > 0.0)
76 specular.rgb = (mat_specular.rgb
77 * gl_LightSource[0].specular.rgb
78 * pow(NdotHV, mat_shininess)
79 * shadowmap);
80 }
81 color.a = mat_diffuse.a;
82
83 // This shouldn't be necessary, but our lighting becomes very
84 // saturated. Clamping the color before modulating by the texture
85 // is closer to what the OpenGL fixed function pipeline does.
86 color = clamp(color, 0.0, 1.0);
87
88 fragColor = color * texel + specular;
89 fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, texel.rgb);
90
91 fragColor.rgb = fog_Func(fragColor.rgb, fogType);
92 gl_FragColor = fragColor;
93 }