PerCameraData.bslinc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. mixin PerCameraData
  2. {
  3. code
  4. {
  5. cbuffer PerCamera
  6. {
  7. float3 gViewDir;
  8. float3 gViewOrigin;
  9. float4x4 gMatViewProj;
  10. float4x4 gMatView;
  11. float4x4 gMatProj;
  12. float4x4 gMatInvProj;
  13. float4x4 gMatInvViewProj;
  14. // Special inverse view-projection matrix that had projection entries that affect z and w eliminated.
  15. // Used to transform a vector(clip_x, clip_y, view_z, view_w), where clip_x/clip_y are in clip space,
  16. // and view_z/view_w in view space, into world space
  17. float4x4 gMatScreenToWorld;
  18. // Converts device Z to world Z using this formula: worldZ = (1 / (deviceZ + y)) * x
  19. float2 gDeviceZToWorldZ;
  20. float2 gNDCZToWorldZ;
  21. // x - near plane distance, y - far plane distance
  22. float2 gNearFar;
  23. // xy - Viewport offset in pixels
  24. // zw - Viewport width & height in pixels
  25. int4 gViewportRectangle;
  26. // xy - (Viewport size in pixels / 2) / Target size in pixels
  27. // zw - (Viewport offset in pixels + (Viewport size in pixels / 2) + Optional pixel center offset) / Target size in pixels
  28. float4 gClipToUVScaleOffset;
  29. float gAmbientFactor;
  30. }
  31. /** Converts Z value in range [0,1] into Z value in view space. */
  32. float convertFromDeviceZ(float deviceZ)
  33. {
  34. return (1.0f / (deviceZ + gDeviceZToWorldZ.y)) * gDeviceZToWorldZ.x;
  35. }
  36. /** Converts Z value from view space to NDC space. */
  37. float convertToNDCZ(float viewZ)
  38. {
  39. return -gNDCZToWorldZ.y + (gNDCZToWorldZ.x / viewZ);
  40. }
  41. };
  42. };