PerCameraData.bslinc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. };
  25. Blocks =
  26. {
  27. Block PerCamera : auto("PerCamera");
  28. };
  29. Technique : base("PerCameraData") =
  30. {
  31. Language = "HLSL11";
  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. }
  52. /** Converts Z value in range [0,1] into Z value in view space. */
  53. float convertFromDeviceZ(float deviceZ)
  54. {
  55. return (1.0f / (deviceZ + gDeviceZToWorldZ.y)) * gDeviceZToWorldZ.x;
  56. }
  57. };
  58. };
  59. };
  60. Technique : base("PerCameraData") =
  61. {
  62. Language = "GLSL";
  63. Pass =
  64. {
  65. Common =
  66. {
  67. layout(binding = 0, std140) uniform PerCamera
  68. {
  69. vec3 gViewDir;
  70. vec3 gViewOrigin;
  71. mat4 gMatViewProj;
  72. mat4 gMatView;
  73. mat4 gMatProj;
  74. mat4 gMatInvProj;
  75. mat4 gMatInvViewProj;
  76. mat4 gMatScreenToWorld;
  77. vec2 gDeviceZToWorldZ;
  78. vec2 gNDCZToWorldZ;
  79. vec2 gNearFar;
  80. ivec4 gViewportRectangle;
  81. vec4 gClipToUVScaleOffset;
  82. };
  83. /** Converts Z value in range [0,1] into Z value in view space. */
  84. float convertFromDeviceZ(float deviceZ)
  85. {
  86. return (1.0f / (deviceZ + gDeviceZToWorldZ.y)) * gDeviceZToWorldZ.x;
  87. }
  88. };
  89. };
  90. };