// STATIC: "HALFLAMBERT" "0..1" // DYNAMIC: "LIGHT_COMBO" "0..21" // DYNAMIC: "DOWATERFOG" "0..1" // DYNAMIC: "NUM_BONES" "0..3" #include "common_vs_fxc.h" #ifdef USE_CONDITIONALS const bool g_bZeroBones : register( b0 ); const bool g_bOneBone : register( b1 ); const bool g_bTwoBones : register( b2 ); #else static const int g_NumBones = NUM_BONES; #endif static const int g_LightCombo = LIGHT_COMBO; static const int g_FogType = DOWATERFOG; static const int g_LocalLightType0 = g_LocalLightType0Array[g_LightCombo]; static const int g_LocalLightType1 = g_LocalLightType1Array[g_LightCombo]; const float4 cBaseTexCoordTransform[2] : register( SHADER_SPECIFIC_CONST_0 ); //----------------------------------------------------------------------------- // Input vertex format //----------------------------------------------------------------------------- struct VS_INPUT { // This is all of the stuff that we ever use. float4 vPos : POSITION; float4 vBoneWeights : BLENDWEIGHT; float4 vBoneIndices : BLENDINDICES; float3 vNormal : NORMAL; float4 vColor : COLOR0; float3 vSpecular : COLOR1; // make these float2's and stick the [n n 0 1] in the dot math. float4 vTexCoord0 : TEXCOORD0; float4 vTexCoord1 : TEXCOORD1; float4 vTexCoord2 : TEXCOORD2; float4 vTexCoord3 : TEXCOORD3; float3 vTangentS : TANGENT; float3 vTangentT : BINORMAL; float4 vUserData : TANGENT; // Position and normal/tangent deltas float3 vPosFlex : POSITION1; float3 vNormalFlex : NORMAL1; }; //----------------------------------------------------------------------------- // Output vertex format //----------------------------------------------------------------------------- struct VS_OUTPUT { // stuff that isn't seen by the pixel shader float4 projPos : POSITION; float fog : FOG; // stuff for the pixel shader HALF4 baseTexCoord2_tangentSpaceVertToEyeVectorXY : TEXCOORD0; // bump mapping and a separate envmap mask texture are mutually exclusive. float3 color2 : TEXCOORD1; float3 color1 : TEXCOORD2; float4 worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ : TEXCOORD3; float3x3 tangentSpaceTranspose : TEXCOORD4; float4 worldPos_projPosZ : TEXCOORD7; float4 fogFactorW : COLOR1; }; //----------------------------------------------------------------------------- // Main shader entry point //----------------------------------------------------------------------------- VS_OUTPUT main( const VS_INPUT v ) { VS_OUTPUT o = ( VS_OUTPUT )0; float4 vPosition = v.vPos; float3 vNormal = v.vNormal; float4 vTangent = v.vUserData; // Flexes coming in from a separate stream (contribution masked by cFlexScale.x) vPosition.xyz += v.vPosFlex * cFlexScale.x; vNormal += v.vNormalFlex * cFlexScale.x; vTangent.xyz += v.vNormalFlex * cFlexScale.x; // Tangent uses normal deltas // Perform skinning float3 worldNormal, worldPos, worldTangentS, worldTangentT; SkinPositionNormalAndTangentSpace( g_NumBones, vPosition, vNormal, vTangent, v.vBoneWeights, v.vBoneIndices, worldPos, worldNormal, worldTangentS, worldTangentT ); // Always normalize since flex path is controlled by runtime // constant not a shader combo and will always generate the normalization worldNormal = normalize( worldNormal ); worldTangentS = normalize( worldTangentS ); worldTangentT = normalize( worldTangentT ); // Transform into projection space float4 projPos = mul( float4( worldPos, 1 ), cViewProj ); o.projPos = projPos; o.fogFactorW = o.fog = CalcFog( worldPos, projPos, g_FogType ); // Needed for water fog alpha and diffuse lighting // FIXME: we shouldn't have to compute this all the time. o.worldPos_projPosZ = float4( worldPos, projPos.z ); // Needed for cubemapping + parallax mapping // FIXME: We shouldn't have to compute this all the time. o.worldVertToEyeVectorXYZ_tangentSpaceVertToEyeVectorZ.xyz = VSHADER_VECT_SCALE * (cEyePos - worldPos); // Compute bumped lighting // FIXME: We shouldn't have to compute this for unlit materials o.color1.xyz = GetVertexColorForLight( worldPos, worldNormal, 0, g_LocalLightType0 ); o.color2.xyz = GetVertexColorForLight( worldPos, worldNormal, 1, g_LocalLightType1 ); // Base texture coordinate transform o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.x = dot( v.vTexCoord0, cBaseTexCoordTransform[0] ); o.baseTexCoord2_tangentSpaceVertToEyeVectorXY.y = dot( v.vTexCoord0, cBaseTexCoordTransform[1] ); // Tangent space transform o.tangentSpaceTranspose[0] = float3( worldTangentS.x, worldTangentT.x, worldNormal.x ); o.tangentSpaceTranspose[1] = float3( worldTangentS.y, worldTangentT.y, worldNormal.y ); o.tangentSpaceTranspose[2] = float3( worldTangentS.z, worldTangentT.z, worldNormal.z ); return o; }