Debian Codegraph @

Shaders/rain-layer.vert

raw
1 // -*-C++-*-
2 #version 120
3
4 varying float fogFactor;
5
6 uniform float range; // From /sim/rendering/clouds3d-vis-range
7
8 float shade = 0.8;
9 float cloud_height = 1000.0;
10
11 void main(void)
12 {
13
14 gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;
15 //gl_TexCoord[0] = gl_MultiTexCoord0 + vec4(textureIndexX, textureIndexY, 0.0, 0.0);
16 vec4 ep = gl_ModelViewMatrixInverse * vec4(0.0,0.0,0.0,1.0);
17 vec4 l = gl_ModelViewMatrixInverse * vec4(0.0,0.0,1.0,1.0);
18 vec3 u = normalize(ep.xyz - l.xyz);
19
20 gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
21 gl_Position.x = gl_Vertex.x;
22 gl_Position.y += gl_Vertex.y;
23 gl_Position.z += gl_Vertex.z;
24 gl_Position.xyz += gl_Color.xyz;
25
26
27
28 // Determine a lighting normal based on the vertex position from the
29 // center of the cloud, so that sprite on the opposite side of the cloud to the sun are darker.
30 float n = dot(normalize(-gl_LightSource[0].position.xyz),
31 normalize(mat3x3(gl_ModelViewMatrix) * (- gl_Position.xyz)));;
32
33 // Determine the position - used for fog and shading calculations
34 vec3 ecPosition = vec3(gl_ModelViewMatrix * gl_Position);
35 float fogCoord = abs(ecPosition.z);
36 float fract = smoothstep(0.0, cloud_height, gl_Position.z + cloud_height);
37
38
39 gl_Position = gl_ModelViewProjectionMatrix * gl_Position;
40
41 // Determine the shading of the sprite based on its vertical position and position relative to the sun.
42 n = min(smoothstep(-0.5, 0.0, n), fract);
43 // Determine the shading based on a mixture from the backlight to the front
44 vec4 backlight = gl_LightSource[0].diffuse * shade;
45
46 gl_FrontColor = mix(backlight, gl_LightSource[0].diffuse, n);
47 gl_FrontColor += gl_FrontLightModelProduct.sceneColor;
48
49 // As we get within 100m of the sprite, it is faded out. Equally at large distances it also fades out.
50 gl_FrontColor.a = min(smoothstep(100.0, 250.0, fogCoord), 1.0 - smoothstep(range*0.9, range, fogCoord));
51 gl_BackColor = gl_FrontColor;
52
53 // Fog doesn't affect rain as much as other objects.
54 fogFactor = exp( -gl_Fog.density * fogCoord * 0.4);
55 fogFactor = clamp(fogFactor, 0.0, 1.0);
56 }