Merge pull request #521 from DavidWyand-GG/CausticsFix

Underwater Fixes
This commit is contained in:
David Wyand 2013-11-04 15:45:39 -08:00
commit af286a33b5
10 changed files with 62 additions and 93 deletions

View file

@ -20,7 +20,6 @@
// IN THE SOFTWARE. // IN THE SOFTWARE.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
singleton GFXStateBlockData( PFX_CausticsStateBlock : PFX_DefaultStateBlock ) singleton GFXStateBlockData( PFX_CausticsStateBlock : PFX_DefaultStateBlock )
{ {
blendDefined = true; blendDefined = true;
@ -42,16 +41,11 @@ singleton ShaderData( PFX_CausticsShader )
//OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl"; //OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl";
//OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl"; //OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl";
samplerNames[0] = "$prepassTex";
samplerNames[1] = "$causticsTex1";
samplerNames[2] = "$causticsTex2";
pixVersion = 3.0; pixVersion = 3.0;
}; };
singleton PostEffect( CausticsPFX ) singleton PostEffect( CausticsPFX )
{ {
requirements = "None";
isEnabled = false; isEnabled = false;
renderTime = "PFXBeforeBin"; renderTime = "PFXBeforeBin";
renderBin = "ObjTranslucentBin"; renderBin = "ObjTranslucentBin";
@ -63,17 +57,4 @@ singleton PostEffect( CausticsPFX )
texture[1] = "textures/caustics_1"; texture[1] = "textures/caustics_1";
texture[2] = "textures/caustics_2"; texture[2] = "textures/caustics_2";
target = "$backBuffer"; 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 );
}

View file

@ -117,3 +117,16 @@ singleton PostEffect( UnderwaterFogPostFx )
isEnabled = true; isEnabled = true;
}; };
function UnderwaterFogPostFx::onEnabled( %this )
{
TurbulenceFx.enable();
CausticsPFX.enable();
return true;
}
function UnderwaterFogPostFx::onDisabled( %this )
{
TurbulenceFx.disable();
CausticsPFX.disable();
return false;
}

View file

@ -40,34 +40,14 @@ singleton ShaderData( PFX_TurbulenceShader )
singleton PostEffect( TurbulenceFx ) singleton PostEffect( TurbulenceFx )
{ {
requirements = "None";
isEnabled = false; isEnabled = false;
allowReflectPass = true; allowReflectPass = true;
renderTime = "PFXAfterBin"; renderTime = "PFXAfterBin";
renderBin = "GlowBin"; renderBin = "GlowBin";
renderPriority = 10; // Render after the glows themselves renderPriority = 0.5; // Render after the glows themselves
shader = PFX_TurbulenceShader; shader = PFX_TurbulenceShader;
stateBlock=PFX_TurbulenceStateBlock; stateBlock=PFX_TurbulenceStateBlock;
texture[0] = "$backBuffer"; 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;
}

View file

@ -28,23 +28,33 @@ uniform float4 rtParams0;
uniform float4 waterFogPlane; uniform float4 waterFogPlane;
uniform float accumTime; 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, float4 main( PFXVertToPix IN,
uniform sampler2D prepassTex :register(S0), uniform sampler2D prepassTex :register(S0),
uniform sampler2D causticsTex0 :register(S1), uniform sampler2D causticsTex0 :register(S1),
uniform sampler2D causticsTex1 :register(S2), uniform sampler2D causticsTex1 :register(S2) ) : COLOR
uniform float2 targetSize : register(C0) ) : COLOR
{ {
//Sample the pre-pass //Sample the pre-pass
float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy; float4 prePass = prepassUncondition( prepassTex, IN.uv0 );
float4 prePass = prepassUncondition( prepassTex, prepassCoord );
//Get depth //Get depth
float depth = prePass.w; float depth = prePass.w;
clip( 0.9999 - depth ); if(depth > 0.9999)
return float4(0,0,0,0);
//Get world position //Get world position
float3 pos = eyePosWorld + IN.wsEyeRay * depth; 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 //Use world position X and Y to calculate caustics UV
float2 causticsUV0 = (abs(pos.xy * 0.25) % float2(1, 1)); float2 causticsUV0 = (abs(pos.xy * 0.25) % float2(1, 1));
float2 causticsUV1 = (abs(pos.xy * 0.2) % 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); caustics *= tex2D(causticsTex1, causticsUV1);
//Use normal Z to modulate caustics //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; caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth;
return caustics; return caustics;

View file

@ -132,7 +132,7 @@ float4 main( PFXVertToPix IN ) : COLOR
inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING; inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING;
//return float4( inColor, 1 ); //return float4( inColor, 1 );
float3 outColor = lerp( inColor, fogColor, fogAmt ); float3 outColor = lerp( inColor, fogColor.rgb, fogAmt );
return float4( hdrEncode( outColor ), 1 ); return float4( hdrEncode( outColor ), 1 );
} }

