diff options
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl')
-rw-r--r-- | linden/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl new file mode 100644 index 0000000..522c990 --- /dev/null +++ b/linden/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl | |||
@@ -0,0 +1,54 @@ | |||
1 | /** | ||
2 | * @file waterFogF.glsl | ||
3 | * | ||
4 | * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc. | ||
5 | * $License$ | ||
6 | */ | ||
7 | |||
8 | uniform vec4 lightnorm; | ||
9 | uniform vec4 waterPlane; | ||
10 | uniform vec4 waterFogColor; | ||
11 | uniform float waterFogDensity; | ||
12 | uniform float waterFogKS; | ||
13 | |||
14 | vec3 getPositionEye(); | ||
15 | |||
16 | vec4 applyWaterFog(vec4 color) | ||
17 | { | ||
18 | //normalize view vector | ||
19 | vec3 view = normalize(getPositionEye()); | ||
20 | float es = -(dot(view, waterPlane.xyz)); | ||
21 | |||
22 | //find intersection point with water plane and eye vector | ||
23 | |||
24 | //get eye depth | ||
25 | float e0 = max(-waterPlane.w, 0.0); | ||
26 | |||
27 | vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0); | ||
28 | |||
29 | //get object depth | ||
30 | float depth = length(getPositionEye() - int_v); | ||
31 | |||
32 | //get "thickness" of water | ||
33 | float l = max(depth, 0.1); | ||
34 | |||
35 | float kd = waterFogDensity; | ||
36 | float ks = waterFogKS; | ||
37 | vec4 kc = waterFogColor; | ||
38 | |||
39 | float F = 0.98; | ||
40 | |||
41 | float t1 = -kd * pow(F, ks * e0); | ||
42 | float t2 = kd + ks * es; | ||
43 | float t3 = pow(F, t2*l) - 1.0; | ||
44 | |||
45 | float L = min(t1/t2*t3, 1.0); | ||
46 | |||
47 | float D = pow(0.98, l*kd); | ||
48 | |||
49 | color.rgb = color.rgb * D + kc.rgb * L; | ||
50 | color.a = kc.a + color.a; | ||
51 | |||
52 | return color; | ||
53 | } | ||
54 | |||