aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl')
-rw-r--r--linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl96
1 files changed, 84 insertions, 12 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl b/linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
index f8b8031..1c14381 100644
--- a/linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
+++ b/linden/indra/newview/app_settings/shaders/class1/environment/waterF.glsl
@@ -1,22 +1,94 @@
1void water_lighting(inout vec3 diff); 1/**
2 * @file waterF.glsl
3 *
4 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
5 * $License$
6 */
7
8vec3 scaleSoftClip(vec3 inColor);
9vec3 atmosTransport(vec3 inColor);
2 10
3uniform samplerCube environmentMap;
4uniform sampler2D diffuseMap; 11uniform sampler2D diffuseMap;
5uniform sampler2D bumpMap; 12uniform sampler2D bumpMap;
13uniform sampler2D screenTex;
14uniform sampler2D refTex;
15
16uniform float sunAngle;
17uniform float sunAngle2;
18uniform float scaledAngle;
19uniform vec3 lightDir;
20uniform vec3 specular;
21uniform float lightExp;
22uniform float refScale;
23uniform float kd;
24uniform vec2 screenRes;
25uniform vec3 normScale;
26uniform float fresnelScale;
27uniform float fresnelOffset;
28uniform float blurMultiplier;
29uniform vec4 fogCol;
6 30
7varying vec4 specular; 31//bigWave is (refCoord.w, view.w);
32varying vec4 refCoord;
33varying vec4 littleWave;
34varying vec4 view;
8 35
9void main() 36void main()
10{ 37{
11 vec4 depth = texture2D(diffuseMap, gl_TexCoord[0].xy); 38 vec3 viewVec = view.xyz;
12 vec4 diff = texture2D(bumpMap, gl_TexCoord[1].xy); 39 vec4 color;
13 vec3 ref = textureCube(environmentMap, gl_TexCoord[2].xyz).rgb; 40
41 float dist = length(viewVec.xy);
42
43 //normalize view vector
44 viewVec = normalize(viewVec);
45
46 //get wave normals
47 vec3 wavef = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0;
48
49 //get detail normals
50 vec3 dcol = texture2D(bumpMap, littleWave.xy).rgb*0.75;
51 dcol += texture2D(bumpMap, littleWave.zw).rgb*1.25;
52
53 //interpolate between big waves and little waves (big waves in deep water)
54 wavef = (wavef + dcol) * 0.5;
55
56 //crunch normal to range [-1,1]
57 wavef -= vec3(1,1,1);
58 wavef = normalize(wavef);
59
60 //get base fresnel components
14 61
15 diff.rgb *= depth.rgb; 62 float df = dot(viewVec,wavef) * fresnelScale + fresnelOffset;
63
64 vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
65
66 float dist2 = dist;
67 dist = max(dist, 5.0);
68
69 //get reflected color
70 vec2 refdistort = wavef.xy*dot(normScale, vec3(0.333));
71 vec2 refvec = distort+refdistort/dist;
72 vec4 refcol = texture2D(refTex, refvec);
73
74 //get specular component
75 float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
76
77 //harden specular
78 spec = pow(spec, lightExp);
79
80 //figure out distortion vector (ripply)
81 vec2 distort2 = distort+wavef.xy*refScale/max(dist*df, 1.0);
16 82
17 vec3 col = mix(diff.rgb, ref, specular.a)+specular.rgb*diff.rgb; 83 vec4 fb = texture2D(screenTex, distort2);
84
85 //mix with reflection
86 color.rgb = mix(mix(fogCol.rgb, fb.rgb, fogCol.a), refcol.rgb, df);
87 color.rgb += spec * specular;
18 88
19 water_lighting(col.rgb); 89 color.rgb = atmosTransport(color.rgb);
20 gl_FragColor.rgb = col.rgb; 90 color.rgb = scaleSoftClip(color.rgb);
21 gl_FragColor.a = (gl_Color.a+depth.a)*0.5; 91 color.a = spec * sunAngle2;
92
93 gl_FragColor = color;
22} 94}