Transform.hlsl 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #ifdef COMPILEVS
  2. #ifdef D3D11
  3. #define OUTPOSITION SV_POSITION
  4. #else
  5. #define OUTPOSITION POSITION
  6. #endif
  7. #ifdef SKINNED
  8. float4x3 GetSkinMatrix(float4 blendWeights, int4 blendIndices)
  9. {
  10. return cSkinMatrices[blendIndices.x] * blendWeights.x +
  11. cSkinMatrices[blendIndices.y] * blendWeights.y +
  12. cSkinMatrices[blendIndices.z] * blendWeights.z +
  13. cSkinMatrices[blendIndices.w] * blendWeights.w;
  14. }
  15. #endif
  16. float2 GetTexCoord(float2 iTexCoord)
  17. {
  18. return float2(dot(iTexCoord, cUOffset.xy) + cUOffset.w, dot(iTexCoord, cVOffset.xy) + cVOffset.w);
  19. };
  20. float4 GetClipPos(float3 worldPos)
  21. {
  22. return mul(float4(worldPos, 1.0), cViewProj);
  23. }
  24. float GetZonePos(float3 worldPos)
  25. {
  26. return saturate(mul(float4(worldPos, 1.0), cZone).z);
  27. }
  28. float GetDepth(float4 clipPos)
  29. {
  30. return dot(clipPos.zw, cDepthMode.zw);
  31. }
  32. #ifdef BILLBOARD
  33. float3 GetBillboardPos(float4 iPos, float2 iSize, float4x3 modelMatrix)
  34. {
  35. return mul(iPos, modelMatrix) + mul(float3(iSize.x, iSize.y, 0.0), cBillboardRot);
  36. }
  37. float3 GetBillboardNormal()
  38. {
  39. return float3(-cBillboardRot[2][0], -cBillboardRot[2][1], -cBillboardRot[2][2]);
  40. }
  41. #endif
  42. #if defined(SKINNED)
  43. #define iModelMatrix GetSkinMatrix(iBlendWeights, iBlendIndices);
  44. #elif defined(INSTANCED)
  45. #define iModelMatrix iModelInstance
  46. #else
  47. #define iModelMatrix cModel
  48. #endif
  49. #ifdef BILLBOARD
  50. #define GetWorldPos(modelMatrix) GetBillboardPos(iPos, iSize, modelMatrix)
  51. #else
  52. #define GetWorldPos(modelMatrix) mul(iPos, modelMatrix)
  53. #endif
  54. #ifdef BILLBOARD
  55. #define GetWorldNormal(modelMatrix) GetBillboardNormal()
  56. #else
  57. #define GetWorldNormal(modelMatrix) normalize(mul(iNormal, (float3x3)modelMatrix))
  58. #endif
  59. #define GetWorldTangent(modelMatrix) normalize(mul(iTangent.xyz, (float3x3)modelMatrix))
  60. #endif
  61. #ifdef COMPILEPS
  62. #ifdef D3D11
  63. #define OUTCOLOR0 SV_TARGET
  64. #define OUTCOLOR1 SV_TARGET1
  65. #define OUTCOLOR2 SV_TARGET2
  66. #define OUTCOLOR3 SV_TARGET3
  67. #else
  68. #define OUTCOLOR0 COLOR0
  69. #define OUTCOLOR1 COLOR1
  70. #define OUTCOLOR2 COLOR2
  71. #define OUTCOLOR3 COLOR3
  72. #endif
  73. #endif