home *** CD-ROM | disk | FTP | other *** search
/ NVIDIA Tech Demo: DAWN / NVIDIA_demo.iso / Dawn.exe / Disk1 / data1.cab / Program_Executable_Files / shaders / eye_inner.vp30 < prev    next >
Encoding:
Text File  |  2003-02-11  |  1.6 KB  |  50 lines

  1. // v2fConnector.HPOS is set to be the homogenous space coordinate
  2. // v2f.diffCol is set to be the texture coordinate
  3. // v2f.worldEyeDir is set to be the eye direction (from eye) in world space
  4. // v2f.worldNormal is set to be the normal in world space
  5. // InverseTransposes not used, as we assume no nonuniform scales.
  6.  
  7.  
  8. // vecMul(matrix, float3) multiplies like a vector instead of point (no translate)
  9. float3 vecMul(const float4x4 matrix, const float3 vec){
  10.     return(float3(dot(vec, matrix._11_12_13),
  11.                   dot(vec, matrix._21_22_23),
  12.                   dot(vec, matrix._31_32_33)));
  13. }
  14.  
  15. struct a2vConnector : application2vertex {
  16.     float4 coord;
  17.     float3 normal;
  18.     float2 diffCol;
  19. };
  20.  
  21. struct v2fConnector : vertex2fragment {
  22.   float4 HPOS        :HPOS;
  23.     float2 diffCol    :TEX0;
  24.     float3 worldEyeDir    :TEX1;
  25.     float3 worldNormal    :TEX2;
  26. };
  27.  
  28. v2fConnector main(a2vConnector a2v,
  29.                   const uniform float4x4 model,
  30.                   const uniform float4 globalCamPos,
  31.                   const uniform float4x4 viewProj){
  32.     v2fConnector v2f;
  33.  
  34.     v2f.diffCol = a2v.diffCol;
  35.  
  36.     float4 objectCoord = a2v.coord;
  37.     float4 worldCoord = mul(model, objectCoord);
  38.     float4 worldEyePos = globalCamPos;
  39.     float3 worldEyeDir = normalize(worldCoord.xyz - worldEyePos.xyz);
  40.     v2f.worldEyeDir = worldEyeDir;
  41.  
  42.     float3 objectNormal = a2v.normal;
  43.     float3 worldNormal = vecMul(model, objectNormal.xyz);
  44.     v2f.worldNormal = worldNormal;
  45.  
  46.     float4 hpos = mul(viewProj, worldCoord);
  47.     v2f.HPOS = hpos;
  48.  
  49.     return v2f;
  50. }