//----------------------------------------------------------------------------- // VertexShader.h //----------------------------------------------------------------------------- #define vPos v0 #define vNormal v1 #define vDiffuse v2 #define vTexCoords v3 #define vTexCoords1 v4 #define vTexCoords2 v5 #define vTexCoords3 v6 #define vBasisU v7 // Texture-space basis #define vBasisV v8 #define vLightDir v9 #define vBlend0 v6 // Blend-shape positions (not allowed with texture-space effects) #define vBlend1 v7 #define vBlend2 v8 #define vBlend3 v9 #define vBlendNorm0 v10 // Blend-shape normals #define vBlendNorm1 v11 #define vBlendNorm2 v12 #define vBlendNorm3 v13 #define vScale v13 #define vIndices v14 #define vWeights v15 #define pNormal r1 // Dedicated registers for passing skinned geometry data between fragments #define pBasisU r2 #define pBasisV r3 #define pPos r11 #define rTemp r4 #define rLightCoeff r5 #define rVertexToLight r6 #define rVertexToEye r7 #define rAtten r8 #define rFinalDiffuse r9 #define rHalfVector r10 #define C_ZERO c0 #define C_ONE c1 #define C_MATERIAL_COLOR c2 #define C_AMBIENT_DIFFUSE c3 #define C_FOG_RANGE c4 #define C_DETAIL_FACTOR c5 #define C_PROJECTION_MATRIX_1 c6 #define C_PROJECTION_MATRIX_2 c7 #define C_PROJECTION_MATRIX_3 c8 #define C_PROJECTION_MATRIX_4 c9 #define C_PROJECTION_MATRIX C_PROJECTION_MATRIX_1 // // Constants c10 through c48 are customizable by individual shaders // #define C_VIEWPORT_SCALE c49 #define C_VIEWPORT_OFFSET c50 #define C_MODEL_EYE_POS c51 #define C_WORLD_HEIGHT_TRANS c52 #define C_LIGHT_POSITION_1 c64 #define C_LIGHT_COLOR_1 c65 #define C_LIGHT_ATTEN_1 c66 #define C_LIGHT_POSITION_2 c67 #define C_LIGHT_COLOR_2 c68 #define C_LIGHT_ATTEN_2 c69 #define C_LIGHT_POSITION_3 c70 #define C_LIGHT_COLOR_3 c71 #define C_LIGHT_ATTEN_3 c72 #define C_LIGHT_POSITION_4 c73 #define C_LIGHT_COLOR_4 c74 #define C_LIGHT_ATTEN_4 c75 #define C_LIGHT_POSITION_5 c76 #define C_LIGHT_COLOR_5 c77 #define C_LIGHT_ATTEN_5 c78 #define C_LIGHT_POSITION_6 c79 #define C_LIGHT_COLOR_6 c80 #define C_LIGHT_ATTEN_6 c81 #define C_LIGHT_POSITION_7 c82 #define C_LIGHT_COLOR_7 c83 #define C_LIGHT_ATTEN_7 c84 #define C_LIGHT_POSITION_8 c85 #define C_LIGHT_COLOR_8 c86 #define C_LIGHT_ATTEN_8 c87 #define C_LIGHT_DIRECTION_1 c88 #define C_LIGHT_CONE_1 c89 #define C_LIGHT_DIRECTION_2 c90 #define C_LIGHT_CONE_2 c91 #define C_LIGHT_DIRECTION_3 c92 #define C_LIGHT_CONE_3 c93 #define C_TEXCOORD_DECOMPRESS c94 //----------------------------------------------------------------------------- // Macros //----------------------------------------------------------------------------- #ifdef _XBOX #define OPOS oPos #define FIXUP_OPOS #define MOVA mov #endif #ifdef _PCBUILD #define OPOS r4 #define FIXUP_OPOS add oPos, r4, c50 #ifdef _VS_2_0 #define MOVA mova #else #define MOVA mov #endif #endif // // NormalizeVector: Normalizes a three-vector // #define NormalizeVector(rVector) \ dp3 rTemp.w, rVector, rVector \ rsq rVector.w, rTemp.w \ mul rVector.xyz, rVector, rVector.w // // CrossProduct: Calculates the cross product of two three-vectors // #define CrossProduct(rSrc1, rSrc2, rDest) \ mul rDest.xyz, rSrc1.zxy, rSrc2.yzx \ mad rDest.xyz, rSrc1.yzx, rSrc2.zxy, -rDest.xyz // // AddDiffusePointLight: Adds the diffuse contribution of an attenuated point light to the destination register // #define AddDiffusePointLight(cPosition, cDiffuse, cAtten, rDest) \ add rVertexToLight, cPosition, -pPos /* Calc light vector */ \ dp3 rTemp.w, rVertexToLight, rVertexToLight \ rsq rVertexToLight.w, rTemp.w \ dst rTemp, rTemp.wwww, rVertexToLight.wwww /* Calc attenuation */ \ dp3 rTemp.w, rTemp, cAtten \ rcp rAtten.w, rTemp.w \ mul rVertexToLight.xyz, rVertexToLight, rVertexToLight.w /* Normalize light vector */ \ dp3 rLightCoeff.x, pNormal, rVertexToLight /* N dot L */ \ max rLightCoeff.x, rLightCoeff.x, C_ZERO.x /* Clamp negative values */ \ mul rLightCoeff.x, rLightCoeff.x, rAtten.w /* Scale by attenuation */ \ mad rDest.xyz, rLightCoeff.x, cDiffuse, rDest // // AddDiffuseSpotLight: Adds the diffuse contribution of an attenuated spot light to the destination register // #define AddDiffuseSpotLight(cPosition, cDiffuse, cAtten, cDirection, cCone, rDest) \ add rVertexToLight, cPosition, -pPos /* Calc light vector */ \ dp3 rTemp.w, rVertexToLight, rVertexToLight \ rsq rVertexToLight.w, rTemp.w \ dst rTemp, rTemp.wwww, rVertexToLight.wwww /* Calc attenuation */ \ dp3 rTemp.w, rTemp, cAtten \ rcp rAtten.w, rTemp.w \ mul rVertexToLight.xyz, rVertexToLight, rVertexToLight.w /* Normalize light vector */ \ dp3 rLightCoeff.x, pNormal, rVertexToLight /* N dot L */ \ max rLightCoeff.x, rLightCoeff.x, C_ZERO.x /* Clamp negative values */ \ dp3 rTemp.w, rVertexToLight, -cDirection /* Scale by spotlight cone */ \ mad rTemp.w, rTemp.w, cCone.x, cCone.y \ mul rLightCoeff.x, rLightCoeff.x, rTemp.w \ max rLightCoeff.x, rLightCoeff.x, C_ZERO.x /* Clamp negative values */ \ mul rLightCoeff.x, rLightCoeff.x, rAtten.w /* Scale by attenuation */ \ mad rDest.xyz, rLightCoeff.x, cDiffuse, rDest // // AddSpecularPointLight: Adds the specular contribution of an attenuated point light to the destination register // #define AddSpecularPointLight(cPosition, cColor, cAtten, rDest) \ add rVertexToLight, cPosition, -pPos /* Calc light vector */ \ dp3 rTemp.w, rVertexToLight, rVertexToLight \ rsq rVertexToLight.w, rTemp.w \ dst rTemp, rTemp.wwww, rVertexToLight.wwww /* Calc attenuation */ \ dp3 rTemp.w, rTemp, cAtten \ rcp rAtten.w, rTemp.w \ mul rVertexToLight.xyz, rVertexToLight, rVertexToLight.w /* Normalize light vector */ \ add rHalfVector, rVertexToEye, rVertexToLight /* Calc half vector */ \ dp3 rTemp.w, rHalfVector, rHalfVector /* Normalize half vector */ \ rsq rHalfVector.w, rTemp.w \ mul rHalfVector.xyz, rHalfVector, rHalfVector.w \ dp3 rLightCoeff.xyz, pNormal, rHalfVector /* N dot H */ \ lit rTemp, rLightCoeff /* Raise to specular power */ \ mul rTemp, rTemp, rAtten.w /* Scale by attenuation */ \ mad rDest.xyz, cColor, rTemp.z, rDest // // CalculateLayeredFog: Sums distance and height fog values and stores result in the destination register // #define CalculateLayeredFog(rSrcPos, rDest) \ add rVertexToEye, C_MODEL_EYE_POS, -rSrcPos /* Calculate distance fog */ \ dp3 rTemp.x, rVertexToEye, rVertexToEye \ rsq rTemp.x, rTemp.x \ rcp rTemp.x, rTemp.x \ mad rTemp.x, rTemp.x, C_FOG_RANGE.x, C_FOG_RANGE.y \ dp4 rTemp.y, rSrcPos, C_WORLD_HEIGHT_TRANS /* Calculate height fog */ \ mad rTemp.y, rTemp.y, C_FOG_RANGE.z, C_FOG_RANGE.w \ min rDest, rTemp.x, rTemp.y /* Store lesser of the two */