summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class2/environment
diff options
context:
space:
mode:
authorBrad Kittenbrink <brad@lindenlab.com>2008-02-27 18:58:14 +0000
committerBrad Kittenbrink <brad@lindenlab.com>2008-02-27 18:58:14 +0000
commit6d52efe452aa8469e0343da1c7d108f3f52ab651 (patch)
treea87be48e9840d7fc1f7ee514d7c7f994e71fdb3c /indra/newview/app_settings/shaders/class2/environment
parent6027ad2630b8650cabcf00628ee9b0d25bedd67f (diff)
Merge of windlight into release (QAR-286). This includes all changes in
windlight14 which have passed QA (up through r79932). svn merge -r 80831:80833 svn+ssh://svn.lindenlab.com/svn/linden/branches/merge_windlight14_r80620
Diffstat (limited to 'indra/newview/app_settings/shaders/class2/environment')
-rw-r--r--indra/newview/app_settings/shaders/class2/environment/terrainF.glsl38
-rw-r--r--indra/newview/app_settings/shaders/class2/environment/terrainV.glsl52
-rwxr-xr-xindra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl39
-rw-r--r--indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl88
-rw-r--r--indra/newview/app_settings/shaders/class2/environment/waterF.glsl223
-rw-r--r--indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl54
6 files changed, 372 insertions, 122 deletions
diff --git a/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl b/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl
new file mode 100644
index 0000000000..4253bc21c3
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/environment/terrainF.glsl
@@ -0,0 +1,38 @@
+/**
+ * @file terrainF.glsl
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+uniform sampler2D detail_0;
+uniform sampler2D detail_1;
+uniform sampler2D detail_2;
+uniform sampler2D detail_3;
+uniform sampler2D alpha_ramp;
+
+vec3 atmosLighting(vec3 light);
+
+vec3 scaleSoftClip(vec3 color);
+
+void main()
+{
+ /// Note: This should duplicate the blending functionality currently used for the terrain rendering.
+
+ /// TODO Confirm tex coords and bind them appropriately in vert shader.
+ vec4 color0 = texture2D(detail_0, gl_TexCoord[0].xy);
+ vec4 color1 = texture2D(detail_1, gl_TexCoord[0].xy);
+ vec4 color2 = texture2D(detail_2, gl_TexCoord[0].xy);
+ vec4 color3 = texture2D(detail_3, gl_TexCoord[0].xy);
+
+ float alpha1 = texture2D(alpha_ramp, gl_TexCoord[0].zw).a;
+ float alpha2 = texture2D(alpha_ramp,gl_TexCoord[1].xy).a;
+ float alphaFinal = texture2D(alpha_ramp, gl_TexCoord[1].zw).a;
+ vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
+
+ /// Add WL Components
+ outColor.rgb = atmosLighting(outColor.rgb * gl_Color.rgb);
+
+ gl_FragColor = vec4(scaleSoftClip(outColor.rgb), 1.0);
+}
+
diff --git a/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl b/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
new file mode 100644
index 0000000000..119d55a2cd
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/environment/terrainV.glsl
@@ -0,0 +1,52 @@
+/**
+ * @file terrainV.glsl
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+void calcAtmospherics(vec3 inPositionEye);
+
+vec4 calcLighting(vec3 pos, vec3 norm, vec4 color, vec4 baseCol);
+
+vec4 texgen_object(vec4 vpos, vec4 tc, mat4 mat, vec4 tp0, vec4 tp1)
+{
+ vec4 tcoord;
+
+ tcoord.x = dot(vpos, tp0);
+ tcoord.y = dot(vpos, tp1);
+ tcoord.z = tc.z;
+ tcoord.w = tc.w;
+
+ tcoord = mat * tcoord;
+
+ return tcoord;
+}
+
+void main()
+{
+ //transform vertex
+ gl_Position = ftransform();
+
+ vec4 pos = gl_ModelViewMatrix * gl_Vertex;
+ vec3 norm = normalize(gl_NormalMatrix * gl_Normal);
+
+ /// Potentially better without it for water.
+ pos /= pos.w;
+
+ calcAtmospherics((gl_ModelViewMatrix * gl_Vertex).xyz);
+
+ vec4 color = calcLighting(pos.xyz, norm, gl_Color, vec4(0));
+
+ gl_FrontColor = color;
+
+ // Transform and pass tex coords
+ gl_TexCoord[0].xy = texgen_object(gl_Vertex, gl_MultiTexCoord0, gl_TextureMatrix[0], gl_ObjectPlaneS[0], gl_ObjectPlaneT[0]).xy;
+
+ vec4 t = gl_MultiTexCoord1;
+
+ gl_TexCoord[0].zw = t.xy;
+ gl_TexCoord[1].xy = t.xy-vec2(2.0, 0.0);
+ gl_TexCoord[1].zw = t.xy-vec2(1.0, 0.0);
+}
+
diff --git a/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl b/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl
new file mode 100755
index 0000000000..3a98970f8c
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/environment/terrainWaterF.glsl
@@ -0,0 +1,39 @@
+/**
+ * @file terrainWaterF.glsl
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+uniform sampler2D detail_0;
+uniform sampler2D detail_1;
+uniform sampler2D detail_2;
+uniform sampler2D detail_3;
+uniform sampler2D alpha_ramp;
+
+vec3 atmosLighting(vec3 light);
+
+vec4 applyWaterFog(vec4 color);
+
+void main()
+{
+ /// Note: This should duplicate the blending functionality currently used for the terrain rendering.
+
+ /// TODO Confirm tex coords and bind them appropriately in vert shader.
+ vec4 color0 = texture2D(detail_0, gl_TexCoord[0].xy);
+ vec4 color1 = texture2D(detail_1, gl_TexCoord[0].xy);
+ vec4 color2 = texture2D(detail_2, gl_TexCoord[0].xy);
+ vec4 color3 = texture2D(detail_3, gl_TexCoord[0].xy);
+
+ float alpha1 = texture2D(alpha_ramp, gl_TexCoord[0].zw).a;
+ float alpha2 = texture2D(alpha_ramp,gl_TexCoord[1].xy).a;
+ float alphaFinal = texture2D(alpha_ramp, gl_TexCoord[1].zw).a;
+ vec4 outColor = mix( mix(color3, color2, alpha2), mix(color1, color0, alpha1), alphaFinal );
+
+ /// Add WL Components
+ outColor.rgb = atmosLighting(outColor.rgb * gl_Color.rgb);
+
+ outColor = applyWaterFog(outColor);
+ gl_FragColor = outColor;
+}
+
diff --git a/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl
new file mode 100644
index 0000000000..1998fea227
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/environment/underWaterF.glsl
@@ -0,0 +1,88 @@
+/**
+ * @file underWaterF.glsl
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+uniform sampler2D diffuseMap;
+uniform sampler2D bumpMap;
+uniform sampler2D screenTex;
+uniform sampler2D refTex;
+uniform sampler2D screenDepth;
+
+uniform vec4 fogCol;
+uniform vec3 lightDir;
+uniform vec3 specular;
+uniform float lightExp;
+uniform vec2 fbScale;
+uniform float refScale;
+uniform float znear;
+uniform float zfar;
+uniform float kd;
+uniform vec4 waterPlane;
+uniform vec3 eyeVec;
+uniform vec4 waterFogColor;
+uniform float waterFogDensity;
+uniform float waterFogKS;
+uniform vec2 screenRes;
+
+//bigWave is (refCoord.w, view.w);
+varying vec4 refCoord;
+varying vec4 littleWave;
+varying vec4 view;
+
+vec4 applyWaterFog(vec4 color, vec3 viewVec)
+{
+ //normalize view vector
+ vec3 view = normalize(viewVec);
+ float es = -view.z;
+
+ //find intersection point with water plane and eye vector
+
+ //get eye depth
+ float e0 = max(-waterPlane.w, 0.0);
+
+ //get object depth
+ float depth = length(viewVec);
+
+ //get "thickness" of water
+ float l = max(depth, 0.1);
+
+ float kd = waterFogDensity;
+ float ks = waterFogKS;
+ vec4 kc = waterFogColor;
+
+ float F = 0.98;
+
+ float t1 = -kd * pow(F, ks * e0);
+ float t2 = kd + ks * es;
+ float t3 = pow(F, t2*l) - 1.0;
+
+ float L = min(t1/t2*t3, 1.0);
+
+ float D = pow(0.98, l*kd);
+ //return vec4(1.0, 0.0, 1.0, 1.0);
+ return color * D + kc * L;
+ //depth /= 10.0;
+ //return vec4(depth,depth,depth,0.0);
+}
+
+void main()
+{
+ vec4 color;
+
+ //get detail normals
+ vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
+ vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
+ vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
+ vec3 wavef = normalize(wave1+wave2+wave3);
+
+ //figure out distortion vector (ripply)
+ vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
+ distort = distort+wavef.xy*refScale;
+
+ vec4 fb = texture2D(screenTex, distort);
+
+ gl_FragColor = applyWaterFog(fb,view.xyz);
+}
diff --git a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
index 11a057b177..8f3d11badc 100644
--- a/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class2/environment/waterF.glsl
@@ -1,138 +1,117 @@
-void applyScatter(inout vec3 color);
+/**
+ * @file waterF.glsl
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+vec3 scaleSoftClip(vec3 inColor);
+vec3 atmosTransport(vec3 inColor);
-uniform sampler2D diffuseMap;
uniform sampler2D bumpMap;
-uniform samplerCube environmentMap; //: TEXUNIT4, // Environment map texture
-uniform sampler2D screenTex; // : TEXUNIT5
+uniform sampler2D screenTex;
+uniform sampler2D refTex;
+uniform float sunAngle;
+uniform float sunAngle2;
uniform vec3 lightDir;
uniform vec3 specular;
uniform float lightExp;
-uniform vec2 fbScale;
uniform float refScale;
+uniform float kd;
+uniform vec2 screenRes;
+uniform vec3 normScale;
+uniform float fresnelScale;
+uniform float fresnelOffset;
+uniform float blurMultiplier;
-float msin(float x) {
- float k = sin(x)+1.0;
- k *= 0.5;
- k *= k;
- return 2.0 * k;
-}
-float mcos(float x) {
- float k = cos(x)+1.0;
- k *= 0.5;
- k *= k;
- return 2.0 * k;
-}
+//bigWave is (refCoord.w, view.w);
+varying vec4 refCoord;
+varying vec4 littleWave;
+varying vec4 view;
-float waveS(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap)
+void main()
{
- return texture1D(sinMap, (dot(d, v)*f + t*s)*f).r*a;
-}
+ vec4 color;
+
+ float dist = length(view.xy);
+
+ //normalize view vector
+ vec3 viewVec = normalize(view.xyz);
+
+ //get wave normals
+ vec3 wave1 = texture2D(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
+ vec3 wave2 = texture2D(bumpMap, littleWave.xy).xyz*2.0-1.0;
+ vec3 wave3 = texture2D(bumpMap, littleWave.zw).xyz*2.0-1.0;
+ //get base fresnel components
+
+ vec3 df = vec3(
+ dot(viewVec, wave1),
+ dot(viewVec, wave2),
+ dot(viewVec, wave3)
+ ) * fresnelScale + fresnelOffset;
+ df *= df;
+
+ vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
+
+ float dist2 = dist;
+ dist = max(dist, 5.0);
+
+ float dmod = sqrt(dist);
+
+ vec2 dmod_scale = vec2(dmod*dmod, dmod);
+
+ //get reflected color
+ vec2 refdistort1 = wave1.xy*normScale.x;
+ vec2 refvec1 = distort+refdistort1/dmod_scale;
+ vec4 refcol1 = texture2D(refTex, refvec1);
+
+ vec2 refdistort2 = wave2.xy*normScale.y;
+ vec2 refvec2 = distort+refdistort2/dmod_scale;
+ vec4 refcol2 = texture2D(refTex, refvec2);
+
+ vec2 refdistort3 = wave3.xy*normScale.z;
+ vec2 refvec3 = distort+refdistort3/dmod_scale;
+ vec4 refcol3 = texture2D(refTex, refvec3);
-float waveC(vec2 v, float t, float a, float f, vec2 d, float s, sampler1D sinMap)
-{
- return texture1D(sinMap, (dot(d, v)*f + t*s)*f).g*a*2.0-1.0;
-}
+ vec4 refcol = refcol1 + refcol2 + refcol3;
+ float df1 = df.x + df.y + df.z;
+ refcol *= df1 * 0.333;
+
+ vec3 wavef = (wave1 + wave2 * 0.4 + wave3 * 0.6) * 0.5;
+
+ wavef.z *= max(-viewVec.z, 0.1);
+ wavef = normalize(wavef);
+
+ float df2 = dot(viewVec, wavef) * fresnelScale+fresnelOffset;
+
+ vec2 refdistort4 = wavef.xy*0.125;
+ refdistort4.y -= abs(refdistort4.y);
+ vec2 refvec4 = distort+refdistort4/dmod;
+ float dweight = min(dist2*blurMultiplier, 1.0);
+ vec4 baseCol = texture2D(refTex, refvec4);
+ refcol = mix(baseCol*df2, refcol, dweight);
-float magnitude(vec3 vec) {
- return sqrt(dot(vec,vec));
-}
-
-vec3 mreflect(vec3 i, vec3 n) {
- return i + n * 2.0 * abs(dot(n,i))+vec3(0.0,0.0,0.5);
-}
-
-void main()
-{
- vec2 texCoord = gl_TexCoord[0].xy; // Texture coordinates
- vec2 littleWave1 = gl_TexCoord[0].zw;
- vec2 littleWave2 = gl_TexCoord[1].xy;
- vec2 bigWave = gl_TexCoord[1].zw;
- vec3 viewVec = gl_TexCoord[2].xyz;
- vec4 refCoord = gl_TexCoord[3];
- vec4 col = gl_Color;
- vec4 color;
-
- //get color from alpha map (alpha denotes water depth), rgb denotes water color
- vec4 wcol = texture2D(diffuseMap, texCoord.xy);
-
- //store texture alpha
- float da = wcol.a;
-
- //modulate by incoming water color
- //wcol.a *= refCoord.w;
-
- //scale wcol.a (water depth) for steep transition
- wcol.a *= wcol.a;
-
- //normalize view vector
- viewVec = normalize(viewVec);
-
- //get bigwave normal
- vec3 wavef = texture2D(bumpMap, bigWave).xyz*2.0;
-
- vec3 view = vec3(viewVec.x, viewVec.y, viewVec.z);
-
- float dx = 1.0-(dot(wavef*2.0-vec3(1.0), view))*da;
- dx *= 0.274;
-
- //get detail normals
- vec3 dcol = texture2D(bumpMap, littleWave1+dx*view.xy).rgb*0.75;
- dcol += texture2D(bumpMap, littleWave2+view.xy*dx*0.1).rgb*1.25;
-
- //interpolate between big waves and little waves (big waves in deep water)
- wavef = wavef*wcol.a + dcol*(1.0-wcol.a);
-
- //crunch normal to range [-1,1]
- wavef -= vec3(1,1,1);
-
- //get base fresnel component
- float df = dot(viewVec,wavef);
- //reposition fresnel to latter half of [0,1]
- df = 1.0-clamp(df,0.0,1.0);
+ //get specular component
+ float spec = clamp(dot(lightDir, (reflect(viewVec,wavef))),0.0,1.0);
+
+ //harden specular
+ spec = pow(spec, 128.0);
- //set output alpha based on fresnel
- color.a = clamp((df+da)*0.5,0.0,1.0);
-
- //calculate reflection vector
- vec3 ref = reflect(viewVec.xyz, wavef);
-
- //get specular component
- float spec = clamp(dot(lightDir, normalize(ref)),0.0,1.0);
-
- //fudge reflection to be more noisy at good angles
- ref.z = ref.z*ref.z+df*df*0.5;
-
- //get diffuse component
- float diff = clamp((abs(dot(ref, wavef))),0.0,1.0)*0.9;
-
- //fudge diffuse for extra contrast and ambience
- diff *= diff;
- diff += 0.4;
-
- //set diffuse color contribution
- color.rgb = textureCube(environmentMap, ref).rgb*diff;
-
- //harden specular
- spec = pow(spec, lightExp);
-
- //add specular color contribution
- color.rgb += spec * specular;
+ //figure out distortion vector (ripply)
+ vec2 distort2 = distort+wavef.xy*refScale/max(dmod*df1, 1.0);
+
+ vec4 fb = texture2D(screenTex, distort2);
+
+ //mix with reflection
+ // Note we actually want to use just df1, but multiplying by 0.999999 gets around and nvidia compiler bug
+ color.rgb = mix(fb.rgb, refcol.rgb, df1 * 0.99999);
+ color.rgb += spec * specular;
+
+ color.rgb = atmosTransport(color.rgb);
+ color.rgb = scaleSoftClip(color.rgb);
+ color.a = spec * sunAngle2;
- //figure out distortion vector (ripply)
- vec2 distort = clamp(((refCoord.xy/refCoord.z) * 0.5 + 0.5 + wavef.xy*refScale),0.0,0.99);
-
- //read from framebuffer (offset)
- vec4 fb = texture2D(screenTex, distort*fbScale);
-
- //tint by framebuffer
- color.rgb = color.a*color.rgb + (1.0-color.a)*fb.rgb;
-
- //apply fog
- applyScatter(color.rgb);
-
- color.a = spec*0.5+fb.a;
-
- gl_FragColor = color;
+ gl_FragColor = color;
}
diff --git a/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl b/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl
new file mode 100644
index 0000000000..522c990cf8
--- /dev/null
+++ b/indra/newview/app_settings/shaders/class2/environment/waterFogF.glsl
@@ -0,0 +1,54 @@
+/**
+ * @file waterFogF.glsl
+ *
+ * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
+ * $License$
+ */
+
+uniform vec4 lightnorm;
+uniform vec4 waterPlane;
+uniform vec4 waterFogColor;
+uniform float waterFogDensity;
+uniform float waterFogKS;
+
+vec3 getPositionEye();
+
+vec4 applyWaterFog(vec4 color)
+{
+ //normalize view vector
+ vec3 view = normalize(getPositionEye());
+ float es = -(dot(view, waterPlane.xyz));
+
+ //find intersection point with water plane and eye vector
+
+ //get eye depth
+ float e0 = max(-waterPlane.w, 0.0);
+
+ vec3 int_v = waterPlane.w > 0.0 ? view * waterPlane.w/es : vec3(0.0, 0.0, 0.0);
+
+ //get object depth
+ float depth = length(getPositionEye() - int_v);
+
+ //get "thickness" of water
+ float l = max(depth, 0.1);
+
+ float kd = waterFogDensity;
+ float ks = waterFogKS;
+ vec4 kc = waterFogColor;
+
+ float F = 0.98;
+
+ float t1 = -kd * pow(F, ks * e0);
+ float t2 = kd + ks * es;
+ float t3 = pow(F, t2*l) - 1.0;
+
+ float L = min(t1/t2*t3, 1.0);
+
+ float D = pow(0.98, l*kd);
+
+ color.rgb = color.rgb * D + kc.rgb * L;
+ color.a = kc.a + color.a;
+
+ return color;
+}
+