View file

@ -41,16 +41,11 @@ singleton ShaderData( PFX_CausticsShader )
//OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl"; //OGLVertexShaderFile = "shaders/common/postFx/gl//postFxV.glsl";
//OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl"; //OGLPixelShaderFile = "shaders/common/postFx/gl/passthruP.glsl";
samplerNames[0] = "$prepassTex";
samplerNames[1] = "$causticsTex1";
samplerNames[2] = "$causticsTex2";
pixVersion = 3.0; pixVersion = 3.0;
}; };
singleton PostEffect( CausticsPFX ) singleton PostEffect( CausticsPFX )
{ {
requirements = "None";
isEnabled = false; isEnabled = false;
renderTime = "PFXBeforeBin"; renderTime = "PFXBeforeBin";
renderBin = "ObjTranslucentBin"; renderBin = "ObjTranslucentBin";
@ -62,17 +57,4 @@ singleton PostEffect( CausticsPFX )
texture[1] = "textures/caustics_1"; texture[1] = "textures/caustics_1";
texture[2] = "textures/caustics_2"; texture[2] = "textures/caustics_2";
target = "$backBuffer"; 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 );
}

View file

@ -117,3 +117,16 @@ singleton PostEffect( UnderwaterFogPostFx )
isEnabled = true; isEnabled = true;
}; };
function UnderwaterFogPostFx::onEnabled( %this )
{
TurbulenceFx.enable();
CausticsPFX.enable();
return true;
}
function UnderwaterFogPostFx::onDisabled( %this )
{
TurbulenceFx.disable();
CausticsPFX.disable();
return false;
}

View file

@ -40,34 +40,14 @@ singleton ShaderData( PFX_TurbulenceShader )
singleton PostEffect( TurbulenceFx ) singleton PostEffect( TurbulenceFx )
{ {
requirements = "None";
isEnabled = false; isEnabled = false;
allowReflectPass = true; allowReflectPass = true;
renderTime = "PFXAfterBin"; renderTime = "PFXAfterBin";
renderBin = "GlowBin"; renderBin = "GlowBin";
renderPriority = 10; // Render after the glows themselves renderPriority = 0.5; // Render after the glows themselves
shader = PFX_TurbulenceShader; shader = PFX_TurbulenceShader;
stateBlock=PFX_TurbulenceStateBlock; stateBlock=PFX_TurbulenceStateBlock;
texture[0] = "$backBuffer"; 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;
}

View file

@ -28,23 +28,33 @@ uniform float4 rtParams0;
uniform float4 waterFogPlane; uniform float4 waterFogPlane;
uniform float accumTime; 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, float4 main( PFXVertToPix IN,
uniform sampler2D prepassTex :register(S0), uniform sampler2D prepassTex :register(S0),
uniform sampler2D causticsTex0 :register(S1), uniform sampler2D causticsTex0 :register(S1),
uniform sampler2D causticsTex1 :register(S2), uniform sampler2D causticsTex1 :register(S2) ) : COLOR
uniform float2 targetSize : register(C0) ) : COLOR
{ {
//Sample the pre-pass //Sample the pre-pass
float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy; float4 prePass = prepassUncondition( prepassTex, IN.uv0 );
float4 prePass = prepassUncondition( prepassTex, prepassCoord );
//Get depth //Get depth
float depth = prePass.w; float depth = prePass.w;
clip( 0.9999 - depth ); if(depth > 0.9999)
return float4(0,0,0,0);
//Get world position //Get world position
float3 pos = eyePosWorld + IN.wsEyeRay * depth; 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 //Use world position X and Y to calculate caustics UV
float2 causticsUV0 = (abs(pos.xy * 0.25) % float2(1, 1)); float2 causticsUV0 = (abs(pos.xy * 0.25) % float2(1, 1));
float2 causticsUV1 = (abs(pos.xy * 0.2) % 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); caustics *= tex2D(causticsTex1, causticsUV1);
//Use normal Z to modulate caustics //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; caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth;
return caustics; return caustics;

View file

@ -132,7 +132,7 @@ float4 main( PFXVertToPix IN ) : COLOR
inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING; inColor.rgb *= 1.0 - saturate( abs( planeDist ) / WET_DEPTH ) * WET_DARKENING;
//return float4( inColor, 1 ); //return float4( inColor, 1 );
float3 outColor = lerp( inColor, fogColor, fogAmt ); float3 outColor = lerp( inColor, fogColor.rgb, fogAmt );
return float4( hdrEncode( outColor ), 1 ); return float4( hdrEncode( outColor ), 1 );
} }