Browse Source

New PostFx (Underwater, Turbulence, and Camera Based Motion Blur)

Ron Kapaun 12 years ago
parent
commit
f01afa7e9a

+ 47 - 0
Templates/Empty/game/core/scripts/client/postFx/MotionBlurFx.cs

@@ -0,0 +1,47 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+singleton ShaderData( PFX_MotionBlurShader )  
+{     
+   DXVertexShaderFile   = "shaders/common/postFx/postFxV.hlsl";  //we use the bare-bones postFxV.hlsl
+   DXPixelShaderFile    = "shaders/common/postFx/motionBlurP.hlsl";  //new pixel shader
+   
+   pixVersion = 3.0;  
+};  
+
+singleton PostEffect(MotionBlurFX)  
+{
+   isEnabled = false;
+
+   renderTime = "PFXAfterDiffuse";  
+
+   shader = PFX_MotionBlurShader;  
+   stateBlock = PFX_DefaultStateBlock;  
+   texture[0] = "$backbuffer";
+   texture[1] = "#prepass";
+   target = "$backBuffer";
+};
+
+function MotionBlurFX::setShaderConsts(%this)
+{
+   %this.setShaderConst( "$velocityMultiplier", 3000 );
+}

+ 79 - 0
Templates/Empty/game/core/scripts/client/postFx/caustics.cs

@@ -0,0 +1,79 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+
+singleton GFXStateBlockData( PFX_CausticsStateBlock : PFX_DefaultStateBlock )
+{
+   blendDefined = true;
+   blendEnable = true; 
+   blendSrc = GFXBlendOne;
+   blendDest = GFXBlendOne;
+   
+   samplersDefined = true;
+   samplerStates[0] = SamplerClampLinear;
+   samplerStates[1] = SamplerWrapLinear;
+   samplerStates[2] = SamplerWrapLinear;
+};
+
+singleton ShaderData( PFX_CausticsShader )
+{   
+   DXVertexShaderFile 	= "shaders/common/postFx/postFxV.hlsl";
+   DXPixelShaderFile 	= "shaders/common/postFx/caustics/causticsP.hlsl";
+         
+   //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 = true;
+   renderTime = "PFXBeforeBin";
+   renderBin = "ObjTranslucentBin";      
+   //renderPriority = 0.1;
+      
+   shader = PFX_CausticsShader;
+   stateBlock = PFX_CausticsStateBlock;
+   texture[0] = "#prepass";
+   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 ); 
+}
+

BIN
Templates/Empty/game/core/scripts/client/postFx/textures/caustics_1.png


BIN
Templates/Empty/game/core/scripts/client/postFx/textures/caustics_2.png


+ 63 - 0
Templates/Empty/game/core/scripts/client/postFx/turbulence.cs

@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+singleton ShaderData( PFX_TurbulenceShader )
+{   
+   DXVertexShaderFile 	= "shaders/common/postFx/postFxV.hlsl";
+   DXPixelShaderFile 	= "shaders/common/postFx/turbulenceP.hlsl";
+           
+   samplerNames[0] = "$inputTex";
+   pixVersion = 3.0;
+};
+
+singleton PostEffect( TurbulenceFx )  
+{  
+   requirements = "None";
+   isEnabled = false;    
+   allowReflectPass = true;  
+         
+   renderTime = "PFXAfterDiffuse";  
+   renderBin = "ObjTranslucentBin";     
+     
+   shader = PFX_TurbulenceShader;  
+   stateBlock = PFX_myShaderStateBlock;  
+   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;
+}

+ 66 - 0
Templates/Empty/game/shaders/common/postFx/caustics/causticsP.hlsl

