/*********************************************************************NVMH3**** $Revision: #3 $ Copyright NVIDIA Corporation 2007 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/ ******************************************************************************/ #include //// UN-TWEAKABLES - AUTOMATICALLY-TRACKED TRANSFORMS //////////////// float4x4 WorldITXf : WorldInverseTranspose < string UIWidget="None"; >; float4x4 WvpXf : WorldViewProjection < string UIWidget="None"; >; float4x4 WorldXf : World < string UIWidget="None"; >; float4x4 ViewIXf : ViewInverse < string UIWidget="None"; >; float2 ScreenSize : VIEWPORTPIXELSIZE < string UIWidget="None"; >; /************************************************************/ /*** TWEAKABLES *********************************************/ /************************************************************/ float3 Lamp0Pos : Position < string Object = "PointLight0"; string UIName = "Lamp 0 Position"; string Space = "World"; > = {-0.5f,2.0f,1.25f}; float Scale : 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 Shading < string UIWidget = "slider"; float uimin = 0.0; float uimax = 1.0; float uistep = 0.01; string UIName = "Flat<->Shaded"; > = 0.0; float NormalGeom < string UIWidget = "slider"; float uimin = 0.0; float uimax = 1.0; float uistep = 0.01; string UIName = "Normals as Geometry"; > = 0.0; float UVGeom < string UIWidget = "slider"; float uimin = 0.0; float uimax = 1.0; float uistep = 0.01; string UIName = "UVs as Geometry"; > = 0.0; float NGRad < string UIWidget = "slider"; float uimin = 1.0; float uimax = 10.0; float uistep = 0.01; string UIName = "Size of ALternate Geometry"; > = 1.0; // shared shadow mapping supported in Cg version /************* 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; }; /*********** vertex shader for all ******/ dbgVertOut debugVS(appdata IN) { dbgVertOut OUT; float4 Po = float4(IN.Pos,1.0); float4 normPo = float4((NGRad*IN.Normal.xyz),1.0); Po = lerp(Po,normPo,NormalGeom); float4 uvPo = float4((NGRad*IN.UV.xy),0.0,1.0); Po = lerp(Po,uvPo,UVGeom); OUT.HPosition = mul(Po,WvpXf); // OUT.HPosition = mul(WvpXf,Po); OUT.WorldNormal = mul(WorldITXf,IN.Normal).xyz; OUT.WorldTangent = mul(WorldITXf,IN.Tangent).xyz; OUT.WorldBinorm = mul(WorldITXf,IN.Binormal).xyz; float4 Pw = mul(WorldXf,Po); OUT.LightVec = (Lamp0Pos-Pw.xyz); OUT.TexCoord = IN.UV.xy; OUT.WorldPos = Pw.xyz; OUT.WorldEyeVec = normalize(ViewIXf[3].xyz - 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,Shading); return OUT; } /********* pixel shaders ********/ float4 debug_rgba(dbgVertOut IN,float3 Vec) { float4 vc = as_rgba(Vec); float4 InColor = IN.BaseColor; return (InColor * vc); } float4 debug_rgba_n(dbgVertOut IN,float3 Vec) { float4 vc = as_rgba_n(Vec); float4 InColor = IN.BaseColor; 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 : VFACE) : COLOR { float d = 0; if (Vf>0) d = 1; return debug_rgba(IN,d.xxx); } float4 vPosPS(dbgVertOut IN,float2 Vpos : VPOS) : COLOR { float2 c = Vpos.xy / ScreenSize.xy; return debug_rgba(IN,float3(c.xy,0)); } float4 uvDerivsPS(dbgVertOut IN) : COLOR { float2 dd = Scale * (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 { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a uvcPS(); } } technique worldNormalVecs_Raw { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a normalsRawPS(); } } technique worldNormalVecs_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a normalsNPS(); } } technique worldTangentVecs_Raw { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a tangentRawPS(); } } technique worldTangentVecs_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a tangentNPS(); } } technique worldBinormalVecs_Raw { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a binormRawPS(); } } technique worldBinormalVecs_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a binormNPS(); } } technique worldViewVec_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a viewNPS(); } } technique worldLightVec_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a lightNPS(); } } technique halfAngles { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a halfAnglePS(); } } technique facingRatio { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a facingPS(); } } technique uv_Derivatives { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a uvDerivsPS(); } } technique dPdu_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a dPduNPS(); } } technique dPdv_Normalized { pass p0 { VertexShader = compile vs_2_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_2_a dPdvNPS(); } } technique vFace_Register { pass p0 { VertexShader = compile vs_3_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_3_0 vFacePS(); } } technique vPos_Register { pass p0 { VertexShader = compile vs_3_0 debugVS(); ZEnable = true; ZWriteEnable = true; ZFunc = LessEqual; AlphaBlendEnable = false; CullMode = None; PixelShader = compile ps_3_0 vPosPS(); } } // # debug_tech(dPduX,debugVS,dPduNxPS) /***************************** eof ***/