/*********************************************************************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. % This effect file uses colors % to illustrate a number of shading vectors -- that is, values % that are typically important in shading. This effect can often % help find bogus parts of models, or be used to explore the contents % of a model. keywords: material debug virtual_machine bumpmap date: 070403 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 */ #ifndef FXCOMPOSER_VERSION /* for very old versions */ #define FXCOMPOSER_VERSION 180 #endif /* FXCOMPOSER_VERSION */ // #define FLIP_TEXTURE_Y /* Different in OpenGL & DirectX */ /*****************************************************************/ /*** EFFECT-SPECIFIC CODE BEGINS HERE ****************************/ /*****************************************************************/ // // Note use of "ungarian Notation" "g" to indicate globally-scaped values // /******* Lighting Macros *******/ /** To use "Object-Space" lighting definitions, change these two macros: **/ #define LIGHT_COORDS "World" // #define OBJECT_SPACE_LIGHTS /* Define if LIGHT_COORDS is "Object" */ /** Define the macro USE_SHARED_SHADOW to permit the import and use of "shared surface "shadow maps created by COLLADA-FX. **/ // #define USE_SHARED_SHADOW #include "include/debug_tools.cgh" /**** UNTWEAKABLES: Hidden & Automatically-Tracked Parameters **********/ // transform object vertices to world-space: float4x4 gWorldXf : World < string UIWidget="None"; >; // transform object normals, tangents, & binormals to world-space: float4x4 gWorldITXf : WorldInverseTranspose < string UIWidget="None"; >; // transform object vertices to view space and project them in perspective: float4x4 gWvpXf : WorldViewProjection < string UIWidget="None"; >; // provide tranform from "view" or "eye" coords back to world-space: float4x4 gViewIXf : ViewInverse < string UIWidget="None"; >; float2 gScreenSize : VIEWPORTPIXELSIZE < string UIWidget="None"; >; /************************************************************/ /*** TWEAKABLES *********************************************/ /************************************************************/ float3 gLamp0Pos : POSITION < string Object = "PointLight0"; string UIName = "Lamp 0 Position"; string Space = (LIGHT_COORDS); > = {-0.5f,2.0f,1.25f}; float gScale : UNITSSCALE < string units = "inches"; string UIWidget = "slider"; float UIMin = 0.001; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Derivatives Brightness"; > = 64.0; float gShading < string UIWidget = "slider"; float uimin = 0.0; float uimax = 1.0; float uistep = 0.01; string UIName = "Flat<->Shaded"; > = 0.0; float gNormalGeom < string UIWidget = "slider"; float uimin = 0.0; float uimax = 1.0; float uistep = 0.01; string UIName = "Normals as Geometry"; > = 0.0; float gUVGeom < string UIWidget = "slider"; float uimin = 0.0; float uimax = 1.0; float uistep = 0.01; string UIName = "UVs as Geometry"; > = 0.0; float gNGRad < string UIWidget = "slider"; float uimin = 1.0; float uimax = 10.0; float uistep = 0.01; string UIName = "Size of ALternate Geometry"; > = 1.0; #ifdef USE_SHARED_SHADOW #define MAX_SHADOW_BIAS 0.01 #define MIN_SHADOW_BIAS 0.00005 #include "include/shadowMap.cgh" DECLARE_SHADOW_XFORMS("SpotLight0",gLampViewXf,gLampProjXf,gShadowViewProjXf) DECLARE_SHADOW_BIAS DECLARE_SHADOW_MAPS(ColorShadTarget,ColorShadSampler,DepthShadTarget,DepthShadSampler) float ShadDens < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; string UIName = "Shadow Density"; > = 0.7; #endif /* USE_SHARED_SHADOW */ /************* DATA STRUCTS **************/ /* data from application vertex buffer */ struct appdata { float3 Pos : POSITION; float4 UV : TEXCOORD0; float4 Normal : NORMAL; float4 Tangent : TANGENT0; float4 Binormal : BINORMAL0; }; /* data passed from vertex shader to pixel shader */ struct dbgVertOut { float4 HPosition : POSITION; float2 TexCoord : TEXCOORD0; float3 LightVec : TEXCOORD1; float3 WorldNormal : TEXCOORD2; float3 WorldEyeVec : TEXCOORD3; float3 WorldTangent : TEXCOORD4; float3 WorldBinorm : TEXCOORD5; float3 WorldPos : TEXCOORD6; float4 BaseColor : COLOR0; #ifdef USE_SHARED_SHADOW float4 LProj : LPROJ_COORD; #endif /* USE_SHARED_SHADOW */ }; /*********** vertex shader for all ******/ dbgVertOut debugVS(appdata IN, uniform float4x4 WorldITXf, // our four standard "untweakable" xforms uniform float4x4 WorldXf, uniform float4x4 ViewIXf, uniform float4x4 WvpXf, uniform float3 LampPos ) { dbgVertOut OUT; float4 Po = float4(IN.Pos,1.0); float4 normPo = float4((gNGRad*IN.Normal.xyz),1.0); Po = lerp(Po,normPo,gNormalGeom); float4 uvPo = float4((gNGRad*IN.UV.xy),0.0,1.0); Po = lerp(Po,uvPo,gUVGeom); OUT.HPosition = mul(WvpXf,Po); // OUT.HPosition = mul(Po,WvpXf); OUT.WorldNormal = mul(IN.Normal,WorldITXf).xyz; OUT.WorldTangent = mul(IN.Tangent,WorldITXf).xyz; OUT.WorldBinorm = mul(IN.Binormal,WorldITXf).xyz; float4 Pw = mul(Po,WorldXf); OUT.LightVec = (LampPos-Pw.xyz); OUT.TexCoord = IN.UV.xy; OUT.WorldPos = Pw.xyz; OUT.WorldEyeVec = normalize(float3(ViewIXf[0].w,ViewIXf[1].w,ViewIXf[2].w) - Pw.xyz); float ldn = dot(normalize(OUT.LightVec),normalize(OUT.WorldNormal)); ldn = max(0,ldn); OUT.BaseColor = lerp(float4(1,1,1,1),ldn.xxxx,gShading); #ifdef USE_SHARED_SHADOW float4 Pl = mul(ShadowViewProjXf,float4(Pw.xyz,1.0)); // "P" in light coords float4x4 BiasXf = make_bias_mat(ShadBias); OUT.LProj = mul(BiasXf,Pl); // bias to make texcoord #endif /* USE_SHARED_SHADOW */ return OUT; } /********* pixel shaders ********/ float4 debug_rgba(dbgVertOut IN,float3 Vec) { float4 vc = as_rgba(Vec); float4 InColor = IN.BaseColor; #ifdef USE_SHARED_SHADOW float shadowed = tex2Dproj(DepthShadSampler,IN.LProj).x; float faded = 1.0-(ShadDens*(1.0-shadowed)); InColor.rgb *= faded; #endif /* USE_SHARED_SHADOW */ return (InColor * vc); } float4 debug_rgba_n(dbgVertOut IN,float3 Vec) { float4 vc = as_rgba_n(Vec); float4 InColor = IN.BaseColor; #ifdef USE_SHARED_SHADOW float shadowed = tex2Dproj(DepthShadSampler,IN.LProj).x; float faded = 1.0-(ShadDens*(1.0-shadowed)); InColor.rgb *= faded; #endif /* USE_SHARED_SHADOW */ return (InColor * vc); } //////// float4 normalsRawPS(dbgVertOut IN) : COLOR { return debug_rgba(IN,IN.WorldNormal); } float4 normalsNPS(dbgVertOut IN) : COLOR { return debug_rgba_n(IN,IN.WorldNormal); } float4 tangentRawPS(dbgVertOut IN) : COLOR { return debug_rgba(IN,IN.WorldTangent); } float4 tangentNPS(dbgVertOut IN) : COLOR { return debug_rgba_n(IN,IN.WorldTangent); } float4 binormRawPS(dbgVertOut IN) : COLOR { return debug_rgba(IN,IN.WorldBinorm); } float4 binormNPS(dbgVertOut IN) : COLOR { return debug_rgba_n(IN,IN.WorldBinorm); } float4 viewNPS(dbgVertOut IN) : COLOR { return debug_rgba(IN,IN.WorldEyeVec); } float4 lightNPS(dbgVertOut IN) : COLOR { return debug_rgba_n(IN,IN.LightVec); } float4 uvcPS(dbgVertOut IN) : COLOR { return debug_rgba(IN,float3(IN.TexCoord.xy,0)); } float4 vFacePS(dbgVertOut IN,float Vf : FACE) : COLOR { float d = 0; if (Vf>0) d = 1; return debug_rgba(IN,d.xxx); } float4 uvDerivsPS(dbgVertOut IN) : COLOR { float2 dd = gScale * (abs(ddx(IN.TexCoord)) + abs(ddy(IN.TexCoord))); return debug_rgba(IN,float3(dd.xy,0)); } float4 dPduNPS(dbgVertOut IN) : COLOR { float3 dPx = ddx(IN.TexCoord.x) * ddx(IN.WorldPos); float3 dPy = ddy(IN.TexCoord.x) * ddy(IN.WorldPos); return debug_rgba(IN,(dPx+dPy)); } float4 dPdvNPS(dbgVertOut IN) : COLOR { float3 dPx = ddx(IN.TexCoord.y) * ddx(IN.WorldPos); float3 dPy = ddy(IN.TexCoord.y) * ddy(IN.WorldPos); return debug_rgba_n(IN,(dPx+dPy)); } float4 halfAnglePS(dbgVertOut IN) :COLOR { float3 Ln = normalize(IN.LightVec); float3 Vn = normalize(IN.WorldEyeVec); // float3 Hn = normalize(Vn + Ln); return debug_rgba_n(IN,(Vn+Ln)); } float4 facingPS(dbgVertOut IN) :COLOR { float3 Nn = normalize(IN.WorldNormal); float3 Vn = normalize(IN.WorldEyeVec); return debug_rgba(IN,float3(abs(dot(Nn,Vn)).xxx)); } /* float4 dPduNxPS(dbgVertOut IN) : COLOR { float3 dPx = ddx(IN.TexCoord.x) * ddx(IN.WorldPos); float3 dPy = ddy(IN.TexCoord.x) * ddy(IN.WorldPos); float3 dPdu = normalize(dPx+dPy); float3 Nn = normalize(IN.WorldNormal); float3 nTan = cross(dPdu,Nn); return debug_rgba(IN,nTan); } */ /////////////////////////////////////// /// TECHNIQUES //////////////////////// /////////////////////////////////////// technique uv_Coordinates < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 uvcPS(); } } technique worldNormalVecs_Raw < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 normalsRawPS(); } } technique worldNormalVecs_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 normalsNPS(); } } technique worldTangentVecs_Raw < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 tangentRawPS(); } } technique worldTangentVecs_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 tangentNPS(); } } technique worldBinormalVecs_Raw < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 binormRawPS(); } } technique worldBinormalVecs_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 binormNPS(); } } technique worldViewVec_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 viewNPS(); } } technique worldLightVec_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 lightNPS(); } } technique halfAngles < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 halfAnglePS(); } } technique facingRatio < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 facingPS(); } } technique uv_Derivatives < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 uvDerivsPS(); } } technique dPdu_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 dPduNPS(); } } technique dPdv_Normalized < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 dPdvNPS(); } } technique vFace_Register < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexProgram = compile vp40 debugVS(gWorldITXf,gWorldXf, gViewIXf,gWvpXf,gLamp0Pos); DepthTestEnable = true; DepthMask = true; CullFaceEnable = false; BlendEnable = false; DepthFunc = LEqual; FragmentProgram = compile fp40 vFacePS(); } } // # debug_tech(dPduX,debugVS,dPduNxPS) /***************************** eof ***/