Debian Codegraph @

Shaders/default.frag

raw
1 // -*-C++-*-
2
3 // Ambient term comes in gl_Color.rgb.
4 #version 120
5
6 varying vec4 diffuse_term;
7 varying vec3 normal;
8 varying vec4 ecPosition;
9
10 uniform sampler2D texture;
11 uniform sampler2D orthophotoTexture;
12
13 ////fog "include" /////
14 uniform int fogType;
15
16 uniform bool orthophotoAvailable;
17
18 vec3 fog_Func(vec3 color, int type);
19 //////////////////////
20
21 float getShadowing();
22 vec3 getClusteredLightsContribution(vec3 p, vec3 n, vec3 texel);
23
24 float luminance(vec3 color)
25 {
26 return dot(vec3(0.212671, 0.715160, 0.072169), color);
27 }
28
29 void main()
30 {
31 vec3 n;
32 float NdotL, NdotHV, fogFactor;
33 vec4 color = gl_Color;
34 vec3 lightDir = gl_LightSource[0].position.xyz;
35 vec3 halfVector = gl_LightSource[0].halfVector.xyz;
36 vec4 texel;
37 vec4 fragColor;
38 vec4 specular = vec4(0.0);
39
40 // If gl_Color.a == 0, this is a back-facing polygon and the
41 // normal should be reversed.
42 n = (2.0 * gl_Color.a - 1.0) * normal;
43 n = normalize(n);
44
45 NdotL = dot(n, lightDir);
46 if (NdotL > 0.0) {
47 float shadowmap = getShadowing();
48 color += diffuse_term * NdotL * shadowmap;
49 NdotHV = max(dot(n, halfVector), 0.0);
50 if (gl_FrontMaterial.shininess > 0.0)
51 specular.rgb = (gl_FrontMaterial.specular.rgb
52 * gl_LightSource[0].specular.rgb
53 * pow(NdotHV, gl_FrontMaterial.shininess)
54 * shadowmap);
55 }
56 color.a = diffuse_term.a;
57 // This shouldn't be necessary, but our lighting becomes very
58 // saturated. Clamping the color before modulating by the texture
59 // is closer to what the OpenGL fixed function pipeline does.
60 color = clamp(color, 0.0, 1.0);
61 texel = texture2D(texture, gl_TexCoord[0].st);
62
63 if (orthophotoAvailable) {
64 vec4 sat_texel = texture2D(orthophotoTexture, gl_TexCoord[2].st);
65 if (sat_texel.a > 0) {
66 texel.rgb = sat_texel.rgb;
67 }
68 }
69
70 fragColor = color * texel + specular;
71 fragColor.rgb += getClusteredLightsContribution(ecPosition.xyz, n, texel.rgb);
72
73 fragColor.rgb = fog_Func(fragColor.rgb, fogType);
74 gl_FragColor = fragColor;
75 }