diff options
author | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:34 -0500 |
commit | cd17687f01420952712a500107e0f93e7ab8d5f8 (patch) | |
tree | ce48c2b706f2c1176290e39fb555fbdf6648ce01 /linden/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | |
parent | Second Life viewer sources 1.19.0.5 (diff) | |
download | meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.zip meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.gz meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.bz2 meta-impy-cd17687f01420952712a500107e0f93e7ab8d5f8.tar.xz |
Second Life viewer sources 1.19.1.0
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | 163 |
1 files changed, 163 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl b/linden/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl new file mode 100644 index 0000000..e149d58 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/windlight/cloudsV.glsl | |||
@@ -0,0 +1,163 @@ | |||
1 | /** | ||
2 | * @file WLCloudsV.glsl | ||
3 | * | ||
4 | * Copyright (c) 2005-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | ////////////////////////////////////////////////////////////////////////// | ||
9 | // The vertex shader for creating the atmospheric sky | ||
10 | /////////////////////////////////////////////////////////////////////////////// | ||
11 | |||
12 | // Output parameters | ||
13 | varying vec4 vary_CloudColorSun; | ||
14 | varying vec4 vary_CloudColorAmbient; | ||
15 | varying float vary_CloudDensity; | ||
16 | |||
17 | // Inputs | ||
18 | uniform vec3 camPosLocal; | ||
19 | |||
20 | uniform vec4 lightnorm; | ||
21 | uniform vec4 sunlight_color; | ||
22 | uniform vec4 ambient; | ||
23 | uniform vec4 blue_horizon; | ||
24 | uniform vec4 blue_density; | ||
25 | uniform vec4 haze_horizon; | ||
26 | uniform vec4 haze_density; | ||
27 | |||
28 | uniform vec4 cloud_shadow; | ||
29 | uniform vec4 density_multiplier; | ||
30 | uniform vec4 max_y; | ||
31 | |||
32 | uniform vec4 glow; | ||
33 | |||
34 | uniform vec4 cloud_color; | ||
35 | |||
36 | uniform vec4 cloud_scale; | ||
37 | |||
38 | void main() | ||
39 | { | ||
40 | |||
41 | // World / view / projection | ||
42 | gl_Position = ftransform(); | ||
43 | |||
44 | gl_TexCoord[0] = gl_MultiTexCoord0; | ||
45 | |||
46 | // Get relative position | ||
47 | vec3 P = gl_Vertex.xyz - camPosLocal.xyz + vec3(0,50,0); | ||
48 | |||
49 | // Set altitude | ||
50 | if (P.y > 0.) | ||
51 | { | ||
52 | P *= (max_y.x / P.y); | ||
53 | } | ||
54 | else | ||
55 | { | ||
56 | P *= (-32000. / P.y); | ||
57 | } | ||
58 | |||
59 | // Can normalize then | ||
60 | vec3 Pn = normalize(P); | ||
61 | float Plen = length(P); | ||
62 | |||
63 | // Initialize temp variables | ||
64 | vec4 temp1 = vec4(0.); | ||
65 | vec4 temp2 = vec4(0.); | ||
66 | vec4 blue_weight; | ||
67 | vec4 haze_weight; | ||
68 | vec4 sunlight = sunlight_color; | ||
69 | vec4 light_atten; | ||
70 | |||
71 | |||
72 | // Sunlight attenuation effect (hue and brightness) due to atmosphere | ||
73 | // this is used later for sunlight modulation at various altitudes | ||
74 | light_atten = (blue_density * 1.0 + haze_density.x * 0.25) * (density_multiplier.x * max_y.x); | ||
75 | |||
76 | // Calculate relative weights | ||
77 | temp1 = blue_density + haze_density.x; | ||
78 | blue_weight = blue_density / temp1; | ||
79 | haze_weight = haze_density.x / temp1; | ||
80 | |||
81 | // Compute sunlight from P & lightnorm (for long rays like sky) | ||
82 | temp2.y = max(0., max(0., Pn.y) * 1.0 + lightnorm.y ); | ||
83 | temp2.y = 1. / temp2.y; | ||
84 | sunlight *= exp( - light_atten * temp2.y); | ||
85 | |||
86 | // Distance | ||
87 | temp2.z = Plen * density_multiplier.x; | ||
88 | |||
89 | // Transparency (-> temp1) | ||
90 | // ATI Bugfix -- can't store temp1*temp2.z in a variable because the ati | ||
91 | // compiler gets confused. | ||
92 | temp1 = exp(-temp1 * temp2.z); | ||
93 | |||
94 | |||
95 | // Compute haze glow | ||
96 | temp2.x = dot(Pn, lightnorm.xyz); | ||
97 | temp2.x = 1. - temp2.x; | ||
98 | // temp2.x is 0 at the sun and increases away from sun | ||
99 | temp2.x = max(temp2.x, .001); | ||
100 | // Set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) | ||
101 | temp2.x *= glow.x; | ||
102 | // Higher glow.x gives dimmer glow (because next step is 1 / "angle") | ||
103 | temp2.x = pow(temp2.x, glow.z); | ||
104 | // glow.z should be negative, so we're doing a sort of (1 / "angle") function | ||
105 | |||
106 | // Add "minimum anti-solar illumination" | ||
107 | temp2.x += .25; | ||
108 | |||
109 | // Increase ambient when there are more clouds | ||
110 | vec4 tmpAmbient = ambient; | ||
111 | tmpAmbient += (1. - tmpAmbient) * cloud_shadow.x * 0.5; | ||
112 | |||
113 | // Dim sunlight by cloud shadow percentage | ||
114 | sunlight *= (1. - cloud_shadow.x); | ||
115 | |||
116 | // Haze color below cloud | ||
117 | vec4 additiveColorBelowCloud = ( blue_horizon * blue_weight * (sunlight + tmpAmbient) | ||
118 | + (haze_horizon.r * haze_weight) * (sunlight * temp2.x + tmpAmbient) | ||
119 | ); | ||
120 | |||
121 | // CLOUDS | ||
122 | |||
123 | sunlight = sunlight_color; | ||
124 | temp2.y = max(0., lightnorm.y * 2.); | ||
125 | temp2.y = 1. / temp2.y; | ||
126 | sunlight *= exp( - light_atten * temp2.y); | ||
127 | |||
128 | // Cloud color out | ||
129 | vary_CloudColorSun = (sunlight * temp2.x) * cloud_color; | ||
130 | vary_CloudColorAmbient = tmpAmbient * cloud_color; | ||
131 | |||
132 | // Attenuate cloud color by atmosphere | ||
133 | temp1 = sqrt(temp1); //less atmos opacity (more transparency) below clouds | ||
134 | vary_CloudColorSun *= temp1; | ||
135 | vary_CloudColorAmbient *= temp1; | ||
136 | vec4 oHazeColorBelowCloud = additiveColorBelowCloud * (1. - temp1); | ||
137 | |||
138 | // Make a nice cloud density based on the cloud_shadow value that was passed in. | ||
139 | vary_CloudDensity = 2. * (cloud_shadow.x - 0.25); | ||
140 | |||
141 | |||
142 | // Texture coords | ||
143 | gl_TexCoord[0] = gl_MultiTexCoord0; | ||
144 | gl_TexCoord[0].xy -= 0.5; | ||
145 | gl_TexCoord[0].xy /= cloud_scale.x; | ||
146 | gl_TexCoord[0].xy += 0.5; | ||
147 | |||
148 | gl_TexCoord[1] = gl_TexCoord[0]; | ||
149 | gl_TexCoord[1].x += lightnorm.x * 0.0125; | ||
150 | gl_TexCoord[1].y += lightnorm.z * 0.0125; | ||
151 | |||
152 | gl_TexCoord[2] = gl_TexCoord[0] * 16.; | ||
153 | gl_TexCoord[3] = gl_TexCoord[1] * 16.; | ||
154 | |||
155 | // Combine these to minimize register use | ||
156 | vary_CloudColorAmbient += oHazeColorBelowCloud; | ||
157 | |||
158 | // needs this to compile on mac | ||
159 | //vary_AtmosAttenuation = vec3(0.0,0.0,0.0); | ||
160 | |||
161 | // END CLOUDS | ||
162 | } | ||
163 | |||