VertexShader SeaVS_GF3Reflect { decl { stream[0]; float v0[3]; // Position float v1[3]; // S vector color v2; // diffuse color v3; // specular float v4[2]; // Tex coord 0 float v5[3]; // T vector } asm { #include "reflect.h" #define V_POSITION v0 #define V_S v1 #define V_DIFFUSE v2 #define V_SPECULAR v3 #define V_TEXTURE v4 #define V_T v5 #define WORLD_VERTEX r0 #define SxT r1 #define S r2 #define T r3 #define EYE_VECTOR r4 #define TEMP r5 vs.1.0 ; Transform position to clip space and output it dp4 oPos.x, V_POSITION, c[CV_WORLDVIEWPROJ_0] dp4 oPos.y, V_POSITION, c[CV_WORLDVIEWPROJ_1] dp4 TEMP.z, V_POSITION, c[CV_WORLDVIEWPROJ_2] dp4 oPos.w, V_POSITION, c[CV_WORLDVIEWPROJ_3] ;add oPos.z, TEMP.z, c[CV_SMALL_DELTA].z mov oPos.z, TEMP.z dp4 TEMP.z, V_POSITION, c[CV_WORLDVIEW_2] ; Normalize S and T dp3 S.w, V_S, V_S rsq S.w, S.w mul S, V_S, S.w dp3 T.w, V_T, V_T rsq T.w, T.w mul T, V_T, T.w ; here we compute SxT (if V_SxT is available, then this is unnecessary, of course) mul SxT, S.zxyw, T.yzxw ; 2 instruction cross product mad SxT, S.yzxw, T.zxyw, -SxT dp3 SxT.w, SxT, SxT ; and 3 instruction normalization rsq SxT.w, SxT.w mul SxT.xyz, SxT, SxT.w ; Scale the bumps mul S, S, c[CV_BUMPSCALE].w mul T, T, c[CV_BUMPSCALE].w ; Rotate the basis vectors by the world transform to put them into world space dp3 oT1.x, S, c[CV_BASISTRANSFORM_0] dp3 oT1.y, T, c[CV_BASISTRANSFORM_0] dp3 oT1.z, SxT, c[CV_BASISTRANSFORM_0] dp3 oT2.x, S, c[CV_BASISTRANSFORM_1] dp3 oT2.y, T, c[CV_BASISTRANSFORM_1] dp3 oT2.z, SxT, c[CV_BASISTRANSFORM_1] dp3 oT3.x, S, c[CV_BASISTRANSFORM_2] dp3 oT3.y, T, c[CV_BASISTRANSFORM_2] dp3 oT3.z, SxT, c[CV_BASISTRANSFORM_2] ; Calculate the eye vector in world space dp3 WORLD_VERTEX.x, V_POSITION, c[CV_WORLD_0] dp3 WORLD_VERTEX.y, V_POSITION, c[CV_WORLD_1] dp3 WORLD_VERTEX.zw, V_POSITION, c[CV_WORLD_2] add EYE_VECTOR, -WORLD_VERTEX, c[CV_EYE_WORLD] dp3 EYE_VECTOR.w, EYE_VECTOR, EYE_VECTOR ; and 3 instruction normalization rsq EYE_VECTOR.w, EYE_VECTOR.w mul EYE_VECTOR.xyz, EYE_VECTOR, EYE_VECTOR.w ; store the eye vector in the texture coordinate w for ; the pixel shader mov oT1.w, EYE_VECTOR.x mov oT2.w, EYE_VECTOR.y mov oT3.w, EYE_VECTOR.z mov oD0, V_DIFFUSE mov oD1, V_SPECULAR ; fog attenuation sub TEMP.z,TEMP.z,c[CV_FOG].y ; dist -= start_fog_distance max TEMP.z,c[CV_ZERO].x,TEMP.z ; clamp to zero mul TEMP.z,TEMP.z,c[CV_FOG].x ; dist * density expp TEMP.z,TEMP.z ; res = e^(dist * density) rcp TEMP.z,TEMP.z ; res = 1 / e^(dist * density) mad oFog.x,TEMP.z,-c[CV_FOG].z,c[CV_FOG].z ; fog = 255.0f * (1.0f/e^(bla) - 1.0f) mov oT0.xy, V_TEXTURE } } PixelShader SeaPS_GF3Reflect { asm { ; Pixel shader - Bumped surface reflections. ; Transforms the bumpmap into the local coordinate system ; by the basis vectors supplied from the vertex shader. ; Then uses the normal and eye vector to generate a ; reflection vector which looks into a cubemap. #include "reflect.h" ; Declare pixel shader version 1.0 ps.1.1 ; Define t0 as a standard 3-vector from bumpmap tex t0 ; Perform matrix multiply to get a local normal bump. Then ; reflect the eye vector through the normal and sample from ; a cubic environment map. texm3x3pad t1, t0_bx2 texm3x3pad t2, t0_bx2 texm3x3vspec t3, t0_bx2 ; result goes in output color mov r0, t3 mul r0, r0, v0 add r0.rgb, r0, v1 } } PixelShader SeaPS_GF3ReflectSunRoad { asm { ; Pixel shader - Bumped surface reflections. ; Transforms the bumpmap into the local coordinate system ; by the basis vectors supplied from the vertex shader. ; Then uses the normal and eye vector to generate a ; reflection vector which looks into a cubemap. #include "reflect.h" ; Declare pixel shader version 1.0 ps.1.1 ; Define t0 as a standard 3-vector from bumpmap tex t0 ; Perform matrix multiply to get a local normal bump. Then ; reflect the eye vector through the normal and sample from ; a cubic environment map. texm3x3pad t1, t0_bx2 texm3x3pad t2, t0_bx2 texm3x3vspec t3, t0_bx2 ; result goes in output color mov r0, t3 mul r0.rgb, r0, v1.a } }