@@ -0,0 +1,66 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#include "../postFx.hlsl"
+#include "shadergen:/autogenConditioners.h"
+
+uniform float3    eyePosWorld;
+uniform float4    rtParams0;
+uniform float4    waterFogPlane;
+uniform float     accumTime;
+
+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
+{   
+   //Sample the pre-pass
+   float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy;  
+   float4 prePass = prepassUncondition( prepassTex, prepassCoord );
+   
+   //Get depth
+   float depth = prePass.w;   
+   clip( 0.9999 - depth );
+   
+   //Get world position
+   float3 pos = eyePosWorld + IN.wsEyeRay * depth;
+   
+   //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));
+   
+   //Animate uvs
+   float timeSin = sin(accumTime);
+   causticsUV0.xy += float2(accumTime*0.1, timeSin*0.2);
+   causticsUV1.xy -= float2(accumTime*0.15, timeSin*0.15);   
+   
+   //Sample caustics texture   
+   float4 caustics = tex2D(causticsTex0, causticsUV0);   
+   caustics *= tex2D(causticsTex1, causticsUV1);
+   
+   //Use normal Z to modulate caustics  
+   float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1);
+   caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth; 
+      
+   return caustics;   
+}

+ 71 - 0
Templates/Empty/game/shaders/common/postFx/motionBlurP.hlsl

@@ -0,0 +1,71 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#include "./postFx.hlsl"
+#include "../torque.hlsl"
+#include "shadergen:/autogenConditioners.h"
+
+uniform float4x4 matPrevScreenToWorld;
+uniform float4x4 matWorldToScreen;
+
+// Passed in from setShaderConsts()
+uniform float velocityMultiplier;
+
+uniform sampler2D backBuffer  : register(S0);
+uniform sampler2D prepassTex  : register(S1);
+
+float4 main(PFXVertToPix IN) : COLOR0
+{
+   float samples = 5;
+   
+   // First get the prepass texture for uv channel 0
+   float4 prepass = prepassUncondition( prepassTex, IN.uv0 );
+   
+   // Next extract the depth
+   float depth = prepass.a;
+   
+   // Create the screen position
+   float4 screenPos = float4(IN.uv0.x*2-1, IN.uv0.y*2-1, depth*2-1, 1);
+
+   // Calculate the world position
+   float4 D = mul(screenPos, matWorldToScreen);
+   float4 worldPos = D / D.w;
+   
+   // Now calculate the previous screen position
+   float4 previousPos = mul( worldPos, matPrevScreenToWorld );
+   previousPos /= previousPos.w;
+	
+   // Calculate the XY velocity
+   float2 velocity = ((screenPos - previousPos) / velocityMultiplier).xy;
+   
+   // Generate the motion blur
+   float4 color = tex2D(backBuffer, IN.uv0);
+	IN.uv0 += velocity;
+	
+   for(int i = 1; i<samples; ++i, IN.uv0 += velocity)
+   {
+      float4 currentColor = tex2D(backBuffer, IN.uv0);
+      color += currentColor;
+   }
+   
+   return color / samples;
+}

+ 45 - 0
Templates/Empty/game/shaders/common/postFx/turbulenceP.hlsl

@@ -0,0 +1,45 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#include "./postFx.hlsl"
+
+uniform float  accumTime;
+
+float4 main( PFXVertToPix IN, uniform sampler2D inputTex : register(S0) ) : COLOR
+{
+	float reduction = 128;	
+	float power = 1.0;
+	float speed = 3.0;
+	float frequency=8;
+	
+	float backbuffer_edge_coef=0.98;
+	float2 screen_center = float2(0.5, 0.5);	
+	float2 cPos = (IN.uv0 - screen_center);
+	
+	float len = 1.0 - length(cPos);		
+	float2 uv = clamp((cPos / len * cos(len * frequency - (accumTime * speed)) * (power / reduction)), 0, 1);
+	return tex2D(inputTex, IN.uv0 * backbuffer_edge_coef + uv);
+
+//    float4 color = tex2D(inputTex, IN.uv0 * backbuffer_edge_coef+(sin*right));           
+//	return color;
+
+}

+ 47 - 0
Templates/Full/game/core/scripts/client/postFx/MotionBlurFx.cs

