VertexShader SeaVS_ATIReflect { 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 #define TEMP1 r6 #define SUN_DIR r7 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 oT0.x, S, c[CV_BASISTRANSFORM_0] dp3 oT0.y, T, c[CV_BASISTRANSFORM_0] dp3 oT0.z, SxT, c[CV_BASISTRANSFORM_0] dp3 oT1.x, S, c[CV_BASISTRANSFORM_1] dp3 oT1.y, T, c[CV_BASISTRANSFORM_1] dp3 oT1.z, SxT, c[CV_BASISTRANSFORM_1] dp3 oT2.x, S, c[CV_BASISTRANSFORM_2] dp3 oT2.y, T, c[CV_BASISTRANSFORM_2] dp3 oT2.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 stage 3 mov oT3.xyz, EYE_VECTOR mov oT4.xy, V_TEXTURE ; calculate vertex 2 sun direction add TEMP1.xyz, -WORLD_VERTEX, c[CV_EYE_WORLD] sub SUN_DIR.xyz, c[CV_SUN_POS], TEMP1 add EYE_VECTOR, -WORLD_VERTEX, c[CV_EYE_WORLD] dp3 SUN_DIR.w, SUN_DIR, SUN_DIR ; and 3 instruction normalization rsq SUN_DIR.w, SUN_DIR.w mul SUN_DIR.xyz, SUN_DIR, SUN_DIR.w mov oT5.xyz, SUN_DIR 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 oFog.x,c[CV_ZERO].x } } PixelShader SeaPS_ATIReflect { asm { #include "reflect.h" ps.1.4 def c1, 0.0f, 0.0f, 0.0f, 0.0f texcrd r0.rgb, t0 ; 1st row of 3x3 basis matrix texcrd r1.rgb, t1 ; 2nd row of 3x3 basis matrix texcrd r2.rgb, t2 ; 3rd row of 3x3 basis matrix texcrd r3.rgb, t3 ; Eye vector texld r4, t4 ; sample normal map ;texcrd r5.xyz, t5 ; sample sun direction dp3 r0.r, r0, r4_bx2 ; 1st row of matrix multiply dp3 r0.g, r1, r4_bx2 ; 2nd row of matrix multiply dp3 r0.b, r2, r4_bx2 ; 3rd row of matrix multiply dp3_x2 r2.rgb, r0, r3 ; 2 * (N dot Eye) mad r1.rgb, r0, r2, -r3 ; 2 * N * (N dot Eye) - Eye ;dp3 r2.rgb,r1,r5 ; r2 = (reflect vector . sun vector) ;mov r2.yzw,c[1] phase ; -------------- two dependent reads texld r0, r1 ; sample diffuse cubic env map //texld r3, r2 ; sample specular lighting texld r5, r1 ;mul r3,r3,c[CP_SUN_COLOR] mul r0, r0, v0 add r0.rgb, r0, v1 ;mad r0, r0, v0, v1 mul r5.rgb, r5, v1.a add r0.rgb, r0, r5 } }