Transform.hlsl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifdef COMPILEVS
  2. #ifdef SKINNED
  3. float4x3 GetSkinMatrix(float4 blendWeights, int4 blendIndices)
  4. {
  5. return cSkinMatrices[blendIndices.x] * blendWeights.x +
  6. cSkinMatrices[blendIndices.y] * blendWeights.y +
  7. cSkinMatrices[blendIndices.z] * blendWeights.z +
  8. cSkinMatrices[blendIndices.w] * blendWeights.w;
  9. }
  10. #endif
  11. float2 GetTexCoord(float2 iTexCoord)
  12. {
  13. return float2(dot(iTexCoord, cUOffset.xy) + cUOffset.w, dot(iTexCoord, cVOffset.xy) + cVOffset.w);
  14. };
  15. float4 GetClipPos(float3 worldPos)
  16. {
  17. return mul(float4(worldPos, 1.0), cViewProj);
  18. }
  19. float GetZonePos(float3 worldPos)
  20. {
  21. return saturate(mul(float4(worldPos, 1.0), cZone).z);
  22. }
  23. float GetDepth(float4 clipPos)
  24. {
  25. return dot(clipPos.zw, cDepthMode.zw);
  26. }
  27. float3 GetBillboardPos(float4 iPos, float2 iSize, float4x3 modelMatrix)
  28. {
  29. return mul(iPos, modelMatrix) + mul(float3(iSize.x, iSize.y, 0.0), cBillboardRot);
  30. }
  31. float3 GetBillboardNormal()
  32. {
  33. return float3(-cBillboardRot[2][0], -cBillboardRot[2][1], -cBillboardRot[2][2]);
  34. }
  35. #if defined(SKINNED)
  36. #define iModelMatrix GetSkinMatrix(iBlendWeights, iBlendIndices);
  37. #elif defined(INSTANCED)
  38. #define iModelMatrix iModelInstance
  39. #else
  40. #define iModelMatrix cModel
  41. #endif
  42. #ifdef BILLBOARD
  43. #define GetWorldPos(modelMatrix) GetBillboardPos(iPos, iSize, modelMatrix)
  44. #else
  45. #define GetWorldPos(modelMatrix) mul(iPos, modelMatrix)
  46. #endif
  47. #ifdef BILLBOARD
  48. #define GetWorldNormal(modelMatrix) GetBillboardNormal()
  49. #else
  50. #define GetWorldNormal(modelMatrix) normalize(mul(iNormal, (float3x3)modelMatrix))
  51. #endif
  52. #define GetWorldTangent(modelMatrix) normalize(mul(iTangent.xyz, (float3x3)modelMatrix))
  53. #endif