Transform.hlsl 1.7 KB

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