@@ -0,0 +1,47 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+singleton ShaderData( PFX_MotionBlurShader )  
+{     
+   DXVertexShaderFile   = "shaders/common/postFx/postFxV.hlsl";  //we use the bare-bones postFxV.hlsl
+   DXPixelShaderFile    = "shaders/common/postFx/motionBlurP.hlsl";  //new pixel shader
+   
+   pixVersion = 3.0;  
+};  
+
+singleton PostEffect(MotionBlurFX)  
+{
+   isEnabled = false;
+
+   renderTime = "PFXAfterDiffuse";  
+
+   shader = PFX_MotionBlurShader;  
+   stateBlock = PFX_DefaultStateBlock;  
+   texture[0] = "$backbuffer";
+   texture[1] = "#prepass";
+   target = "$backBuffer";
+};
+
+function MotionBlurFX::setShaderConsts(%this)
+{
+   %this.setShaderConst( "$velocityMultiplier", 3000 );
+}

+ 78 - 0
Templates/Full/game/core/scripts/client/postFx/caustics.cs

@@ -0,0 +1,78 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+singleton GFXStateBlockData( PFX_CausticsStateBlock : PFX_DefaultStateBlock )
+{
+   blendDefined = true;
+   blendEnable = true; 
+   blendSrc = GFXBlendOne;
+   blendDest = GFXBlendOne;
+   
+   samplersDefined = true;
+   samplerStates[0] = SamplerClampLinear;
+   samplerStates[1] = SamplerWrapLinear;
+   samplerStates[2] = SamplerWrapLinear;
+};
+
+singleton ShaderData( PFX_CausticsShader )
+{   
+   DXVertexShaderFile 	= "shaders/common/postFx/postFxV.hlsl";
+   DXPixelShaderFile 	= "shaders/common/postFx/caustics/causticsP.hlsl";
+         
+   //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 = true;
+   renderTime = "PFXBeforeBin";
+   renderBin = "ObjTranslucentBin";      
+   //renderPriority = 0.1;
+      
+   shader = PFX_CausticsShader;
+   stateBlock = PFX_CausticsStateBlock;
+   texture[0] = "#prepass";
+   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 ); 
+}
+

BIN
Templates/Full/game/core/scripts/client/postFx/textures/caustics_1.png


BIN
Templates/Full/game/core/scripts/client/postFx/textures/caustics_2.png


+ 63 - 0
Templates/Full/game/core/scripts/client/postFx/turbulence.cs

@@ -0,0 +1,63 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+singleton ShaderData( PFX_TurbulenceShader )
+{   
+   DXVertexShaderFile 	= "shaders/common/postFx/postFxV.hlsl";
+   DXPixelShaderFile 	= "shaders/common/postFx/turbulenceP.hlsl";
+           
+   samplerNames[0] = "$inputTex";
+   pixVersion = 3.0;
+};
+
+singleton PostEffect( TurbulenceFx )  
+{  
+   requirements = "None";
+   isEnabled = false;    
+   allowReflectPass = true;  
+         
+   renderTime = "PFXAfterDiffuse";  
+   renderBin = "ObjTranslucentBin";     
+     
+   shader = PFX_TurbulenceShader;  
+   stateBlock = PFX_myShaderStateBlock;  
+   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;
+}

+ 66 - 0
Templates/Full/game/shaders/common/postFx/caustics/causticsP.hlsl

