ScreenPos.hlsl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifdef COMPILEVS
  2. float3x3 GetCameraRot()
  3. {
  4. return float3x3(cViewInv[0][0], cViewInv[0][1], cViewInv[0][2],
  5. cViewInv[1][0], cViewInv[1][1], cViewInv[1][2],
  6. cViewInv[2][0], cViewInv[2][1], cViewInv[2][2]);
  7. }
  8. float4 GetScreenPos(float4 clipPos)
  9. {
  10. return float4(
  11. clipPos.x * cGBufferOffsets.z + cGBufferOffsets.x * clipPos.w,
  12. -clipPos.y * cGBufferOffsets.w + cGBufferOffsets.y * clipPos.w,
  13. 0.0,
  14. clipPos.w);
  15. }
  16. float2 GetScreenPosPreDiv(float4 clipPos)
  17. {
  18. return float2(
  19. clipPos.x / clipPos.w * cGBufferOffsets.z + cGBufferOffsets.x,
  20. -clipPos.y / clipPos.w * cGBufferOffsets.w + cGBufferOffsets.y);
  21. }
  22. float2 GetQuadTexCoord(float4 clipPos)
  23. {
  24. return float2(
  25. clipPos.x / clipPos.w * 0.5 + 0.5,
  26. -clipPos.y / clipPos.w * 0.5 + 0.5);
  27. }
  28. float2 GetQuadTexCoordNoFlip(float3 worldPos)
  29. {
  30. return float2(
  31. worldPos.x * 0.5 + 0.5,
  32. -worldPos.y * 0.5 + 0.5);
  33. }
  34. float3 GetFarRay(float4 clipPos)
  35. {
  36. float3 viewRay = float3(
  37. clipPos.x / clipPos.w * cFrustumSize.x,
  38. clipPos.y / clipPos.w * cFrustumSize.y,
  39. cFrustumSize.z);
  40. return mul(viewRay, GetCameraRot());
  41. }
  42. float3 GetNearRay(float4 clipPos)
  43. {
  44. float3 viewRay = float3(
  45. clipPos.x / clipPos.w * cFrustumSize.x,
  46. clipPos.y / clipPos.w * cFrustumSize.y,
  47. 0.0);
  48. return mul(viewRay, GetCameraRot()) * cDepthMode.z;
  49. }
  50. #endif