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

  1. // v2fConnector.HPOS is set to be the homogenous space coordinate
  2. // v2f.skinColor_frontSpec is set to be the texture coordinate
  3. // v2f.worldNormal is set to be the normal in world space
  4. // v2f.worldReflect is set to be the reflection in world space
  5. // v2f.worldEyeDir is set to be the eye direction (from eye) in world space
  6. // v2f.skinSilouetteVec is set to be the skin silouette vector
  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.     float4 normal;
  20.     float3 boneWeight0_2;
  21.     float3 boneIndex0_2;
  22.     float2 skinColor_frontSpec;
  23. };
  24.  
  25. struct v2fConnector : vertex2fragment {
  26.   float4 HPOS        :HPOS;
  27.     float2 skinColor_frontSpec    :TEX0;
  28.     float3 worldNormal    :TEX1;
  29.     float3 worldReflect    :TEX2;
  30.     float3 worldEyeDir    :TEX3;
  31.     float4 skinSilouetteVec    :TEX4;
  32. };
  33.  
  34. v2fConnector main(a2vConnector a2v,
  35.                   const uniform float4x4 model[7],
  36.                   const uniform float4 globalCamPos,
  37.                   const uniform float4x4 viewProj){
  38.     v2fConnector v2f;
  39.  
  40.     v2f.skinColor_frontSpec = a2v.skinColor_frontSpec;
  41.  
  42.     float4 objectNormal = a2v.normal;
  43.     float4x4 worldSkinMatrix;
  44.     worldSkinMatrix[0] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][0];
  45.     worldSkinMatrix[1] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][1];
  46.     worldSkinMatrix[2] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][2];
  47.     worldSkinMatrix[3] = a2v.boneWeight0_2.x * model[a2v.boneIndex0_2.x][3];
  48.     worldSkinMatrix[0] = worldSkinMatrix[0] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][0];
  49.     worldSkinMatrix[1] = worldSkinMatrix[1] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][1];
  50.     worldSkinMatrix[2] = worldSkinMatrix[2] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][2];
  51.     worldSkinMatrix[3] = worldSkinMatrix[3] + a2v.boneWeight0_2.y * model[a2v.boneIndex0_2.y][3];
  52.     worldSkinMatrix[0] = worldSkinMatrix[0] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][0];
  53.     worldSkinMatrix[1] = worldSkinMatrix[1] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][1];
  54.     worldSkinMatrix[2] = worldSkinMatrix[2] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][2];
  55.     worldSkinMatrix[3] = worldSkinMatrix[3] + a2v.boneWeight0_2.z * model[a2v.boneIndex0_2.z][3];
  56.     float3 worldNormal = vecMul(worldSkinMatrix, objectNormal);
  57.     worldNormal = normalize(worldNormal);
  58.     v2f.worldNormal = worldNormal;
  59.  
  60.     float4 objectCoord = a2v.coord;
  61.     float4 worldCoord = mul(worldSkinMatrix, objectCoord);
  62.     float4 worldEyePos = globalCamPos;
  63.     float3 worldEyeDir = normalize(worldCoord.xyz - worldEyePos.xyz);
  64.     float3 worldReflection = reflect(worldEyeDir, worldNormal);
  65.     v2f.worldReflect = worldReflection;
  66.  
  67.     v2f.worldEyeDir = worldEyeDir;
  68.  
  69.     float4 skinSilouetteVec;
  70.     skinSilouetteVec.x = 1.0-dot(worldNormal, -worldEyeDir);
  71.     skinSilouetteVec.y = skinSilouetteVec.x*skinSilouetteVec.x;
  72.     v2f.skinSilouetteVec = skinSilouetteVec;
  73.  
  74.     float4 hpos = mul(viewProj, worldCoord);
  75.     v2f.HPOS = hpos;
  76.  
  77.     return v2f;
  78. }