/*********************************************************************NVMH3**** ******************************************************************************* $Revision: #4 $ Copyright NVIDIA Corporation 2008 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA OR ITS SUPPLIERS BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT, OR CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. % Create a scratched-movie-film look using animated noise keywords: image_processing animation virtual_machine date: 070401 keywords: DirectX10 // Note that this version has twin versions of all techniques, // so that this single effect file can be used in *either* // DirectX9 or DirectX10 To learn more about shading, shaders, and to bounce ideas off other shader authors and users, visit the NVIDIA Shader Library Forums at: http://developer.nvidia.com/forums/ ******************************************************************************* ******************************************************************************/ /*****************************************************************/ /*** HOST APPLICATION IDENTIFIERS ********************************/ /*** Potentially predefined by varying host environments *********/ /*****************************************************************/ // #define _XSI_ /* predefined when running in XSI */ // #define TORQUE /* predefined in TGEA 1.7 and up */ // #define _3DSMAX_ /* predefined in 3DS Max */ #ifdef _3DSMAX_ int ParamID = 0x0003; /* Used by Max to select the correct parser */ #endif /* _3DSMAX_ */ #ifdef _XSI_ #define Main Static /* Technique name used for export to XNA */ #endif /* _XSI_ */ #ifndef FXCOMPOSER_VERSION /* for very old versions */ #define FXCOMPOSER_VERSION 180 #endif /* FXCOMPOSER_VERSION */ #ifndef DIRECT3D_VERSION #define DIRECT3D_VERSION 0x900 #endif /* DIRECT3D_VERSION */ #define FLIP_TEXTURE_Y /* Different in OpenGL & DirectX */ /*****************************************************************/ /*** EFFECT-SPECIFIC CODE BEGINS HERE ****************************/ /*****************************************************************/ // // Un-Comment the PROCEDURAL_TEXTURE macro to enable texture generation in // DirectX9 ONLY // DirectX10 may not issue errors, but will generate no texture either // // #define PROCEDURAL_TEXTURE // // shared-surface access supported in Cg version #include #define NOISE2D_SCALE 1 //#define NOISE2D_FORMAT "A16B16G16R16F" #include float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "scene"; string ScriptOrder = "postprocess"; string ScriptOutput = "color"; string Script = "Technique=Technique?Main:Main10;"; > = 0.8; // color and depth used for full-screen clears float4 gClearColor < string UIWidget = "Color"; string UIName = "Background"; > = {0.1, 0.1, 0.1, 0.0}; float gClearDepth = 1.0; float gTimer : TIME < string UIWidget = "None"; >; /////////////////////////////////////////////////////////// /////////////////////////////////////// Tweakables //////// /////////////////////////////////////////////////////////// float gSpeed1 < string UIName = "Speed (Slower=Longer Scratches)"; string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 0.2f; float UIStep = 0.0001f; > = 0.03f; float gSpeed2 < string UIName = "Side Scroll Speed"; string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 0.01f; float UIStep = 0.0001f; > = 0.01f; float gScratchIntensity < string UIName = "Scratch Threshhold"; string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 1.0f; float UIStep = 0.0001f; > = 0.65f; float gIS < string UIName = "Scratch Width"; string UIWidget = "slider"; float UIMin = 0.0f; float UIMax = 0.1f; float UIStep = 0.0001f; > = 0.01f; /////////////////////////////////////////////////////////// /////////////////////////////////////// Textures ////////// /////////////////////////////////////////////////////////// DECLARE_QUAD_TEX(gSceneTexture,gSceneSampler,"A8R8G8B8") DECLARE_QUAD_DEPTH_BUFFER(DepthBuffer,"D24S8") ////////////////////////////////////////////////////// /////////////////////////////////// pixel shader ///// ////////////////////////////////////////////////////// float4 scratchPS(QuadVertexOutput IN, uniform sampler2D SceneSampler, uniform sampler2D Noise2DSamp, uniform float Timer, uniform float Speed1, uniform float Speed2, uniform float ScratchIntensity, uniform float IS ) : COLOR { float ScanLine = (Timer*Speed1); float Side = (Timer*Speed2); float4 img = tex2D(SceneSampler,IN.UV); float2 s = float2(IN.UV.x+Side,ScanLine); float scratch = tex2D(Noise2DSamp,s).x; scratch = 2.0f*(scratch - ScratchIntensity)/IS; scratch = 1.0-abs(1.0f-scratch); //scratch = scratch * 100.0f; scratch = max(0,scratch); //scratch = min(scratch,1.0f); return img + float4(scratch.xxx,0); } /////////////////////////////////////// /// TECHNIQUES //////////////////////// /////////////////////////////////////// // // DirectX10 Version // #if DIRECT3D_VERSION >= 0xa00 // // Standard DirectX10 Material State Blocks // RasterizerState DisableCulling { CullMode = NONE; }; DepthStencilState DepthEnabling { DepthEnable = TRUE; }; DepthStencilState DepthDisabling { DepthEnable = FALSE; DepthWriteMask = ZERO; }; BlendState DisableBlend { BlendEnable[0] = FALSE; }; technique10 Main10 < string Script = #ifndef SHARED_BG_IMAGE "RenderColorTarget0=gSceneTexture;" "RenderDepthStencilTarget=DepthBuffer;" "ClearSetColor=gClearColor;" "ClearSetDepth=gClearDepth;" "Clear=Color;" "Clear=Depth;" "ScriptExternal=Color;" // calls all "previous" techniques & materials "Pass=PostP0;"; #else /* defined(SHARED_BG_IMAGE) - no nead to create one, COLLADA has done it for us */ "ClearSetColor=gClearColor;" "ClearSetDepth=gClearDepth;" "Clear=Color;" "Clear=Depth;" "Pass=PostP0;"; #endif /* SHARED_BG_IMAGE */ > { pass PostP0 < string Script = "RenderColorTarget0=;" "RenderDepthStencilTarget=;" "Draw=Buffer;"; > { SetVertexShader( CompileShader( vs_4_0, ScreenQuadVS2(QuadTexelOffsets) ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, scratchPS(gSceneSampler, gNoise2DSamp, gTimer,gSpeed1,gSpeed2, gScratchIntensity,gIS) ) ); SetRasterizerState(DisableCulling); SetDepthStencilState(DepthDisabling, 0); SetBlendState(DisableBlend, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF); } } #endif /* DIRECT3D_VERSION >= 0xa00 */ // // DirectX9 Version // technique Main < string Script = #ifndef SHARED_BG_IMAGE "RenderColorTarget0=gSceneTexture;" "RenderDepthStencilTarget=DepthBuffer;" "ClearSetColor=gClearColor;" "ClearSetDepth=gClearDepth;" "Clear=Color;" "Clear=Depth;" "ScriptExternal=Color;" // calls all "previous" techniques & materials "Pass=PostP0;"; #else /* defined(SHARED_BG_IMAGE) - no nead to create one, COLLADA has done it for us */ "ClearSetColor=gClearColor;" "ClearSetDepth=gClearDepth;" "Clear=Color;" "Clear=Depth;" "Pass=PostP0;"; #endif /* SHARED_BG_IMAGE */ > { pass PostP0 < string Script = "RenderColorTarget0=;" "RenderDepthStencilTarget=;" "Draw=Buffer;"; > { VertexShader = compile vs_3_0 ScreenQuadVS2(QuadTexelOffsets); ZEnable = false; ZWriteEnable = false; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_3_0 scratchPS(gSceneSampler, gNoise2DSamp, gTimer,gSpeed1,gSpeed2, gScratchIntensity,gIS); } } ////////////////////////////////////////////// /////////////////////////////////////// eof // //////////////////////////////////////////////