shaders/DynamicLightingShadow/Shaders/LightingShadowMapVS.cg

shaders/DynamicLightingShadow/Shaders/LightingShadowMapVS.cg
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
// ENABLE_SHADOWS should be defined in order to enable shadows
// Transformations.
uniform float4x4 ModelViewProj : state.matrix.mvp;
uniform float4x4 WorldMatrix : state.matrix.modelview;
uniform float4x4 WorldMatrixIT : state.matrix.modelview.invtrans;
// Texture stuff.
uniform float4x4 ColorTextureMatrix;
uniform float4x4 NormalMapMatrix;
uniform int ColorTextureValid;
uniform int NormalMapValid;
struct VertIn
{
float4 Position : POSITION;
float4 Normal : NORMAL;
float3 UV : TEXCOORD0;
float3 Tangent : TEXCOORD1;
float3 Binormal : TEXCOORD2;
};
struct VertOut
{
float4 Position : POSITION;
float3 Normal : TEXCOORD0;
float3 WorldPos : TEXCOORD1;
float3 UVColor : TEXCOORD2;
float3 UVNormal : TEXCOORD3;
float3 Tangent : TEXCOORD4;
float3 Binormal : TEXCOORD5;
#ifdef ENABLE_SHADOWS
float4 LocalPos : TEXCOORD6;
#endif
};
VertOut main( VertIn IN )
{
VertOut OUT;
// Transform vertex position into homogenous clip-space
OUT.Position = mul( ModelViewProj, IN.Position );
// Pass the world position on untransformed
OUT.WorldPos = mul( WorldMatrix, IN.Position ).xyz;
// Pass the normal information onto the pixel shader
OUT.Normal = mul( WorldMatrixIT, IN.Normal ).xyz;
float4 uv = float4( IN.UV.xy, 0, 1 );
// Pass on UV info
if ( ColorTextureValid )
{
OUT.UVColor.xy = mul( ColorTextureMatrix, uv ).xy;
OUT.UVColor.z = 0.0f;
}
if ( NormalMapValid )
{
OUT.UVNormal.xy = mul( NormalMapMatrix, uv ).xy;
OUT.UVNormal.z = 0.0f;
OUT.Tangent = mul( WorldMatrixIT, float4(IN.Tangent,0) );
OUT.Binormal = mul( WorldMatrixIT, float4(IN.Binormal,0) );
}
#ifdef ENABLE_SHADOWS
OUT.LocalPos = IN.Position;
#endif
return OUT;
}