vs_2_0 dcl_position v0 dcl_normal v1 #include "..\..\VertexShader.h" ;------------------------------------------------------------------------------ ; Geometry transform ;------------------------------------------------------------------------------ ; Copy model-space geometry to pipeline registers mov pPos, vPos mov pNormal, vNormal ; Transform position to projection space m4x4 OPOS, vPos, C_PROJECTION_MATRIX FIXUP_OPOS #include "..\..\VertexShader.h" ;------------------------------------------------------------------------------ ; Defines ;------------------------------------------------------------------------------ #define C_LIGHT_POSITION c10 #define C_LIGHT_DIR c11 #define C_SHADING_TYPE c12 #define C_TEXGEN_MATRIX_1 c13 #define C_TEXGEN_MATRIX_2 c14 #define C_TEXGEN_MATRIX_3 c15 #define C_ATTENUATION_RANGE c16 ;------------------------------------------------------------------------------ ; Diffuse color ;------------------------------------------------------------------------------ ; Initialize diffuse color mov rFinalDiffuse, C_MATERIAL_COLOR ; Calculate the vertex-to-light vector, and project along the light's direction add rVertexToLight, C_LIGHT_POSITION, -pPos dp3 rAtten.x, C_LIGHT_DIR, rVertexToLight ; Clip vertices behind the light to zero sge rTemp.x, rAtten.x, C_LIGHT_POSITION.w mul rFinalDiffuse.w, rFinalDiffuse.w, rTemp.x ; Apply N-dot-L shading to the diffuse alpha NormalizeVector(rVertexToLight) dp3 rLightCoeff.x, pNormal, C_LIGHT_DIR ; Directional light shading dp3 rLightCoeff.y, pNormal, rVertexToLight ; Point light shading mov rLightCoeff.z, C_ZERO dp3 rLightCoeff, rLightCoeff, C_SHADING_TYPE ; Select type of shading to apply max rLightCoeff.x, rLightCoeff.x, C_ZERO.x mul rFinalDiffuse.w, rFinalDiffuse.w, rLightCoeff.x ; Scale projected vertex-to-light vector and apply to the diffuse alpha mad rAtten.x, rAtten.x, C_ATTENUATION_RANGE.x, C_ATTENUATION_RANGE.y max rAtten.x, rAtten.x, C_ZERO min rAtten.x, rAtten.x, C_ONE mul rFinalDiffuse.w, rFinalDiffuse.w, rAtten.x ; Copy the final color to output mov oD0, rFinalDiffuse #include "..\..\VertexShader.h" ;------------------------------------------------------------------------------ ; Fog calculation ;------------------------------------------------------------------------------ #include "..\..\VertexShader.h" ;------------------------------------------------------------------------------ ; Defines ;------------------------------------------------------------------------------ #define C_LIGHT_POSITION c10 #define C_LIGHT_DIR c11 #define C_SHADING_TYPE c12 #define C_TEXGEN_MATRIX_1 c13 #define C_TEXGEN_MATRIX_2 c14 #define C_TEXGEN_MATRIX_3 c15 #define C_ATTENUATION_RANGE c16 #define C_INTERPOLATION_RANGE c17 ;------------------------------------------------------------------------------ ; Texture coordinates ;------------------------------------------------------------------------------ ; Apply texture matrix to position to generate texture coordinates #ifdef _XBOX dp4 oT0.x, pPos, C_TEXGEN_MATRIX_1 #else dp4 oT0, pPos, C_TEXGEN_MATRIX_1 #endif dp4 oT0.y, pPos, C_TEXGEN_MATRIX_2 ; Third texture coordinate needed for perspective divide dp4 oT0.w, pPos, C_TEXGEN_MATRIX_3