/*********************************************************************NVMH3**** Path: NVSDK\Common\media\cgfx File: $Id: //sw/devtools/SDK/9.5/SDK/MEDIA/HLSL/parallaxBumpMap.fx#1 $ Copyright NVIDIA Corporation 2002-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. ******************************************************************************/ /************* "UN-TWEAKABLES," TRACKED BY CPU APPLICATION **************/ float Script : STANDARDSGLOBAL < string UIWidget = "none"; string ScriptClass = "object"; string ScriptOrder = "standard"; string ScriptOutput = "color"; string Script = "Technique=Technique?Main:FlatColor:Seevec;"; > = 0.8; float4x4 WorldITXf : WorldInverseTranspose ; float4x4 WvpXf : WorldViewProjection ; float4x4 WorldXf : World ; float4x4 ViewIXf : ViewInverse ; /////////////////////////////////////////////////////////////// /// TWEAKABLES //////////////////////////////////////////////// /////////////////////////////////////////////////////////////// ////////////////////////////////////////////// point light float3 LightPos : POSITION < string UIName = "Position"; string Object = "PointLight"; string Space = "World"; > = {10.0f, 10.0f, 10.0f}; float3 LightColor : SPECULAR < string UIName = "Lamp"; string UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f}; ////////////////////////////////////////////// surface float3 SurfColor : DIFFUSE < string UIName = "Surface Tint"; string UIWidget = "Color"; > = {1.0f, 1.0f, 1.0f}; float Bumpy < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 2.0; float UIStep = 0.01; string UIName = "Bump Height"; > = 1.0; float Height < string UIWidget = "slider"; float UIMin = -0.1; float UIMax = 0.2; float UIStep = 0.001; string UIName = "Displacement Height"; > = 0.02; float Bias < string UIWidget = "slider"; float UIMin = -0.5; float UIMax = 0.5; float UIStep = 0.001; string UIName = "Displacement Bias"; > = 0.0; float UScale < string UIWidget = "slider"; float UIMin = 1.0; float UIMax = 16.0; float UIStep = 1.0; string UIName = "U Texture Repeat"; > = 1.0; float VScale < string UIWidget = "slider"; float UIMin = 1.0; float UIMax = 10.0; float UIStep = 1.0; string UIName = "V Texture Repeat"; > = 1.0; float Ks < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 1.0; float UIStep = 0.01; string UIName = "Specular"; > = 0.5; float SpecExpon : SpecularPower < string UIWidget = "slider"; float UIMin = 0.0; float UIMax = 100.0; float UIStep = 0.01; string UIName = "Specular Exponent"; > = 40.0; //////////////////////////////////////////////////////// /// TEXTURES /////////////////////////////////////////// //////////////////////////////////////////////////////// texture ColorTexture : DIFFUSE < string ResourceName = "default_color.dds"; string ResourceType = "2D"; >; sampler2D ColorSampler = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = WRAP; AddressV = WRAP; }; texture NormalTexture : NORMAL < string ResourceName = "default_bump_normal.dds"; string ResourceType = "2D"; >; sampler2D NormalSampler = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = WRAP; AddressV = WRAP; }; texture HeightTexture < string ResourceName = "default_bump.dds"; string ResourceType = "2D"; >; sampler2D HeightSampler = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = WRAP; AddressV = WRAP; }; /*********************************************************/ /************* DATA STRUCTS ******************************/ /*********************************************************/ /* data from application vertex buffer */ struct appdata { float3 Position : POSITION; float4 UV : TEXCOORD0; float4 Normal : NORMAL; float4 Tangent : TANGENT0; float4 Binormal : BINORMAL0; }; struct vertexOutput { float4 HPosition : POSITION; float2 UV : TEXCOORD0; float3 LightVec : TEXCOORD1; float3 WorldNormal : TEXCOORD2; float3 WorldView : TEXCOORD3; float3 WorldTangent : TEXCOORD4; float3 WorldBinorm : TEXCOORD5; float3 TanView : TEXCOORD6; }; /*********************************************************/ /*********** vertex shader *******************************/ /*********************************************************/ vertexOutput basicVS(appdata IN) { vertexOutput OUT; float3 Nw = normalize(mul(IN.Normal,WorldITXf).xyz); float3 Tw = normalize(mul(IN.Tangent,WorldITXf).xyz); float3 Bw = normalize(mul(IN.Binormal,WorldITXf).xyz); OUT.WorldNormal = Nw; OUT.WorldTangent = Tw; OUT.WorldBinorm = Bw; float4 Po = float4(IN.Position.xyz,1.0); // object coordinates float3 Pw = mul(Po,WorldXf).xyz; // world coordinates OUT.LightVec = LightPos - Pw; OUT.UV = float2(UScale,VScale) * IN.UV.xy; float3 Vn = normalize(ViewIXf[3].xyz - Pw); // obj coords OUT.WorldView = Vn; float3x3 tanXf = float3x3(Tw,Bw,Nw); OUT.TanView = mul(Vn,tanXf); //OUT.TanView = mul(tanXf,Vn); OUT.HPosition = mul(Po,WvpXf); // screen clipspace coords return OUT; } /*********************************************************/ /*********** pixel shader ********************************/ /*********************************************************/ float4 everythingPS(vertexOutput IN) : COLOR { float3 tv = normalize(IN.TanView); float altitude = tex2D(HeightSampler,IN.UV).x + Bias; float2 nuv = Height*altitude*tv.xy; nuv += IN.UV; float3 Nn = normalize(IN.WorldNormal); float3 Tn = normalize(IN.WorldTangent); float3 Bn = normalize(IN.WorldBinorm); float3 bumps = Bumpy * (tex2D(NormalSampler,nuv).xyz-(0.5).xxx); float3 Nb = Nn + (bumps.x * Tn + bumps.y * Bn); Nb = normalize(Nb); float3 Vn = normalize(IN.WorldView); float3 Ln = normalize(IN.LightVec); float3 Hn = normalize(Vn + Ln); float hdn = dot(Hn,Nb); float ldn = dot(Ln,Nb); float4 litVec = lit(ldn,hdn,SpecExpon); float3 diffContrib = litVec.y * LightColor; float3 specContrib = Ks * litVec.z * diffContrib; float3 colorTex = tex2D(ColorSampler,nuv).xyz; float3 result = colorTex * diffContrib + specContrib; return float4(result.xyz,1.0); } float4 flatColorPS(vertexOutput IN) : COLOR { float3 tv = normalize(IN.TanView); float altitude = tex2D(HeightSampler,IN.UV).x + Bias; float2 nuv = Height*altitude*tv.xy; nuv += IN.UV; float3 Nn = normalize(IN.WorldNormal); float3 Tn = normalize(IN.WorldTangent); float3 Bn = normalize(IN.WorldBinorm); float3 bumps = Bumpy * (tex2D(NormalSampler,nuv).xyz-(0.5).xxx); float3 Nb = Nn + (bumps.x * Tn + bumps.y * Bn); Nb = normalize(Nb); float3 Vn = normalize(IN.WorldView); float3 Ln = normalize(IN.LightVec); float3 Hn = normalize(Vn + Ln); float hdn = dot(Hn,Nb); float ldn = dot(Ln,Nb); float4 litVec = lit(ldn,hdn,SpecExpon); float3 diffContrib = litVec.y * LightColor; float3 specContrib = Ks * litVec.z * diffContrib; float3 result = SurfColor * diffContrib + specContrib; return float4(result.xyz,1.0); } float4 seevecPS(vertexOutput IN) : COLOR { float3 tv = normalize(IN.TanView); float altitude = tex2D(HeightSampler,IN.UV).x + Bias; float2 nuv = Height*altitude*tv.xy; nuv += IN.UV; float3 result = 0.5+(tv*0.5); //float3 result = 0.5+float3(nuv.xy*0.5,0); return float4(result.xy,0.0,1.0); } //////////////////////////////////////////////////////////////////// /// TECHNIQUES ///////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// technique Main < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_2_0 basicVS(); ZEnable = true; ZWriteEnable = true; CullMode = None; PixelShader = compile ps_2_0 everythingPS(); } } technique FlatColor < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_2_0 basicVS(); ZEnable = true; ZWriteEnable = true; CullMode = None; PixelShader = compile ps_2_0 flatColorPS(); } } technique Seevec < string Script = "Pass=p0;"; > { pass p0 < string Script = "Draw=geometry;"; > { VertexShader = compile vs_2_0 basicVS(); ZEnable = true; ZWriteEnable = true; CullMode = None; PixelShader = compile ps_2_0 seevecPS(); } } /***************************** eof ***/