summaryrefslogtreecommitdiff
path: root/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/app_settings/shaders/class1/deferred/materialF.glsl')
-rw-r--r--indra/newview/app_settings/shaders/class1/deferred/materialF.glsl65
1 files changed, 55 insertions, 10 deletions
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
index 027c6eeadb..9ce4d89df7 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialF.glsl
@@ -51,7 +51,6 @@ vec3 linear_to_srgb(vec3 cl)
return 1.055 * pow(cl, vec3(0.41666)) - 0.055;
}
-
#if (DIFFUSE_ALPHA_MODE == DIFFUSE_ALPHA_MODE_BLEND)
#ifdef DEFINE_GL_FRAGCOLOR
@@ -136,6 +135,52 @@ uniform vec3 light_direction[8];
uniform vec3 light_attenuation[8];
uniform vec3 light_diffuse[8];
+#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 calcDirectionalLight(vec3 n, vec3 l)
{
float a = max(dot(n,l),0.0);
@@ -221,10 +266,6 @@ vec4 getPosition_d(vec2 pos_screen, float depth)
return pos;
}
-vec3 getPositionEye()
-{
- return vary_PositionEye;
-}
vec3 getSunlitColor()
{
return vary_SunlitColor;
@@ -672,7 +713,6 @@ void main()
//convert to linear space before adding local lights
col = srgb_to_linear(col);
-
vec3 npos = normalize(-pos.xyz);
#define LIGHT_LOOP(i) col.rgb = col.rgb + calcPointLightOrSpotLight(light_diffuse[i].rgb, npos, diffuse.rgb, final_specular, pos.xyz, norm.xyz, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, glare);
@@ -685,13 +725,17 @@ void main()
LIGHT_LOOP(6)
LIGHT_LOOP(7)
+ glare = min(glare, 1.0);
+ float al = max(diffcol.a,glare)*vertex_color.a;
- //convert to gamma space for display on screen
- col.rgb = linear_to_srgb(col.rgb);
+#ifdef WATER_FOG
+ vec4 temp = applyWaterFogDeferred(pos, vec4(col.rgb, al));
+ col.rgb = temp.rgb;
+ al = temp.a;
+#endif
frag_color.rgb = col.rgb;
- glare = min(glare, 1.0);
- frag_color.a = max(diffcol.a,glare)*vertex_color.a;
+ frag_color.a = al;
#else
frag_data[0] = final_color;
@@ -699,3 +743,4 @@ void main()
frag_data[2] = final_normal; // XY = Normal. Z = Env. intensity.
#endif
}
+