home *** CD-ROM | disk | FTP | other *** search
/ NVIDIA Tech Demo: DAWN / NVIDIA_demo.iso / Dawn.exe / Disk1 / data1.cab / Program_Executable_Files / shaders_ultra / finalTeeth.vp30 < prev    next >
Encoding:
Text File  |  2003-02-11  |  2.4 KB  |  67 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.worldTanMatrixX is set to be the tangentMatrix X-row in world space
  5. // v2f.worldTanMatrixY is set to be the tangentMatrix Y-row in world space
  6. // v2f.worldTanMatrixZ is set to be the tangentMatrix Z-row in world space
  7. // InverseTransposes not used, as we assume no nonuniform scales.
  8.  
  9.  
  10. // vecMul(matrix, float3) multiplies like a vector instead of point (no translate)
  11. float3 vecMul(const float4x4 matrix, const float3 vec){
  12.     return(float3(dot(vec, matrix._11_12_13),
  13.                   dot(vec, matrix._21_22_23),
  14.                   dot(vec, matrix._31_32_33)));
  15. }
  16.  
  17. struct a2vConnector : application2vertex {
  18.     float4 coord;
  19.     float3 normal;
  20.     float4 tangent;
  21.     float4 diffCol;
  22. };
  23.  
  24. struct v2fConnector : vertex2fragment {
  25.   float4 HPOS        :HPOS;
  26.     float4 diffCol    :TEX0;
  27.     float3 worldEyeDir    :TEX1;
  28.     float3 worldTanMatrixX    :TEX5;
  29.     float3 worldTanMatrixY    :TEX6;
  30.     float3 worldTanMatrixZ    :TEX7;
  31. };
  32.  
  33. v2fConnector main(a2vConnector a2v,
  34.                   const uniform float4x4 model,
  35.                   const uniform float4 globalCamPos,
  36.                   const uniform float4x4 viewProj){
  37.     v2fConnector v2f;
  38.  
  39.     v2f.diffCol = a2v.diffCol;
  40.  
  41.     float4 objectCoord = a2v.coord;
  42.     float4 worldCoord = mul(model, objectCoord);
  43.     float4 worldEyePos = globalCamPos;
  44.     float3 worldEyeDir = normalize(worldCoord.xyz - worldEyePos.xyz);
  45.     v2f.worldEyeDir = worldEyeDir;
  46.  
  47.     float3 objectNormal = a2v.normal;
  48.     float3 worldNormal = vecMul(model, objectNormal.xyz);
  49.     float4 objectTangent = a2v.tangent;
  50.     float4 worldTangent;
  51.     worldTangent.xyz = vecMul(model, objectTangent.xyz);
  52.     worldTangent.w = objectTangent.w;
  53.     float3 worldBinormal = worldTangent.w * normalize(cross(worldNormal, worldTangent.xyz));
  54.     float3 worldTanMatrixX = float3(worldTangent.x, worldBinormal.x, worldNormal.x);
  55.     v2f.worldTanMatrixX = worldTanMatrixX;
  56.  
  57.     float3 worldTanMatrixY = float3(worldTangent.y, worldBinormal.y, worldNormal.y);
  58.     v2f.worldTanMatrixY = worldTanMatrixY;
  59.  
  60.     float3 worldTanMatrixZ = float3(worldTangent.z, worldBinormal.z, worldNormal.z);
  61.     v2f.worldTanMatrixZ = worldTanMatrixZ;
  62.  
  63.     float4 hpos = mul(viewProj, worldCoord);
  64.     v2f.HPOS = hpos;
  65.  
  66.     return v2f;
  67. }