Transform.hlsl 1.6 KB

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