Debian Codegraph @

Shaders/clouds-thick.vert

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