/*********************************************************************NVMH3**** File: $Id: //sw/devtools/SDK/9.5/SDK/MEDIA/HLSL/post_image_diffusion.fx#3 $ Copyright NVIDIA Corporation 2004 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. ******************************************************************************/ // #define TWEAKABLE_TEXEL_OFFSET // #define QUAD_FLOAT #include float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "scene"; string ScriptOrder = "postprocess"; string ScriptOutput = "color"; string Script = "Technique=Main"; > = 0.8; float4 ClearColor < string UIName = "Background"; string UIWidget = "color"; > = {0.2,0.2,0.2,0.0}; float ClearDepth < string UIWidget = "none"; > = 1.0; float passnumber ; // loop counter, hidden /////////////////////////////////////////////////////////// ///////////////////////////// Render-to-Texture Data ////// /////////////////////////////////////////////////////////// // DECLARE_QUAD_TEX(SceneTexture,SceneSampler,"A8R8G8B8") DECLARE_QUAD_DEPTH_BUFFER(DepthBuffer, "D24S8") DECLARE_QUAD_TEX(Map1,Sampler1,"A8R8G8B8") DECLARE_QUAD_TEX(Map2,Sampler2,"A8R8G8B8") ///////////////////////////////////////////////////// //// Tweakables ///////////////////////////////////// ///////////////////////////////////////////////////// float npasses < float UIStep = 1.0; string UIName = "Diff passes"; > = 4.0f; float Blur < string UIWidget = "slider"; float UIMin = 0; float UIMax = 4; float UIStep = 0.01; > = 1.0; ///////////////// struct BlurVertexOutput { QUAD_REAL4 Position : POSITION; QUAD_REAL4 NU : TEXCOORD0; QUAD_REAL2 CC : TEXCOORD1; QUAD_REAL4 PU : TEXCOORD2; QUAD_REAL4 NV : TEXCOORD3; QUAD_REAL4 PV : TEXCOORD4; }; /////////// Vertex shader for "BlurVertexOutput" /////////// BlurVertexOutput BlurVS( QUAD_REAL3 Position : POSITION, QUAD_REAL3 TexCoord : TEXCOORD0 ) { BlurVertexOutput OUT=(BlurVertexOutput)0; QUAD_REAL2 center; OUT.Position = QUAD_REAL4(Position, 1); QUAD_REAL2 texelSize = QUAD_REAL2((1.0/QuadScreenSize.x), (1.0/QuadScreenSize.y)); QUAD_REAL2 blurSize = Blur * texelSize; #ifdef NO_TEXEL_OFFSET center = TexCoord.xy; #else /* NO_TEXEL_OFFSET */ QUAD_REAL2 off = QuadTexOffset * texelSize; QUAD_REAL2(QuadTexOffset/(QuadScreenSize.x),QuadTexOffset/(QuadScreenSize.y)); center = QUAD_REAL2(TexCoord.xy+off); #endif /* NO_TEXEL_OFFSET */ OUT.CC = center; OUT.NU.xy = QUAD_REAL2(center.x-blurSize.x,center.y); OUT.PU.xy = QUAD_REAL2(center.x+blurSize.x,center.y); OUT.NV.xy = QUAD_REAL2(center.x,center.y-blurSize.y); OUT.PV.xy = QUAD_REAL2(center.x,center.y+blurSize.y); OUT.NU.zw = QUAD_REAL2(center.x-blurSize.x,center.y-blurSize.y); OUT.PU.zw = QUAD_REAL2(center.x+blurSize.x,center.y+blurSize.y); OUT.NV.zw = QUAD_REAL2(center.x-blurSize.x,center.y-blurSize.y); OUT.PV.zw = QUAD_REAL2(center.x+blurSize.x,center.y+blurSize.y); return OUT; } /////// Pixel shader to expand values /////// QUAD_REAL4 ExpandPS(BlurVertexOutput IN,uniform sampler2D InputSampler) : COLOR { QUAD_REAL4 scc = tex2D(InputSampler, IN.CC); QUAD_REAL4 result = scc; QUAD_REAL4 snu = tex2D(InputSampler, IN.NU.xy); QUAD_REAL4 spu = tex2D(InputSampler, IN.PU.xy); QUAD_REAL4 snv = tex2D(InputSampler, IN.NV.xy); QUAD_REAL4 spv = tex2D(InputSampler, IN.PV.xy); QUAD_REAL4 sa = tex2D(InputSampler, IN.NU.zw); QUAD_REAL4 sb = tex2D(InputSampler, IN.PU.zw); QUAD_REAL4 sc = tex2D(InputSampler, IN.NV.zw); QUAD_REAL4 sd = tex2D(InputSampler, IN.PV.zw); QUAD_REAL w; w = 0.0; QUAD_REAL3 c; c = QUAD_REAL3(0,0,0); if (scc.a != 0.0) { // don't bother if there's already a value!!!! if (snu.a == 0) { w += 1.0; c += snu.rgb; } if (spu.a == 0) { w += 1.0; c += spu.rgb; } if (snv.a == 0) { w += 1.0; c += snv.rgb; } if (spv.a == 0) { w += 1.0; c += spv.rgb; } if (sa.a == 0) { w += 0.7; c += 0.7*sa.rgb; } if (sb.a == 0) { w += 0.7; c += 0.7*sb.rgb; } if (sc.a == 0) { w += 0.7; c += 0.7*sc.rgb; } if (sd.a == 0) { w += 0.7; c += 0.7*sd.rgb; } if (w > 0.0) { c = c / w; result = QUAD_REAL4(c.rgb,0.0); // result = QUAD_REAL4(1,0,1,0.0); } } return result; } /*******************************************************************/ /************* TECHNIQUES ******************************************/ /*******************************************************************/ technique Main < string Script = "RenderColorTarget0=Map1;" "RenderDepthStencilTarget=DepthBuffer;" "ClearSetColor=ClearColor;" "ClearSetDepth=ClearDepth;" "Clear=Color;" "Clear=Depth;" "ScriptExternal=color;" "LoopByCount=npasses;" //"LoopBegin;" "LoopGetIndex=passnumber;" // Render Object(s) "Pass=p0;" // Blend Results into accum buffer "Pass=p1;" "LoopEnd;" "Pass=show;"; > { pass p0 < string Script = "RenderColorTarget0=Map2;" "RenderDepthStencilTarget=DepthBuffer;" "Draw=Buffer;"; > { cullmode = none; ZEnable = false; ZWriteEnable = false; AlphaBlendEnable = true; SrcBlend = ONE; DestBlend = ZERO; VertexShader = compile vs_3_0 BlurVS(); PixelShader = compile ps_3_0 ExpandPS(Sampler1); } pass p1 < string Script = "RenderColorTarget0=Map1;" "RenderDepthStencilTarget=DepthBuffer;" "Draw=Buffer;"; > { cullmode = none; ZEnable = false; ZWriteEnable = false; AlphaBlendEnable = true; SrcBlend = ONE; DestBlend = ZERO; VertexShader = compile vs_3_0 BlurVS(); PixelShader = compile ps_3_0 ExpandPS(Sampler2); } pass show < string Script = "RenderColorTarget0=;" "RenderDepthStencilTarget=;" "Draw=Buffer;"; > { cullmode = none; ZEnable = false; ZWriteEnable = false; AlphaBlendEnable = true; SrcBlend = ONE; DestBlend = ZERO; VertexShader = compile vs_2_0 ScreenQuadVS(); PixelShader = compile ps_2_a TexQuadPS(Sampler1); } } /***************************** eof ***/