MiscRendererTypes.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Shaders/Include/Common.h>
  7. ANKI_BEGIN_NAMESPACE
  8. /// Directional light (sun).
  9. struct DirectionalLight
  10. {
  11. Vec3 m_diffuseColor;
  12. F32 m_power;
  13. Vec3 m_direction;
  14. U32 m_shadowCascadeCount : 31; ///< If shadowCascadeCount is zero then it doesn't cast shadow.
  15. U32 m_active : 1;
  16. Vec4 m_shadowCascadeDistances;
  17. Mat4 m_textureMatrices[kMaxShadowCascades];
  18. Vec4 m_cascadeFarPlanes;
  19. Vec4 m_cascadePcfTexelRadius; ///< The radius of the PCF. In UV space.
  20. };
  21. static_assert(kMaxShadowCascades == 4u); // Because m_shadowCascadeDistances and m_cascadeFarPlanes is a Vec4
  22. /// Common matrices and stuff.
  23. struct CommonMatrices
  24. {
  25. Mat3x4 m_cameraTransform;
  26. Mat3x4 m_view;
  27. Mat4 m_projection;
  28. Mat4 m_viewProjection;
  29. Mat4 m_jitter;
  30. Mat4 m_projectionJitter;
  31. Mat4 m_viewProjectionJitter;
  32. Mat4 m_invertedViewProjectionJitter; ///< To unproject in world space.
  33. Mat4 m_invertedViewProjection;
  34. Mat4 m_invertedProjectionJitter; ///< To unproject in view space.
  35. /// It's being used to reproject a clip space position of the current frame to the previous frame. Its value should be m_jitter *
  36. /// m_prevFrame.m_viewProjection * m_invertedViewProjectionJitter. At first it unprojects the current position to world space, all fine here. Then
  37. /// it projects to the previous frame as if the previous frame was using the current frame's jitter matrix.
  38. Mat4 m_reprojection;
  39. /// To unproject to view space. Jitter not considered.
  40. /// @code
  41. /// F32 z = m_unprojectionParameters.z / (m_unprojectionParameters.w + depth);
  42. /// Vec2 xy = ndc * m_unprojectionParameters.xy * z;
  43. /// pos = Vec3(xy, z);
  44. /// @endcode
  45. Vec4 m_unprojectionParameters;
  46. /// Part of the perspective projection matrix. Used in cheapPerspectiveUnprojection
  47. Vec4 m_projMat00_11_22_23;
  48. Vec2 m_jitterOffsetNdc;
  49. F32 m_near;
  50. F32 m_far;
  51. };
  52. enum class SkyType
  53. {
  54. kSolidColor,
  55. kTextureWithEquirectangularMapping,
  56. kTextureWithEctahedronMapping,
  57. };
  58. struct Sky
  59. {
  60. Vec3 m_solidColor;
  61. U32 m_type : 2; // One of SkyType
  62. U32 m_texture : 30;
  63. };
  64. struct IndirectDiffuseClipmapTextures
  65. {
  66. U32 m_irradianceTexture : 16;
  67. U32 m_irradianceOctMapSize : 16;
  68. U32 m_radianceTexture : 16;
  69. U32 m_radianceOctMapSize : 16;
  70. U32 m_distanceMomentsTexture : 16;
  71. U32 m_distanceMomentsOctMapSize : 16;
  72. U32 m_averageIrradianceTexture : 16;
  73. U32 m_probeValidityTexture : 16;
  74. };
  75. struct IndirectDiffuseClipmapConstants
  76. {
  77. UVec3 m_probeCounts;
  78. U32 m_totalProbeCount;
  79. Vec4 m_sizes[kIndirectDiffuseClipmapCount];
  80. Vec4 m_aabbMins[kIndirectDiffuseClipmapCount];
  81. Vec4 m_previousFrameAabbMins[kIndirectDiffuseClipmapCount];
  82. IndirectDiffuseClipmapTextures m_textures[kIndirectDiffuseClipmapCount];
  83. };
  84. struct LocalLightsGridConstants
  85. {
  86. Vec3 m_volumeMin;
  87. F32 m_padding1;
  88. Vec3 m_volumeMax;
  89. F32 m_padding2;
  90. Vec3 m_cellSize;
  91. F32 m_padding3;
  92. UVec3 m_cellCounts;
  93. F32 m_padding4;
  94. };
  95. /// Common constants for all passes.
  96. struct GlobalRendererConstants
  97. {
  98. Vec2 m_renderingSize;
  99. F32 m_time;
  100. U32 m_frame;
  101. Vec4 m_nearPlaneWSpace;
  102. Vec3 m_cameraPosition;
  103. F32 m_reflectionProbesMipCount;
  104. UVec2 m_tileCounts;
  105. U32 m_zSplitCount;
  106. F32 m_zSplitCountOverFrustumLength; ///< m_zSplitCount/(far-near)
  107. Vec2 m_zSplitMagic; ///< It's the "a" and "b" of computeZSplitClusterIndex(). See there for details.
  108. U32 m_lightVolumeLastZSplit;
  109. U32 m_padding1;
  110. DirectionalLight m_directionalLight;
  111. CommonMatrices m_matrices;
  112. CommonMatrices m_previousMatrices;
  113. Sky m_sky;
  114. IndirectDiffuseClipmapConstants m_indirectDiffuseClipmaps;
  115. LocalLightsGridConstants m_localLightsGrid;
  116. };
  117. // RT shadows
  118. struct RtShadowsDenoiseConstants
  119. {
  120. Mat4 m_invViewProjMat;
  121. F32 m_time;
  122. U32 m_minSampleCount;
  123. U32 m_maxSampleCount;
  124. F32 m_padding2;
  125. };
  126. struct RtShadowsSbtBuildConstants
  127. {
  128. U32 m_shaderHandleDwordSize;
  129. U32 m_sbtRecordDwordSize;
  130. U32 m_raygenHandleIndex; ///< Index to the handles buffer
  131. U32 m_missHandleIndex;
  132. };
  133. // Lens flare
  134. struct LensFlareSprite
  135. {
  136. Vec4 m_posScale; // xy: Position, zw: Scale
  137. Vec4 m_color;
  138. Vec4 m_depthPad3;
  139. };
  140. // Depth downscale
  141. struct DepthDownscaleConstants
  142. {
  143. Vec2 m_srcTexSizeOverOne;
  144. U32 m_threadgroupCount;
  145. U32 m_mipmapCount;
  146. };
  147. struct ReflectionConstants
  148. {
  149. U32 m_ssrMaxIterations;
  150. U32 m_ssrStepIncrement;
  151. Vec2 m_roughnessCutoffToGiEdges;
  152. };
  153. struct PixelFailedSsr
  154. {
  155. U32 m_pixel;
  156. U32 m_reflectionDirAndRoughness;
  157. U32 m_pdf_f16_rayDirT_f16;
  158. };
  159. // Vol fog
  160. struct VolumetricFogConstants
  161. {
  162. Vec3 m_fogDiffuse;
  163. F32 m_fogScatteringCoeff;
  164. F32 m_fogAbsorptionCoeff;
  165. F32 m_near;
  166. F32 m_far;
  167. F32 m_zSplitCountf;
  168. UVec3 m_volumeSize;
  169. F32 m_maxZSplitsToProcessf;
  170. };
  171. // Vol lighting
  172. struct VolumetricLightingConstants
  173. {
  174. F32 m_densityAtMinHeight;
  175. F32 m_densityAtMaxHeight;
  176. F32 m_minHeight;
  177. F32 m_oneOverMaxMinusMinHeight; // 1 / (maxHeight / minHeight)
  178. UVec3 m_volumeSize;
  179. F32 m_maxZSplitsToProcessf;
  180. };
  181. // SSAO
  182. struct SsaoConstants
  183. {
  184. F32 m_radius; ///< In meters.
  185. U32 m_sampleCount;
  186. Vec2 m_viewportSizef;
  187. Vec4 m_unprojectionParameters;
  188. F32 m_projectionMat00;
  189. F32 m_projectionMat11;
  190. F32 m_projectionMat22;
  191. F32 m_projectionMat23;
  192. Vec2 m_padding;
  193. F32 m_ssaoPower;
  194. U32 m_frameCount;
  195. Mat3x4 m_viewMat;
  196. Mat3x4 m_viewToWorldMat;
  197. };
  198. struct LodAndRenderableIndex
  199. {
  200. U32 m_lod_2bit_renderableIndex_30bit;
  201. };
  202. ANKI_END_NAMESPACE