Skip to content
Snippets Groups Projects
Commit 6472b75b authored by David Parks's avatar David Parks
Browse files

SL-20611 Followup -- fix edge cases with transparent objects around eye/object above/below water.

parent c573d27e
No related branches found
No related tags found
No related merge requests found
...@@ -35,19 +35,19 @@ in vec3 vary_position; ...@@ -35,19 +35,19 @@ in vec3 vary_position;
in vec4 vertex_color; in vec4 vertex_color;
in vec2 vary_texcoord0; in vec2 vary_texcoord0;
vec4 applyWaterFogViewLinear(vec3 pos, vec4 color);
vec3 srgb_to_linear(vec3 cs); vec3 srgb_to_linear(vec3 cs);
vec3 linear_to_srgb(vec3 cl); vec3 linear_to_srgb(vec3 cl);
vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten);
void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive, out vec3 atten);
#ifdef HAS_ALPHA_MASK #ifdef HAS_ALPHA_MASK
uniform float minimum_alpha; uniform float minimum_alpha;
#endif #endif
#ifdef IS_ALPHA #ifdef IS_ALPHA
uniform vec4 waterPlane;
void waterClip(vec3 pos); void waterClip(vec3 pos);
void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, out vec3 sunlit, out vec3 amblit, out vec3 additive,
out vec3 atten);
vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
#endif #endif
void main() void main()
...@@ -77,21 +77,20 @@ void main() ...@@ -77,21 +77,20 @@ void main()
vec3 pos = vary_position; vec3 pos = vary_position;
#ifndef IS_HUD #ifndef IS_HUD
color.rgb = srgb_to_linear(color.rgb);
color.a = final_alpha;
#ifdef IS_ALPHA
vec3 sunlit; vec3 sunlit;
vec3 amblit; vec3 amblit;
vec3 additive; vec3 additive;
vec3 atten; vec3 atten;
calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten); calcAtmosphericVars(pos.xyz, vec3(0), 1.0, sunlit, amblit, additive, atten);
color.rgb = srgb_to_linear(color.rgb); color.rgb = applySkyAndWaterFog(pos, additive, atten, color).rgb;
#ifdef IS_ALPHA
color.rgb = atmosFragLighting(color.rgb, additive, atten);
#endif #endif
vec4 fogged = applyWaterFogViewLinear(pos, vec4(color.rgb, final_alpha));
color.rgb = fogged.rgb;
color.a = fogged.a;
#endif #endif
frag_color = max(color, vec4(0)); frag_color = max(color, vec4(0));
......
...@@ -33,6 +33,8 @@ uniform float waterFogKS; ...@@ -33,6 +33,8 @@ uniform float waterFogKS;
vec3 srgb_to_linear(vec3 col); vec3 srgb_to_linear(vec3 col);
vec3 linear_to_srgb(vec3 col); vec3 linear_to_srgb(vec3 col);
vec3 atmosFragLighting(vec3 light, vec3 additive, vec3 atten);
// get a water fog color that will apply the appropriate haze to a color given // get a water fog color that will apply the appropriate haze to a color given
// a blend function of (ONE, SOURCE_ALPHA) // a blend function of (ONE, SOURCE_ALPHA)
vec4 getWaterFogViewNoClip(vec3 pos) vec4 getWaterFogViewNoClip(vec3 pos)
...@@ -108,3 +110,35 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color) ...@@ -108,3 +110,35 @@ vec4 applyWaterFogViewLinear(vec3 pos, vec4 color)
return applyWaterFogViewLinearNoClip(pos, color); return applyWaterFogViewLinearNoClip(pos, color);
} }
// for post deferred shaders, apply sky and water fog in a way that is consistent with
// the deferred rendering haze post effects
vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color)
{
bool eye_above_water = dot(vec3(0), waterPlane.xyz) + waterPlane.w > 0.0;
bool obj_above_water = dot(pos.xyz, waterPlane.xyz) + waterPlane.w > 0.0;
if (eye_above_water)
{
if (!obj_above_water)
{
color.rgb = applyWaterFogViewLinearNoClip(pos, color).rgb;
}
else
{
color.rgb = atmosFragLighting(color.rgb, additive, atten);
}
}
else
{
if (obj_above_water)
{
color.rgb = atmosFragLighting(color.rgb, additive, atten);
}
else
{
color.rgb = applyWaterFogViewLinearNoClip(pos, color).rgb;
}
}
return color;
}
...@@ -65,14 +65,11 @@ uniform vec3 light_diffuse[8]; ...@@ -65,14 +65,11 @@ uniform vec3 light_diffuse[8];
void waterClip(vec3 pos); void waterClip(vec3 pos);
vec4 applyWaterFogViewLinear(vec3 pos, vec4 color);
vec3 srgb_to_linear(vec3 c); vec3 srgb_to_linear(vec3 c);
vec3 linear_to_srgb(vec3 c); vec3 linear_to_srgb(vec3 c);
vec2 encode_normal (vec3 n); vec2 encode_normal (vec3 n);
vec3 atmosFragLightingLinear(vec3 light, vec3 additive, vec3 atten); vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
#ifdef HAS_SUN_SHADOW #ifdef HAS_SUN_SHADOW
...@@ -283,9 +280,7 @@ void main() ...@@ -283,9 +280,7 @@ void main()
// sum local light contrib in linear colorspace // sum local light contrib in linear colorspace
color.rgb += light.rgb; color.rgb += light.rgb;
color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, color).rgb;
color = applyWaterFogViewLinear(pos.xyz, color);
#endif // #else // FOR_IMPOSTOR #endif // #else // FOR_IMPOSTOR
......
...@@ -85,8 +85,6 @@ void main() ...@@ -85,8 +85,6 @@ void main()
color.rgb = srgb_to_linear(color.rgb); color.rgb = srgb_to_linear(color.rgb);
applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity); applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity);
color.rgb = atmosFragLighting(color.rgb, additive, atten);
color = applyWaterFogViewLinear(pos.xyz, color);
#endif #endif
color.a = 1.0; color.a = 1.0;
......
...@@ -37,9 +37,7 @@ ...@@ -37,9 +37,7 @@
uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 otherwise uniform float emissive_brightness; // fullbright flag, 1.0 == fullbright, 0.0 otherwise
uniform int sun_up_factor; uniform int sun_up_factor;
vec4 applyWaterFogViewLinear(vec3 pos, vec4 color); vec4 applySkyAndWaterFog(vec3 pos, vec3 additive, vec3 atten, vec4 color);
vec3 atmosFragLightingLinear(vec3 l, vec3 additive, vec3 atten);
vec3 scaleSoftClipFragLinear(vec3 l); vec3 scaleSoftClipFragLinear(vec3 l);
void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive); void calcAtmosphericVarsLinear(vec3 inPositionEye, vec3 norm, vec3 light_dir, out vec3 sunlit, out vec3 amblit, out vec3 atten, out vec3 additive);
void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist); void calcHalfVectors(vec3 lv, vec3 n, vec3 v, out vec3 h, out vec3 l, out float nh, out float nl, out float nv, out float vh, out float lightDist);
...@@ -399,10 +397,7 @@ void main() ...@@ -399,10 +397,7 @@ void main()
color += light; color += light;
color.rgb = atmosFragLightingLinear(color.rgb, additive, atten); color.rgb = applySkyAndWaterFog(pos.xyz, additive, atten, vec4(color, 1.0)).rgb;
vec4 temp = applyWaterFogViewLinear(pos, vec4(color, 0.0));
color = temp.rgb;
glare *= 1.0-emissive; glare *= 1.0-emissive;
glare = min(glare, 1.0); glare = min(glare, 1.0);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment