PerCameraData.bslinc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. Parameters =
  2. {
  3. float3 gViewDir : auto("ViewDir");
  4. float3 gViewOrigin : auto("ViewOrigin");
  5. mat4x4 gMatViewProj : auto("VP");
  6. mat4x4 gMatView : auto("V");
  7. mat4x4 gMatProj : auto("P");
  8. mat4x4 gMatInvProj : auto("IP");
  9. mat4x4 gMatInvViewProj : auto("IVP");
  10. // Special inverse view-projection matrix that had projection entries that affect z and w eliminated.
  11. // Used to transform a vector(clip_x, clip_y, view_z, view_w), where clip_x/clip_y are in clip space,
  12. // and view_z/view_w in view space, into world space
  13. mat4x4 gMatScreenToWorld : auto("ScreenToWorld");
  14. // Converts device Z to world Z using this formula: worldZ = (1 / (deviceZ + y)) * x
  15. float2 gDeviceZToWorldZ : auto("DeviceToWorldZ");
  16. // x - near plane distance, y - far plane distance
  17. float2 gNearFar : auto("NearFar");
  18. // xy - Viewport offset in pixels
  19. // zw - Viewport width & height in pixels
  20. int4 gViewportRectangle : auto("ViewportRect");
  21. // xy - (Viewport size in pixels / 2) / Target size in pixels
  22. // zw - (Viewport offset in pixels + (Viewport size in pixels / 2) + Optional pixel center offset) / Target size in pixels
  23. float4 gClipToUVScaleOffset : auto("ClipToUVScaleOffset");
  24. float gAmbientFactor;
  25. };
  26. Blocks =
  27. {
  28. Block PerCamera : auto("PerCamera");
  29. };
  30. Technique : base("PerCameraData") =
  31. {
  32. Pass =
  33. {
  34. Common =
  35. {
  36. cbuffer PerCamera
  37. {
  38. float3 gViewDir;
  39. float3 gViewOrigin;
  40. float4x4 gMatViewProj;
  41. float4x4 gMatView;
  42. float4x4 gMatProj;
  43. float4x4 gMatInvProj;
  44. float4x4 gMatInvViewProj;
  45. float4x4 gMatScreenToWorld;
  46. float2 gDeviceZToWorldZ;
  47. float2 gNDCZToWorldZ;
  48. float2 gNearFar;
  49. int4 gViewportRectangle;
  50. float4 gClipToUVScaleOffset;
  51. float gAmbientFactor;
  52. }
  53. /** Converts Z value in range [0,1] into Z value in view space. */
  54. float convertFromDeviceZ(float deviceZ)
  55. {
  56. return (1.0f / (deviceZ + gDeviceZToWorldZ.y)) * gDeviceZToWorldZ.x;
  57. }
  58. /** Converts Z value from view space to NDC space. */
  59. float convertToNDCZ(float viewZ)
  60. {
  61. return -gNDCZToWorldZ.y + (gNDCZToWorldZ.x / viewZ);
  62. }
  63. };
  64. };
  65. };