PerCameraData.bslinc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. Language = "HLSL11";
  33. Pass =
  34. {
  35. Common =
  36. {
  37. cbuffer PerCamera
  38. {
  39. float3 gViewDir;
  40. float3 gViewOrigin;
  41. float4x4 gMatViewProj;
  42. float4x4 gMatView;
  43. float4x4 gMatProj;
  44. float4x4 gMatInvProj;
  45. float4x4 gMatInvViewProj;
  46. float4x4 gMatScreenToWorld;
  47. float2 gDeviceZToWorldZ;
  48. float2 gNDCZToWorldZ;
  49. float2 gNearFar;
  50. int4 gViewportRectangle;
  51. float4 gClipToUVScaleOffset;
  52. float gAmbientFactor;
  53. }
  54. /** Converts Z value in range [0,1] into Z value in view space. */
  55. float convertFromDeviceZ(float deviceZ)
  56. {
  57. return (1.0f / (deviceZ + gDeviceZToWorldZ.y)) * gDeviceZToWorldZ.x;
  58. }
  59. };
  60. };
  61. };
  62. Technique : base("PerCameraData") =
  63. {
  64. Language = "GLSL";
  65. Pass =
  66. {
  67. Common =
  68. {
  69. layout(binding = 0, std140) uniform PerCamera
  70. {
  71. vec3 gViewDir;
  72. vec3 gViewOrigin;
  73. mat4 gMatViewProj;
  74. mat4 gMatView;
  75. mat4 gMatProj;
  76. mat4 gMatInvProj;
  77. mat4 gMatInvViewProj;
  78. mat4 gMatScreenToWorld;
  79. vec2 gDeviceZToWorldZ;
  80. vec2 gNDCZToWorldZ;
  81. vec2 gNearFar;
  82. ivec4 gViewportRectangle;
  83. vec4 gClipToUVScaleOffset;
  84. float gAmbientFactor;
  85. };
  86. /** Converts Z value in range [0,1] into Z value in view space. */
  87. float convertFromDeviceZ(float deviceZ)
  88. {
  89. return (1.0f / (deviceZ + gDeviceZToWorldZ.y)) * gDeviceZToWorldZ.x;
  90. }
  91. };
  92. };
  93. };