Debian Codegraph @

Shaders/object_instancing_colored_lowspec.frag

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