/************************************************** * File: CameraReflect.txt Vertex Shader * * Author: Ben Cohen (07/06/2001) * * Description: Generating UV coords from camera. * *************************************************/ /************************************************* * Constants: * * c0 - constants vector {0,1.0,0.5,256} * c1 - screen offsets {0.53125, 0.53125, 0.03125, 0.0} * c2-c5 - World->screen transformation matrix. * c6 - Light direction * c7 - Directional light colour * c8 - Ambient light Colour * c9-c12 - World view matrix * c13-c15- Inverse world view matrix * c16-c19- Texture transform matrix * * Streams: * v0 - Centre Position vector {x,y,z,w} * v1 - Vertex position {x,y,z,w} * v2 - Colour * v3 - Texture co-ords {u,v} * ************************************************/ xvs.1.0 #include "Shader_def.h" #define R_EYE_VERTEX r8 #define R_EYE_NORMAL r9 #define R_EYE_VECTOR r3 #define R_DOT2 r4 ; Transform position dp4 oPos.x, v0, c[CV_WORLDVIEWPROJ_0] dp4 oPos.y, v0, c[CV_WORLDVIEWPROJ_1] dp4 oPos.z, v0, c[CV_WORLDVIEWPROJ_2] dp4 oPos.w, v0, c[CV_WORLDVIEWPROJ_3] dp4 R_EYE_VERTEX.x, v0, c[CV_WORLDVIEW_0] dp4 R_EYE_VERTEX.y, v0, c[CV_WORLDVIEW_1] dp4 R_EYE_VERTEX.z, v0, c[CV_WORLDVIEW_2] dp4 R_EYE_VERTEX.w, v0, c[CV_WORLDVIEW_3] ; Create R_EYE_VECTOR, the normalized vector from the eye to the vertex dp3 R_EYE_VECTOR.w, R_EYE_VERTEX, R_EYE_VERTEX rsq R_EYE_VECTOR.w, R_EYE_VECTOR.w mul R_EYE_VECTOR, R_EYE_VERTEX, R_EYE_VECTOR.w ; Transform normal to eye-space ; We use the inverse transpose of the worldview ; matrix to do this dp3 R_EYE_NORMAL.x, v1, c[CV_WORLDVIEWIT_0] dp3 R_EYE_NORMAL.y, v1, c[CV_WORLDVIEWIT_1] dp3 R_EYE_NORMAL.z, v1, c[CV_WORLDVIEWIT_2] ; Need to re-normalize normal dp3 R_EYE_NORMAL.w, R_EYE_NORMAL, R_EYE_NORMAL rsq R_EYE_NORMAL.w, R_EYE_NORMAL.w mul R_EYE_NORMAL, R_EYE_NORMAL, R_EYE_NORMAL.w ; Calculate E - 2*(E dot N)*N dp3 R_DOT2, R_EYE_VECTOR, R_EYE_NORMAL add R_DOT2, R_DOT2, R_DOT2 mul R_EYE_NORMAL, R_EYE_NORMAL, R_DOT2 add oT1, R_EYE_VECTOR, -R_EYE_NORMAL mov oT1.w, c[CV_CONSTANT].y ; Copy vertex colour mov oD0, v2 mov oT0, v3