diff options
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl | 137 |
1 files changed, 137 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl b/linden/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl new file mode 100644 index 0000000..e40372e --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/windlight/atmosphericsV.glsl | |||
@@ -0,0 +1,137 @@ | |||
1 | /** | ||
2 | * @file atmosphericsV.glsl | ||
3 | * | ||
4 | * Copyright (c) 2005-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | // varying param funcs | ||
9 | void setSunlitColor(vec3 v); | ||
10 | void setAmblitColor(vec3 v); | ||
11 | void setAdditiveColor(vec3 v); | ||
12 | void setAtmosAttenuation(vec3 v); | ||
13 | void setPositionEye(vec3 v); | ||
14 | |||
15 | vec3 getAdditiveColor(); | ||
16 | |||
17 | //varying vec4 vary_CloudUVs; | ||
18 | //varying float vary_CloudDensity; | ||
19 | |||
20 | // Inputs | ||
21 | uniform vec4 morphFactor; | ||
22 | uniform vec3 camPosLocal; | ||
23 | //uniform vec4 camPosWorld; | ||
24 | |||
25 | uniform vec4 lightnorm; | ||
26 | uniform vec4 sunlight_color; | ||
27 | uniform vec4 ambient; | ||
28 | uniform vec4 blue_horizon; | ||
29 | uniform vec4 blue_density; | ||
30 | uniform vec4 haze_horizon; | ||
31 | uniform vec4 haze_density; | ||
32 | uniform vec4 cloud_shadow; | ||
33 | uniform vec4 density_multiplier; | ||
34 | uniform vec4 distance_multiplier; | ||
35 | uniform vec4 max_y; | ||
36 | uniform vec4 glow; | ||
37 | |||
38 | void calcAtmospherics(vec3 inPositionEye) { | ||
39 | |||
40 | vec3 P = inPositionEye; | ||
41 | setPositionEye(P); | ||
42 | |||
43 | //(TERRAIN) limit altitude | ||
44 | if (P.y > max_y.x) P *= (max_y.x / P.y); | ||
45 | if (P.y < -max_y.x) P *= (-max_y.x / P.y); | ||
46 | |||
47 | vec3 tmpLightnorm = lightnorm.xyz; | ||
48 | |||
49 | vec3 Pn = normalize(P); | ||
50 | float Plen = length(P); | ||
51 | |||
52 | vec4 temp1 = vec4(0); | ||
53 | vec3 temp2 = vec3(0); | ||
54 | vec4 blue_weight; | ||
55 | vec4 haze_weight; | ||
56 | vec4 sunlight = sunlight_color; | ||
57 | vec4 light_atten; | ||
58 | |||
59 | //sunlight attenuation effect (hue and brightness) due to atmosphere | ||
60 | //this is used later for sunlight modulation at various altitudes | ||
61 | light_atten = (blue_density * 1.0 + vec4(haze_density.r) * 0.25) * (density_multiplier.x * max_y.x); | ||
62 | //I had thought blue_density and haze_density should have equal weighting, | ||
63 | //but attenuation due to haze_density tends to seem too strong | ||
64 | |||
65 | temp1 = blue_density + vec4(haze_density.r); | ||
66 | blue_weight = blue_density / temp1; | ||
67 | haze_weight = vec4(haze_density.r) / temp1; | ||
68 | |||
69 | //(TERRAIN) compute sunlight from lightnorm only (for short rays like terrain) | ||
70 | temp2.y = max(0.0, tmpLightnorm.y); | ||
71 | temp2.y = 1. / temp2.y; | ||
72 | sunlight *= exp( - light_atten * temp2.y); | ||
73 | |||
74 | // main atmospheric scattering line integral | ||
75 | temp2.z = Plen * density_multiplier.x; | ||
76 | |||
77 | // Transparency (-> temp1) | ||
78 | // ATI Bugfix -- can't store temp1*temp2.z*distance_multiplier.x in a variable because the ati | ||
79 | // compiler gets confused. | ||
80 | temp1 = exp(-temp1 * temp2.z * distance_multiplier.x); | ||
81 | |||
82 | //final atmosphere attenuation factor | ||
83 | setAtmosAttenuation(temp1.rgb); | ||
84 | //vary_AtmosAttenuation = distance_multiplier / 10000.; | ||
85 | //vary_AtmosAttenuation = density_multiplier * 100.; | ||
86 | //vary_AtmosAttenuation = vec4(Plen / 100000., 0., 0., 1.); | ||
87 | |||
88 | //compute haze glow | ||
89 | //(can use temp2.x as temp because we haven't used it yet) | ||
90 | temp2.x = dot(Pn, tmpLightnorm.xyz); | ||
91 | temp2.x = 1. - temp2.x; | ||
92 | //temp2.x is 0 at the sun and increases away from sun | ||
93 | temp2.x = max(temp2.x, .03); //was glow.y | ||
94 | //set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot) | ||
95 | temp2.x *= glow.x; | ||
96 | //higher glow.x gives dimmer glow (because next step is 1 / "angle") | ||
97 | temp2.x = pow(temp2.x, glow.z); | ||
98 | //glow.z should be negative, so we're doing a sort of (1 / "angle") function | ||
99 | |||
100 | //add "minimum anti-solar illumination" | ||
101 | temp2.x += .25; | ||
102 | |||
103 | |||
104 | //increase ambient when there are more clouds | ||
105 | vec4 tmpAmbient = ambient + (vec4(1.) - ambient) * cloud_shadow.x * 0.5; | ||
106 | |||
107 | //haze color | ||
108 | setAdditiveColor( | ||
109 | vec3(blue_horizon * blue_weight * (sunlight*(1.-cloud_shadow.x) + tmpAmbient) | ||
110 | + (haze_horizon.r * haze_weight) * (sunlight*(1.-cloud_shadow.x) * temp2.x | ||
111 | + tmpAmbient))); | ||
112 | |||
113 | //brightness of surface both sunlight and ambient | ||
114 | setSunlitColor(vec3(sunlight * .5)); | ||
115 | setAmblitColor(vec3(tmpAmbient * .25)); | ||
116 | setAdditiveColor(getAdditiveColor() * vec3(1.0 - temp1)); | ||
117 | |||
118 | // vary_SunlitColor = vec3(0); | ||
119 | // vary_AmblitColor = vec3(0); | ||
120 | // vary_AdditiveColor = vec4(Pn, 1.0); | ||
121 | |||
122 | /* | ||
123 | const float cloudShadowScale = 100.; | ||
124 | // Get cloud uvs for shadowing | ||
125 | vec3 cloudPos = inPositionEye + camPosWorld - cloudShadowScale / 2.; | ||
126 | vary_CloudUVs.xy = cloudPos.xz / cloudShadowScale; | ||
127 | |||
128 | // We can take uv1 and multiply it by (TerrainSpan / CloudSpan) | ||
129 | // cloudUVs *= (((worldMaxZ - worldMinZ) * 20) /40000.); | ||
130 | vary_CloudUVs *= (10000./40000.); | ||
131 | |||
132 | // Offset by sun vector * (CloudAltitude / CloudSpan) | ||
133 | vary_CloudUVs.x += tmpLightnorm.x / tmpLightnorm.y * (3000./40000.); | ||
134 | vary_CloudUVs.y += tmpLightnorm.z / tmpLightnorm.y * (3000./40000.); | ||
135 | */ | ||
136 | } | ||
137 | |||