diff --git a/Templates/Empty/game/core/scripts/client/postFx/caustics.cs b/Templates/Empty/game/core/scripts/client/postFx/caustics.cs index c24176e48..c6a694c51 100644 --- a/Templates/Empty/game/core/scripts/client/postFx/caustics.cs +++ b/Templates/Empty/game/core/scripts/client/postFx/caustics.cs @@ -20,7 +20,6 @@ // IN THE SOFTWARE. //----------------------------------------------------------------------------- - singleton GFXStateBlockData( PFX_CausticsStateBlock : PFX_DefaultStateBlock ) { blendDefined = true; @@ -42,16 +41,11 @@ singleton ShaderData( PFX_CausticsShader ) //OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl"; //OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl"; - samplerNames[0] = "$prepassTex"; - samplerNames[1] = "$causticsTex1"; - samplerNames[2] = "$causticsTex2"; - pixVersion = 3.0; }; singleton PostEffect( CausticsPFX ) { - requirements = "None"; isEnabled = false; renderTime = "PFXBeforeBin"; renderBin = "ObjTranslucentBin"; @@ -63,17 +57,4 @@ singleton PostEffect( CausticsPFX ) texture[1] = "textures/caustics_1"; texture[2] = "textures/caustics_2"; target = "$backBuffer"; - }; - -// this effects the timing of the animation - - -$CausticsPFX::refTime = getSimTime(); - -function CausticsPFX::setShaderConsts(%this) -{ - //echo($Sim::time - %this.timeStart); - //echo(%this.timeConst); - %this.setShaderConst( "$refTime", $CausticsPFX::refTime ); -} - diff --git a/Templates/Empty/game/core/scripts/client/postFx/fog.cs b/Templates/Empty/game/core/scripts/client/postFx/fog.cs index 44539cb0b..5257db595 100644 --- a/Templates/Empty/game/core/scripts/client/postFx/fog.cs +++ b/Templates/Empty/game/core/scripts/client/postFx/fog.cs @@ -117,3 +117,16 @@ singleton PostEffect( UnderwaterFogPostFx ) isEnabled = true; }; +function UnderwaterFogPostFx::onEnabled( %this ) +{ + TurbulenceFx.enable(); + CausticsPFX.enable(); + return true; +} + +function UnderwaterFogPostFx::onDisabled( %this ) +{ + TurbulenceFx.disable(); + CausticsPFX.disable(); + return false; +} diff --git a/Templates/Empty/game/core/scripts/client/postFx/turbulence.cs b/Templates/Empty/game/core/scripts/client/postFx/turbulence.cs index bf63ced07..767470e67 100644 --- a/Templates/Empty/game/core/scripts/client/postFx/turbulence.cs +++ b/Templates/Empty/game/core/scripts/client/postFx/turbulence.cs @@ -40,34 +40,14 @@ singleton ShaderData( PFX_TurbulenceShader ) singleton PostEffect( TurbulenceFx ) { - requirements = "None"; isEnabled = false; allowReflectPass = true; renderTime = "PFXAfterBin"; renderBin = "GlowBin"; - renderPriority = 10; // Render after the glows themselves + renderPriority = 0.5; // Render after the glows themselves shader = PFX_TurbulenceShader; stateBlock=PFX_TurbulenceStateBlock; texture[0] = "$backBuffer"; - - renderPriority = 0.1; }; - -function TurbulenceFx::setShaderConsts(%this) -{ - %this.setShaderConst(%this.timeConst, $Sim::time - %this.timeStart); -} - -function UnderwaterFogPostFx::onEnabled( %this ) -{ - TurbulenceFx.enable(); - return true; -} - -function UnderwaterFogPostFx::onDisabled( %this ) -{ - TurbulenceFx.disable(); - return false; -} \ No newline at end of file diff --git a/Templates/Empty/game/shaders/common/postFx/caustics/causticsP.hlsl b/Templates/Empty/game/shaders/common/postFx/caustics/causticsP.hlsl index f9242734b..c7635027d 100644 --- a/Templates/Empty/game/shaders/common/postFx/caustics/causticsP.hlsl +++ b/Templates/Empty/game/shaders/common/postFx/caustics/causticsP.hlsl @@ -28,23 +28,33 @@ uniform float4 rtParams0; uniform float4 waterFogPlane; uniform float accumTime; +float distanceToPlane(float4 plane, float3 pos) +{ + return (plane.x * pos.x + plane.y * pos.y + plane.z * pos.z) + plane.w; +} + float4 main( PFXVertToPix IN, uniform sampler2D prepassTex :register(S0), uniform sampler2D causticsTex0 :register(S1), - uniform sampler2D causticsTex1 :register(S2), - uniform float2 targetSize : register(C0) ) : COLOR + uniform sampler2D causticsTex1 :register(S2) ) : COLOR { //Sample the pre-pass - float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy; - float4 prePass = prepassUncondition( prepassTex, prepassCoord ); + float4 prePass = prepassUncondition( prepassTex, IN.uv0 ); //Get depth float depth = prePass.w; - clip( 0.9999 - depth ); + if(depth > 0.9999) + return float4(0,0,0,0); //Get world position float3 pos = eyePosWorld + IN.wsEyeRay * depth; + // Check the water depth + float waterDepth = -distanceToPlane(waterFogPlane, pos); + if(waterDepth < 0) + return float4(0,0,0,0); + waterDepth = saturate(waterDepth); + //Use world position X and Y to calculate caustics UV float2 causticsUV0 = (abs(pos.xy * 0.25) % float2(1, 1)); float2 causticsUV1 = (abs(pos.xy * 0.2) % float2(1, 1)); @@ -59,7 +69,7 @@ float4 main( PFXVertToPix IN, caustics *= tex2D(causticsTex1, causticsUV1); //Use normal Z to modulate caustics - float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1); + //float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1); caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth; return caustics; diff --git a/Templates/Empty/game/shaders/common/postFx/underwaterFogP.hlsl b/Templates/Empty/game/shaders/common/postFx/underwaterFogP.hlsl index a0aa90ecd..c01467e29 100644 --- a/Templates/Empty/game/shaders/common/postFx/underwaterFogP.hlsl +++ b/Templates/Empty/game/shaders/common/postFx/underwaterFogP.hlsl @@ -132,7 +132,7 @@ float4 main( PFXVertToPix IN ) : COLOR inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING; //return float4( inColor, 1 ); - float3 outColor = lerp( inColor, fogColor, fogAmt ); + float3 outColor = lerp( inColor, fogColor.rgb, fogAmt ); return float4( hdrEncode( outColor ), 1 ); } \ No newline at end of file diff --git a/Templates/Full/game/core/scripts/client/postFx/caustics.cs b/Templates/Full/game/core/scripts/client/postFx/caustics.cs index e73e112a5..c6a694c51 100644 --- a/Templates/Full/game/core/scripts/client/postFx/caustics.cs +++ b/Templates/Full/game/core/scripts/client/postFx/caustics.cs @@ -41,16 +41,11 @@ singleton ShaderData( PFX_CausticsShader ) //OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl"; //OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl"; - samplerNames[0] = "$prepassTex"; - samplerNames[1] = "$causticsTex1"; - samplerNames[2] = "$causticsTex2"; - pixVersion = 3.0; }; singleton PostEffect( CausticsPFX ) { - requirements = "None"; isEnabled = false; renderTime = "PFXBeforeBin"; renderBin = "ObjTranslucentBin"; @@ -62,17 +57,4 @@ singleton PostEffect( CausticsPFX ) texture[1] = "textures/caustics_1"; texture[2] = "textures/caustics_2"; target = "$backBuffer"; - }; - -// this effects the timing of the animation - - -$CausticsPFX::refTime = getSimTime(); - -function CausticsPFX::setShaderConsts(%this) -{ - //echo($Sim::time - %this.timeStart); - //echo(%this.timeConst); - %this.setShaderConst( "$refTime", $CausticsPFX::refTime ); -} - diff --git a/Templates/Full/game/core/scripts/client/postFx/fog.cs b/Templates/Full/game/core/scripts/client/postFx/fog.cs index 44539cb0b..5257db595 100644 --- a/Templates/Full/game/core/scripts/client/postFx/fog.cs +++ b/Templates/Full/game/core/scripts/client/postFx/fog.cs @@ -117,3 +117,16 @@ singleton PostEffect( UnderwaterFogPostFx ) isEnabled = true; }; +function UnderwaterFogPostFx::onEnabled( %this ) +{ + TurbulenceFx.enable(); + CausticsPFX.enable(); + return true; +} + +function UnderwaterFogPostFx::onDisabled( %this ) +{ + TurbulenceFx.disable(); + CausticsPFX.disable(); + return false; +} diff --git a/Templates/Full/game/core/scripts/client/postFx/turbulence.cs b/Templates/Full/game/core/scripts/client/postFx/turbulence.cs index bf63ced07..767470e67 100644 --- a/Templates/Full/game/core/scripts/client/postFx/turbulence.cs +++ b/Templates/Full/game/core/scripts/client/postFx/turbulence.cs @@ -40,34 +40,14 @@ singleton ShaderData( PFX_TurbulenceShader ) singleton PostEffect( TurbulenceFx ) { - requirements = "None"; isEnabled = false; allowReflectPass = true; renderTime = "PFXAfterBin"; renderBin = "GlowBin"; - renderPriority = 10; // Render after the glows themselves + renderPriority = 0.5; // Render after the glows themselves shader = PFX_TurbulenceShader; stateBlock=PFX_TurbulenceStateBlock; texture[0] = "$backBuffer"; - - renderPriority = 0.1; }; - -function TurbulenceFx::setShaderConsts(%this) -{ - %this.setShaderConst(%this.timeConst, $Sim::time - %this.timeStart); -} - -function UnderwaterFogPostFx::onEnabled( %this ) -{ - TurbulenceFx.enable(); - return true; -} - -function UnderwaterFogPostFx::onDisabled( %this ) -{ - TurbulenceFx.disable(); - return false; -} \ No newline at end of file diff --git a/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl b/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl index f9242734b..c7635027d 100644 --- a/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl @@ -28,23 +28,33 @@ uniform float4 rtParams0; uniform float4 waterFogPlane; uniform float accumTime; +float distanceToPlane(float4 plane, float3 pos) +{ + return (plane.x * pos.x + plane.y * pos.y + plane.z * pos.z) + plane.w; +} + float4 main( PFXVertToPix IN, uniform sampler2D prepassTex :register(S0), uniform sampler2D causticsTex0 :register(S1), - uniform sampler2D causticsTex1 :register(S2), - uniform float2 targetSize : register(C0) ) : COLOR + uniform sampler2D causticsTex1 :register(S2) ) : COLOR { //Sample the pre-pass - float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy; - float4 prePass = prepassUncondition( prepassTex, prepassCoord ); + float4 prePass = prepassUncondition( prepassTex, IN.uv0 ); //Get depth float depth = prePass.w; - clip( 0.9999 - depth ); + if(depth > 0.9999) + return float4(0,0,0,0); //Get world position float3 pos = eyePosWorld + IN.wsEyeRay * depth; + // Check the water depth + float waterDepth = -distanceToPlane(waterFogPlane, pos); + if(waterDepth < 0) + return float4(0,0,0,0); + waterDepth = saturate(waterDepth); + //Use world position X and Y to calculate caustics UV float2 causticsUV0 = (abs(pos.xy * 0.25) % float2(1, 1)); float2 causticsUV1 = (abs(pos.xy * 0.2) % float2(1, 1)); @@ -59,7 +69,7 @@ float4 main( PFXVertToPix IN, caustics *= tex2D(causticsTex1, causticsUV1); //Use normal Z to modulate caustics - float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1); + //float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1); caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth; return caustics; diff --git a/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl b/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl index a0aa90ecd..c01467e29 100644 --- a/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl +++ b/Templates/Full/game/shaders/common/postFx/underwaterFogP.hlsl @@ -132,7 +132,7 @@ float4 main( PFXVertToPix IN ) : COLOR inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING; //return float4( inColor, 1 ); - float3 outColor = lerp( inColor, fogColor, fogAmt ); + float3 outColor = lerp( inColor, fogColor.rgb, fogAmt ); return float4( hdrEncode( outColor ), 1 ); } \ No newline at end of file