aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/app_settings/shaders/class2/environment
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/app_settings/shaders/class2/environment')
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl38
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl52
-rwxr-xr-xlinden/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl39
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl88
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/environment/waterF.glsl223
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl54
-rw-r--r--linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl53
7 files changed, 372 insertions, 175 deletions
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl
new file mode 100644
index 0000000..4253bc2
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl
@@ -0,0 +1,38 @@
1/**
2 * @file terrainF.glsl
3 *
4 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
5 * $License$
6 */
7
8uniform sampler2D detail_0;
9uniform sampler2D detail_1;
10uniform sampler2D detail_2;
11uniform sampler2D detail_3;
12uniform sampler2D alpha_ramp;
13
14vec3 atmosLighting(vec3 light);
15
16vec3 scaleSoftClip(vec3 color);
17
18void main()
19{
20 /// Note: This should duplicate the blending functionality currently used for the terrain rendering.
21
22 /// TODO Confirm tex coords and bind them appropriately in vert shader.
23 vec4 color0 = texture2D(detail_0, gl_TexCoord[0].xy);
24 vec4 color1 = texture2D(detail_1, gl_TexCoord[0].xy);
25 vec4 color2 = texture2D(detail_2, gl_TexCoord[0].xy);
26 vec4 color3 = texture2D(detail_3, gl_TexCoord[0].xy);
27
28 float alpha1 = texture2D(alpha_ramp, gl_TexCoord[0].zw).a;
29 float alpha2 = texture2D(alpha_ramp,gl_TexCoord[1].xy).a;
30 float alphaFinal = texture2D(alpha_ramp, gl_TexCoord[1].zw).a;
31 vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
32
33 /// Add WL Components
34 outColor.rgb = atmosLighting(outColor.rgb * gl_Color.rgb);
35
36 gl_FragColor = vec4(scaleSoftClip(outColor.rgb), 1.0);
37}
38
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
new file mode 100644
index 0000000..119d55a
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
@@ -0,0 +1,52 @@
1/**
2 * @file terrainV.glsl
3 *
4 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
5 * $License$
6 */
7
8void calcAtmospherics(vec3 inPositionEye);
9
10vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
11
12vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
13{
14 vec4 tcoord;
15
16 tcoord.x = dot(vpos, tp0);
17 tcoord.y = dot(vpos, tp1);
18 tcoord.z = tc.z;
19 tcoord.w = tc.w;
20
21 tcoord = mat * tcoord;
22
23 return tcoord;
24}
25
26void main()
27{
28 //transform vertex
29 gl_Position = ftransform();
30
31 vec4 pos = gl_ModelViewMatrix * gl_Vertex;
32 vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
33
34 /// Potentially better without it for water.
35 pos /= pos.w;
36
37 calcAtmospherics((gl_ModelViewMatrix * gl_Vertex).xyz);
38
39 vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0));
40
41 gl_FrontColor = color;
42
43 // Transform and pass tex coords
44 gl_TexCoord[0].xy = texgen_object(gl_Vertex, gl_MultiTexCoord0, gl_TextureMatrix[0], gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
45
46 vec4 t = gl_MultiTexCoord1;
47
48 gl_TexCoord[0].zw = t.xy;
49 gl_TexCoord[1].xy = t.xy-vec2(2.0, 0.0);
50 gl_TexCoord[1].zw = t.xy-vec2(1.0, 0.0);
51}
52
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl
new file mode 100755
index 0000000..3a98970
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl
@@ -0,0 +1,39 @@
1/**
2 * @file terrainWaterF.glsl
3 *
4 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
5 * $License$
6 */
7
8uniform sampler2D detail_0;
9uniform sampler2D detail_1;
10uniform sampler2D detail_2;
11uniform sampler2D detail_3;
12uniform sampler2D alpha_ramp;
13
14vec3 atmosLighting(vec3 light);
15
16vec4 applyWaterFog(vec4 color);
17
18void main()
19{
20 /// Note: This should duplicate the blending functionality currently used for the terrain rendering.
21
22 /// TODO Confirm tex coords and bind them appropriately in vert shader.
23 vec4 color0 = texture2D(detail_0, gl_TexCoord[0].xy);
24 vec4 color1 = texture2D(detail_1, gl_TexCoord[0].xy);
25 vec4 color2 = texture2D(detail_2, gl_TexCoord[0].xy);
26 vec4 color3 = texture2D(detail_3, gl_TexCoord[0].xy);
27
28 float alpha1 = texture2D(alpha_ramp, gl_TexCoord[0].zw).a;
29 float alpha2 = texture2D(alpha_ramp,gl_TexCoord[1].xy).a;
30 float alphaFinal = texture2D(alpha_ramp, gl_TexCoord[1].zw).a;
31 vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
32
33 /// Add WL Components
34 outColor.rgb = atmosLighting(outColor.rgb * gl_Color.rgb);
35
36 outColor = applyWaterFog(outColor);
37 gl_FragColor = outColor;
38}
39
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl
new file mode 100644
index 0000000..1998fea
--- /dev/null
+++ b/linden/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl
@@ -0,0 +1,88 @@
1/**
2 * @file underWaterF.glsl
3 *
4 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
5 * $License$
6 */
7
8uniform sampler2D diffuseMap;
9uniform sampler2D bumpMap;
10uniform sampler2D screenTex;
11uniform sampler2D refTex;
12uniform sampler2D screenDepth;
13
14uniform vec4 fogCol;
15uniform vec3 lightDir;
16uniform vec3 specular;
17uniform float lightExp;
18uniform vec2 fbScale;
19uniform float refScale;
20uniform float znear;
21uniform float zfar;
22uniform float kd;
23uniform vec4 waterPlane;
24uniform vec3 eyeVec;
25uniform vec4 waterFogColor;
26uniform float waterFogDensity;
27uniform float waterFogKS;
28uniform vec2 screenRes;
29
30//bigWave is (refCoord.w, view.w);
31varying vec4 refCoord;
32varying vec4 littleWave;
33varying vec4 view;
34
35vec4 applyWaterFog(vec4 color, vec3 viewVec)
36{
37 //normalize view vector
38 vec3 view = normalize(viewVec);
39 float es = -view.z;
40
41 //find intersection point with water plane and eye vector
42
43 //get eye depth
44 float e0 = max(-waterPlane.w, 0.0);
45
46 //get object depth
47 float depth = length(viewVec);
48
49 //get "thickness" of water
50 float l = max(depth, 0.1);
51
52 float kd = waterFogDensity;
53 float ks = waterFogKS;
54 vec4 kc = waterFogColor;
55
56 float F = 0.98;
57
58 float t1 = -kd * pow(F, ks * e0);
59 float t2 = kd + ks * es;
60 float t3 = pow(F, t2*l) - 1.0;
61
62 float L = min(t1/t2*t3, 1.0);
63
64 float D = pow(0.98, l*kd);
65 //return vec4(1.0, 0.0, 1.0, 1.0);
66 return color * D + kc * L;
67 //depth /= 10.0;
68 //return vec4(depth,depth,depth,0.0);
69}
70
71void main()
72{
73 vec4 color;
74
75 //get detail normals
76 vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
77 vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
78 vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
79 vec3 wavef = normalize(wave1+wave2+wave3);
80
81 //figure out distortion vector (ripply)
82 vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
83 distort = distort+wavef.xy*refScale;
84
85 vec4 fb = texture2D(screenTex, distort);
86
87 gl_FragColor = applyWaterFog(fb,view.xyz);
88}
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
index 11a057b..6ec3dc4 100644
--- a/linden/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
+++ b/linden/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
@@ -1,138 +1,117 @@
1void applyScatter(inout vec3 color); 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 sampler2D diffuseMap;
4uniform sampler2D bumpMap; 11uniform sampler2D bumpMap;
5uniform samplerCube environmentMap; //: TEXUNIT4, // Environment map texture 12uniform sampler2D screenTex;
6uniform sampler2D screenTex; // : TEXUNIT5 13uniform sampler2D refTex;
7 14
15uniform float sunAngle;
16uniform float sunAngle2;
8uniform vec3 lightDir; 17uniform vec3 lightDir;
9uniform vec3 specular; 18uniform vec3 specular;
10uniform float lightExp; 19uniform float lightExp;
11uniform vec2 fbScale;
12uniform float refScale; 20uniform float refScale;
21uniform float kd;
22uniform vec2 screenRes;
23uniform vec3 normScale;
24uniform float fresnelScale;
25uniform float fresnelOffset;
26uniform float blurMultiplier;
13 27
14float msin(float x) {
15 float k = sin(x)+1.0;
16 k *= 0.5;
17 k *= k;
18 return 2.0 * k;
19}
20 28
21float mcos(float x) { 29//bigWave is (refCoord.w, view.w);
22 float k = cos(x)+1.0; 30varying vec4 refCoord;
23 k *= 0.5; 31varying vec4 littleWave;
24 k *= k; 32varying vec4 view;
25 return 2.0 * k;
26}
27 33
28float waveS(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap) 34void main()
29{ 35{
30 return texture1D(sinMap, (dot(d, v)*f + t*s)*f).r*a; 36 vec4 color;
31} 37
38 float dist = length(view.xy);
39
40 //normalize view vector
41 vec3 viewVec = normalize(view.xyz);
42
43 //get wave normals
44 vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
45 vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
46 vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
47 //get base fresnel components
48
49 vec3 df = vec3(
50 dot(viewVec, wave1),
51 dot(viewVec, (wave2 + wave3) * 0.5),
52 dot(viewVec, wave3)
53 ) * fresnelScale + fresnelOffset;
54 df *= df;
55
56 vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
57
58 float dist2 = dist;
59 dist = max(dist, 5.0);
60
61 float dmod = sqrt(dist);
62
63 vec2 dmod_scale = vec2(dmod*dmod, dmod);
64
65 //get reflected color
66 vec2 refdistort1 = wave1.xy*normScale.x;
67 vec2 refvec1 = distort+refdistort1/dmod_scale;
68 vec4 refcol1 = texture2D(refTex, refvec1);
69
70 vec2 refdistort2 = wave2.xy*normScale.y;
71 vec2 refvec2 = distort+refdistort2/dmod_scale;
72 vec4 refcol2 = texture2D(refTex, refvec2);
73
74 vec2 refdistort3 = wave3.xy*normScale.z;
75 vec2 refvec3 = distort+refdistort3/dmod_scale;
76 vec4 refcol3 = texture2D(refTex, refvec3);
32 77
33float waveC(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap) 78 vec4 refcol = refcol1 + refcol2 + refcol3;
34{ 79 float df1 = df.x + df.y + df.z;
35 return texture1D(sinMap, (dot(d, v)*f + t*s)*f).g*a*2.0-1.0; 80 refcol *= df1 * 0.333;
36} 81
82 vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5;
83
84 wavef.z *= max(-viewVec.z, 0.1);
85 wavef = normalize(wavef);
86
87 float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset;
88
89 vec2 refdistort4 = wavef.xy*0.125;
90 refdistort4.y -= abs(refdistort4.y);
91 vec2 refvec4 = distort+refdistort4/dmod;
92 float dweight = min(dist2*blurMultiplier, 1.0);
93 vec4 baseCol = texture2D(refTex, refvec4);
94 refcol = mix(baseCol*df2, refcol, dweight);
37 95
38float magnitude(vec3 vec) { 96 //get specular component
39 return sqrt(dot(vec,vec)); 97 float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
40} 98
41 99 //harden specular
42vec3 mreflect(vec3 i, vec3 n) { 100 spec = pow(spec, 128.0);
43 return i + n * 2.0 * abs(dot(n,i))+vec3(0.0,0.0,0.5);
44}
45
46void main()
47{
48 vec2 texCoord = gl_TexCoord[0].xy; // Texture coordinates
49 vec2 littleWave1 = gl_TexCoord[0].zw;
50 vec2 littleWave2 = gl_TexCoord[1].xy;
51 vec2 bigWave = gl_TexCoord[1].zw;
52 vec3 viewVec = gl_TexCoord[2].xyz;
53 vec4 refCoord = gl_TexCoord[3];
54 vec4 col = gl_Color;
55 vec4 color;
56
57 //get color from alpha map (alpha denotes water depth), rgb denotes water color
58 vec4 wcol = texture2D(diffuseMap, texCoord.xy);
59
60 //store texture alpha
61 float da = wcol.a;
62
63 //modulate by incoming water color
64 //wcol.a *= refCoord.w;
65
66 //scale wcol.a (water depth) for steep transition
67 wcol.a *= wcol.a;
68
69 //normalize view vector
70 viewVec = normalize(viewVec);
71
72 //get bigwave normal
73 vec3 wavef = texture2D(bumpMap, bigWave).xyz*2.0;
74
75 vec3 view = vec3(viewVec.x, viewVec.y, viewVec.z);
76
77 float dx = 1.0-(dot(wavef*2.0-vec3(1.0), view))*da;
78 dx *= 0.274;
79
80 //get detail normals
81 vec3 dcol = texture2D(bumpMap, littleWave1+dx*view.xy).rgb*0.75;
82 dcol += texture2D(bumpMap, littleWave2+view.xy*dx*0.1).rgb*1.25;
83
84 //interpolate between big waves and little waves (big waves in deep water)
85 wavef = wavef*wcol.a + dcol*(1.0-wcol.a);
86
87 //crunch normal to range [-1,1]
88 wavef -= vec3(1,1,1);
89
90 //get base fresnel component
91 float df = dot(viewVec,wavef);
92 //reposition fresnel to latter half of [0,1]
93 df = 1.0-clamp(df,0.0,1.0);
94 101
95 //set output alpha based on fresnel 102 //figure out distortion vector (ripply)
96 color.a = clamp((df+da)*0.5,0.0,1.0); 103 vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0);
97 104
98 //calculate reflection vector 105 vec4 fb = texture2D(screenTex, distort2);
99 vec3 ref = reflect(viewVec.xyz, wavef); 106
100 107 //mix with reflection
101 //get specular component 108 // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug
102 float spec = clamp(dot(lightDir, normalize(ref)),0.0,1.0); 109 color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999);
103 110 color.rgb += spec * specular;
104 //fudge reflection to be more noisy at good angles 111
105 ref.z = ref.z*ref.z+df*df*0.5; 112 color.rgb = atmosTransport(color.rgb);
106 113 color.rgb = scaleSoftClip(color.rgb);
107 //get diffuse component 114 color.a = spec * sunAngle2;
108 float diff = clamp((abs(dot(ref, wavef))),0.0,1.0)*0.9;
109
110 //fudge diffuse for extra contrast and ambience
111 diff *= diff;
112 diff += 0.4;
113
114 //set diffuse color contribution
115 color.rgb = textureCube(environmentMap, ref).rgb*diff;
116
117 //harden specular
118 spec = pow(spec, lightExp);
119
120 //add specular color contribution
121 color.rgb += spec * specular;
122 115
123 //figure out distortion vector (ripply) 116 gl_FragColor = color;
124 vec2 distort = clamp(((refCoord.xy/refCoord.z) * 0.5 + 0.5 + wavef.xy*refScale),0.0,0.99);
125
126 //read from framebuffer (offset)
127 vec4 fb = texture2D(screenTex, distort*fbScale);
128
129 //tint by framebuffer
130 color.rgb = color.a*color.rgb + (1.0-color.a)*fb.rgb;
131
132 //apply fog
133 applyScatter(color.rgb);
134
135 color.a = spec*0.5+fb.a;
136
137 gl_FragColor = color;
138} 117}
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
8uniform vec4 lightnorm;
9uniform vec4 waterPlane;
10uniform vec4 waterFogColor;
11uniform float waterFogDensity;
12uniform float waterFogKS;
13
14vec3 getPositionEye();
15
16vec4 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
diff --git a/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl b/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl
deleted file mode 100644
index 25309fa..0000000
--- a/linden/indra/newview/app_settings/shaders/class2/environment/waterV.glsl
+++ /dev/null
@@ -1,53 +0,0 @@
1void default_scatter(vec3 viewVec, vec3 lightDir);
2
3uniform vec2 d1;
4uniform vec2 d2;
5uniform float time;
6uniform vec3 eyeVec;
7
8float wave(vec2 v, float t, float f, vec2 d, float s)
9{
10 return (dot(d, v)*f + t*s)*f;
11}
12
13void main()
14{
15 //transform vertex
16 vec4 position = gl_Vertex;
17 mat4 modelViewProj = gl_ModelViewProjectionMatrix;
18 vec4 oPosition = modelViewProj * position;
19 vec3 oRefCoord = oPosition.xyz + vec3(0, 0, 0.2);
20
21 //get view vector
22 vec4 oEyeVec;
23 oEyeVec.xyz = position.xyz-eyeVec;
24
25 //get wave position parameter (create sweeping horizontal waves)
26 vec3 v = position.xyz;
27 v.x += (cos(v.x*0.08+time*0.01)+sin(v.y*0.02))*6.0;
28
29 //get two normal map (detail map) texture coordinates
30 vec2 oTexCoord = gl_MultiTexCoord0.xy;
31 vec2 littleWave1 = (v.xy)*vec2(0.7, 1.5)+d2*time*0.065;
32 vec2 littleWave2 = (v.xy)*vec2(0.07, 0.15)-d1*time*0.087;
33
34 //pass wave parameters to pixel shader
35 float t = time * 0.075;
36 vec2 bigWave = (v.xy)*vec2(0.04,0.04)+d1*t;
37
38 //pass color and fog color to pixel shader
39 vec4 col = gl_Color;
40 col.a = clamp(abs(dot(normalize(oEyeVec.xyz), vec3(0,0,1))),0.0,1.0);
41 col.a = 1.0-col.a;
42 col.a += 0.75;
43 default_scatter((gl_ModelViewMatrix * gl_Vertex).xyz, gl_LightSource[0].position.xyz);
44
45 gl_Position = oPosition;
46 gl_TexCoord[0].xy = oTexCoord;
47 gl_TexCoord[0].zw = littleWave1;
48 gl_TexCoord[1].xy = littleWave2;
49 gl_TexCoord[1].zw = bigWave;
50 gl_TexCoord[2].xyz = oEyeVec.xyz;
51 gl_TexCoord[3].xyz = oRefCoord;
52 gl_FrontColor = col;
53}