@@ -0,0 +1,66 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#include "../postFx.hlsl"
+#include "shadergen:/autogenConditioners.h"
+
+uniform float3    eyePosWorld;
+uniform float4    rtParams0;
+uniform float4    waterFogPlane;
+uniform float     accumTime;
+
+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
+{   
+   //Sample the pre-pass
+   float2 prepassCoord = ( IN.uv0.xy * rtParams0.zw ) + rtParams0.xy;  
+   float4 prePass = prepassUncondition( prepassTex, prepassCoord );
+   
+   //Get depth
+   float depth = prePass.w;   
+   clip( 0.9999 - depth );
+   
+   //Get world position
+   float3 pos = eyePosWorld + IN.wsEyeRay * depth;
+   
+   //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));
+   
+   //Animate uvs
+   float timeSin = sin(accumTime);
+   causticsUV0.xy += float2(accumTime*0.1, timeSin*0.2);
+   causticsUV1.xy -= float2(accumTime*0.15, timeSin*0.15);   
+   
+   //Sample caustics texture   
+   float4 caustics = tex2D(causticsTex0, causticsUV0);   
+   caustics *= tex2D(causticsTex1, causticsUV1);
+   
+   //Use normal Z to modulate caustics  
+   float waterDepth = 1 - saturate(pos.z + waterFogPlane.w + 1);
+   caustics *= saturate(prePass.z) * pow(1-depth, 64) * waterDepth; 
+      
+   return caustics;   
+}

+ 71 - 0
Templates/Full/game/shaders/common/postFx/motionBlurP.hlsl

@@ -0,0 +1,71 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#include "./postFx.hlsl"
+#include "../torque.hlsl"
+#include "shadergen:/autogenConditioners.h"
+
+uniform float4x4 matPrevScreenToWorld;
+uniform float4x4 matWorldToScreen;
+
+// Passed in from setShaderConsts()
+uniform float velocityMultiplier;
+
+uniform sampler2D backBuffer  : register(S0);
+uniform sampler2D prepassTex  : register(S1);
+
+float4 main(PFXVertToPix IN) : COLOR0
+{
+   float samples = 5;
+   
+   // First get the prepass texture for uv channel 0
+   float4 prepass = prepassUncondition( prepassTex, IN.uv0 );
+   
+   // Next extract the depth
+   float depth = prepass.a;
+   
+   // Create the screen position
+   float4 screenPos = float4(IN.uv0.x*2-1, IN.uv0.y*2-1, depth*2-1, 1);
+
+   // Calculate the world position
+   float4 D = mul(screenPos, matWorldToScreen);
+   float4 worldPos = D / D.w;
+   
+   // Now calculate the previous screen position
+   float4 previousPos = mul( worldPos, matPrevScreenToWorld );
+   previousPos /= previousPos.w;
+	
+   // Calculate the XY velocity
+   float2 velocity = ((screenPos - previousPos) / velocityMultiplier).xy;
+   
+   // Generate the motion blur
+   float4 color = tex2D(backBuffer, IN.uv0);
+	IN.uv0 += velocity;
+	
+   for(int i = 1; i<samples; ++i, IN.uv0 += velocity)
+   {
+      float4 currentColor = tex2D(backBuffer, IN.uv0);
+      color += currentColor;
+   }
+   
+   return color / samples;
+}

+ 45 - 0
Templates/Full/game/shaders/common/postFx/turbulenceP.hlsl

@@ -0,0 +1,45 @@
+//-----------------------------------------------------------------------------
+// Copyright (c) 2012 GarageGames, LLC
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to
+// deal in the Software without restriction, including without limitation the
+// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+// sell copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+// IN THE SOFTWARE.
+//-----------------------------------------------------------------------------
+
+#include "./postFx.hlsl"
+
+uniform float  accumTime;
+
+float4 main( PFXVertToPix IN, uniform sampler2D inputTex : register(S0) ) : COLOR
+{
+	float reduction = 128;	
+	float power = 1.0;
+	float speed = 3.0;
+	float frequency=8;
+	
+	float backbuffer_edge_coef=0.98;
+	float2 screen_center = float2(0.5, 0.5);	
+	float2 cPos = (IN.uv0 - screen_center);
+	
+	float len = 1.0 - length(cPos);		
+	float2 uv = clamp((cPos / len * cos(len * frequency - (accumTime * speed)) * (power / reduction)), 0, 1);
+	return tex2D(inputTex, IN.uv0 * backbuffer_edge_coef + uv);
+
+//    float4 color = tex2D(inputTex, IN.uv0 * backbuffer_edge_coef+(sin*right));           
+//	return color;
+
+}