summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred
diff options
context:
space:
mode:
authorGraham Linden <graham@lindenlab.com>2013-07-21 14:28:54 -0700
committerGraham Linden <graham@lindenlab.com>2013-07-21 14:28:54 -0700
commitcaefe0e74cf553de41c6c8748dd2ea5ef4d82c06 (patch)
tree55cdae8ef9376823851babf5a654361cd6e4ff33 /indra/newview/app_settings/shaders/class1/deferred
parent94abe75dea90ee91dd044161d8587279b0bfae13 (diff)
NORSPEC-311 fix alpha / opaque lighting diffs
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred')
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/alphaF.glsl56
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl55
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl73
-rwxr-xr-xindra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl9
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl2
5 files changed, 186 insertions, 9 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
index b64852f17b..69b0f8f012 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/alphaF.glsl
@@ -136,6 +136,52 @@ float pcfShadow(sampler2DShadow shadowMap, vec4 stc)
}
#endif
+#if WATER_FOG
+uniform vec4 waterPlane;
+uniform vec4 waterFogColor;
+uniform float waterFogDensity;
+uniform float waterFogKS;
+
+vec4 applyWaterFogDeferred(vec3 pos, vec4 color)
+{
+ //normalize view vector
+ vec3 view = normalize(pos);
+ 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(pos - 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;
+}
+#endif
+
vec3 srgb_to_linear(vec3 cs)
{
@@ -240,8 +286,9 @@ void main()
vec4 gamma_diff = diff;
diff.rgb = srgb_to_linear(diff.rgb);
-
+
#ifdef USE_VERTEX_COLOR
+ diff.rgb *= vertex_color.rgb;
float vertex_color_alpha = vertex_color.a;
#else
float vertex_color_alpha = 1.0;
@@ -266,6 +313,7 @@ void main()
color.rgb = scaleSoftClip(color.rgb);
color.rgb = srgb_to_linear(color.rgb);
+
col = vec4(0,0,0,0);
#define LIGHT_LOOP(i) col.rgb += light_diffuse[i].rgb * calcPointLightOrSpotLight(pos.xyz, normal, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z);
@@ -281,7 +329,11 @@ void main()
color.rgb += diff.rgb * vary_pointlight_col_linear * col.rgb;
color.rgb = linear_to_srgb(color.rgb);
- //color.rgb = vec3(1,0,1);
+
+#if WATER_FOG
+ color = applyWaterFogDeferred(pos.xyz, color);
+#endif
+
frag_color = color;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl
index a74256de81..00743abe34 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightAlphaMaskF.glsl
@@ -61,6 +61,52 @@ vec3 linear_to_srgb(vec3 cl)
return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
}
+#ifdef WATER_FOG
+uniform vec4 waterPlane;
+uniform vec4 waterFogColor;
+uniform float waterFogDensity;
+uniform float waterFogKS;
+
+vec4 applyWaterFogDeferred(vec3 pos, vec4 color)
+{
+ //normalize view vector
+ vec3 view = normalize(pos);
+ 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(pos - 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;
+}
+#endif
+
uniform float minimum_alpha;
void main()
@@ -72,7 +118,7 @@ void main()
#endif
float final_alpha = color.a * vertex_color.a;
- if (final_alpha < minimum_alpha)
+ if (color.a < minimum_alpha)
{
discard;
}
@@ -84,7 +130,12 @@ void main()
color.rgb = fullbrightScaleSoftClip(color.rgb);
color.rgb = linear_to_srgb(color.rgb);
- //color.rgb = vec3(1,0,1);
+
+
+#ifdef WATER_FOG
+ color = applyWaterFogDeferred(pos, vec4(color));
+#endif
+
frag_color.rgb = color.rgb;
frag_color.a = final_alpha;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
index 5876efedec..1e8df68a72 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightF.glsl
@@ -35,12 +35,63 @@ out vec4 frag_color;
uniform sampler2D diffuseMap;
#endif
+VARYING vec3 vary_position;
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
vec3 fullbrightAtmosTransport(vec3 light);
vec3 fullbrightScaleSoftClip(vec3 light);
+#if HAS_ALPHA_MASK
+uniform float minimum_alpha;
+#endif
+
+#ifdef WATER_FOG
+uniform vec4 waterPlane;
+uniform vec4 waterFogColor;
+uniform float waterFogDensity;
+uniform float waterFogKS;
+
+vec4 applyWaterFogDeferred(vec3 pos, vec4 color)
+{
+ //normalize view vector
+ vec3 view = normalize(pos);
+ 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(pos - 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;
+}
+#endif
+
vec3 srgb_to_linear(vec3 cs)
{
@@ -69,15 +120,31 @@ void main()
vec4 color = texture2D(diffuseMap, vary_texcoord0.xy);
#endif
+ float final_alpha = color.a * vertex_color.a;
+
+#if HAS_ALPHA_MASK
+ if (color.a < minimum_alpha)
+ {
+ discard;
+ }
+#endif
- color.rgb = srgb_to_linear(color.rgb);
color.rgb *= vertex_color.rgb;
+ color.rgb = srgb_to_linear(color.rgb);
+
color.rgb = fullbrightAtmosTransport(color.rgb);
color.rgb = fullbrightScaleSoftClip(color.rgb);
-
+
color.rgb = linear_to_srgb(color.rgb);
- //color.rgb = vec3(1,0,1);
+
+#ifdef WATER_FOG
+ vec3 pos = vary_position;
+ vec4 fogged = applyWaterFogDeferred(pos, vec4(color.rgb, final_alpha));
+ color.rgb = fogged.rgb;
+ color.a = fogged.a;
+#endif
+
frag_color.rgb = color.rgb;
frag_color.a = color.a;
}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl
index 3f09a15375..22f47b7572 100755
--- a/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/fullbrightV.glsl
@@ -40,6 +40,9 @@ vec3 atmosAffectDirectionalLight(float lightIntensity);
vec3 scaleDownLight(vec3 light);
vec3 scaleUpLight(vec3 light);
+#if WATER_FOG
+VARYING vec3 vary_position;
+#endif
VARYING vec4 vertex_color;
VARYING vec2 vary_texcoord0;
@@ -53,7 +56,11 @@ void main()
passTextureIndex();
gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
-
+
+#if WATER_FOG
+ vary_position = pos.xyz;
+#endif
+
vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
calcAtmospherics(pos.xyz);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
index a3610bfffa..59b027a045 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
@@ -51,7 +51,7 @@ vec3 linear_to_srgb(vec3 cl)
void main()
{
vec4 diff = texture2DRect(diffuseRect, vary_fragcoord);
- diff.rgb = linear_to_srgb(diff.rgb);
+ diff.rgb = pow(diff.rgb,vec3(texture_gamma));
frag_color = diff;
}