ソースを参照

Underwater Fixes

- Caustics now respects the passed in water plane rather than assume
that the water plane is on the XY plane.  This allows for caustics to
work for steep rivers.
- Fixed lerp() warning in underwaterFogP.hlsl.
- Cleaned up turbulence and caustics PostEffect scripts to remove unused
items.
- Caustics are now enabled and disabled based on the control object
being underwater, just like turbulence.  Moved this code to fog.cs to be
with the underwater postFX.
DavidWyand-GG 12 年 前
コミット
3baf6d83c4

+ 0 - 19
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 ); 
-}
-

+ 13 - 0
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;
+}

+ 1 - 21
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;
-}

+ 16 - 6
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;   

+ 1 - 1
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 );        
 }

+ 0 - 18
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 ); 
-}
-

+ 13 - 0
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;
+}

+ 1 - 21
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;
-}

+ 16 - 6
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;   

+ 1 - 1
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 );        
 }