scene_forward_inc.glsl 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. #define M_PI 3.14159265359
  2. #define ROUGHNESS_MAX_LOD 5
  3. #define MAX_GI_PROBES 8
  4. #if defined(GL_KHR_shader_subgroup_ballot) && defined(GL_KHR_shader_subgroup_arithmetic)
  5. #extension GL_KHR_shader_subgroup_ballot : enable
  6. #extension GL_KHR_shader_subgroup_arithmetic : enable
  7. #define USE_SUBGROUPS
  8. #endif
  9. #include "cluster_data_inc.glsl"
  10. #if !defined(MODE_RENDER_DEPTH) || defined(MODE_RENDER_MATERIAL) || defined(MODE_RENDER_SDF) || defined(MODE_RENDER_NORMAL_ROUGHNESS) || defined(MODE_RENDER_GIPROBE) || defined(TANGENT_USED) || defined(NORMAL_MAP_USED)
  11. #ifndef NORMAL_USED
  12. #define NORMAL_USED
  13. #endif
  14. #endif
  15. layout(push_constant, binding = 0, std430) uniform DrawCall {
  16. uint instance_index;
  17. uint uv_offset;
  18. uint pad0;
  19. uint pad1;
  20. }
  21. draw_call;
  22. /* Set 0 Scene data that never changes, ever */
  23. #define SAMPLER_NEAREST_CLAMP 0
  24. #define SAMPLER_LINEAR_CLAMP 1
  25. #define SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP 2
  26. #define SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP 3
  27. #define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_CLAMP 4
  28. #define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_CLAMP 5
  29. #define SAMPLER_NEAREST_REPEAT 6
  30. #define SAMPLER_LINEAR_REPEAT 7
  31. #define SAMPLER_NEAREST_WITH_MIPMAPS_REPEAT 8
  32. #define SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT 9
  33. #define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_REPEAT 10
  34. #define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_REPEAT 11
  35. #define SDFGI_MAX_CASCADES 8
  36. /* Set 1: Base Pass (never changes) */
  37. layout(set = 0, binding = 1) uniform sampler material_samplers[12];
  38. layout(set = 0, binding = 2) uniform sampler shadow_sampler;
  39. #define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6)
  40. #define INSTANCE_FLAGS_USE_SDFGI (1 << 7)
  41. #define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8)
  42. #define INSTANCE_FLAGS_USE_LIGHTMAP (1 << 9)
  43. #define INSTANCE_FLAGS_USE_SH_LIGHTMAP (1 << 10)
  44. #define INSTANCE_FLAGS_USE_GIPROBE (1 << 11)
  45. #define INSTANCE_FLAGS_MULTIMESH (1 << 12)
  46. #define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13)
  47. #define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14)
  48. #define INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA (1 << 15)
  49. #define INSTANCE_FLAGS_MULTIMESH_STRIDE_SHIFT 16
  50. //3 bits of stride
  51. #define INSTANCE_FLAGS_MULTIMESH_STRIDE_MASK 0x7
  52. #define INSTANCE_FLAGS_SKELETON (1 << 19)
  53. #define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 20)
  54. layout(set = 0, binding = 3, std430) restrict readonly buffer OmniLights {
  55. LightData data[];
  56. }
  57. omni_lights;
  58. layout(set = 0, binding = 4, std430) restrict readonly buffer SpotLights {
  59. LightData data[];
  60. }
  61. spot_lights;
  62. layout(set = 0, binding = 5) buffer restrict readonly ReflectionProbeData {
  63. ReflectionData data[];
  64. }
  65. reflections;
  66. layout(set = 0, binding = 6, std140) uniform DirectionalLights {
  67. DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
  68. }
  69. directional_lights;
  70. #define LIGHTMAP_FLAG_USE_DIRECTION 1
  71. #define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2
  72. struct Lightmap {
  73. mat3 normal_xform;
  74. };
  75. layout(set = 0, binding = 7, std140) restrict readonly buffer Lightmaps {
  76. Lightmap data[];
  77. }
  78. lightmaps;
  79. struct LightmapCapture {
  80. vec4 sh[9];
  81. };
  82. layout(set = 0, binding = 8, std140) restrict readonly buffer LightmapCaptures {
  83. LightmapCapture data[];
  84. }
  85. lightmap_captures;
  86. layout(set = 0, binding = 9) uniform texture2D decal_atlas;
  87. layout(set = 0, binding = 10) uniform texture2D decal_atlas_srgb;
  88. layout(set = 0, binding = 11, std430) restrict readonly buffer Decals {
  89. DecalData data[];
  90. }
  91. decals;
  92. layout(set = 0, binding = 12, std430) restrict readonly buffer GlobalVariableData {
  93. vec4 data[];
  94. }
  95. global_variables;
  96. #ifndef LOW_END_MODE
  97. struct SDFGIProbeCascadeData {
  98. vec3 position;
  99. float to_probe;
  100. ivec3 probe_world_offset;
  101. float to_cell; // 1/bounds * grid_size
  102. };
  103. layout(set = 0, binding = 13, std140) uniform SDFGI {
  104. vec3 grid_size;
  105. uint max_cascades;
  106. bool use_occlusion;
  107. int probe_axis_size;
  108. float probe_to_uvw;
  109. float normal_bias;
  110. vec3 lightprobe_tex_pixel_size;
  111. float energy;
  112. vec3 lightprobe_uv_offset;
  113. float y_mult;
  114. vec3 occlusion_clamp;
  115. uint pad3;
  116. vec3 occlusion_renormalize;
  117. uint pad4;
  118. vec3 cascade_probe_size;
  119. uint pad5;
  120. SDFGIProbeCascadeData cascades[SDFGI_MAX_CASCADES];
  121. }
  122. sdfgi;
  123. #endif //LOW_END_MODE
  124. /* Set 2: Render Pass (changes per render pass) */
  125. layout(set = 1, binding = 0, std140) uniform SceneData {
  126. mat4 projection_matrix;
  127. mat4 inv_projection_matrix;
  128. mat4 camera_matrix;
  129. mat4 inv_camera_matrix;
  130. vec2 viewport_size;
  131. vec2 screen_pixel_size;
  132. uint cluster_shift;
  133. uint cluster_width;
  134. uint cluster_type_size;
  135. uint max_cluster_element_count_div_32;
  136. //use vec4s because std140 doesnt play nice with vec2s, z and w are wasted
  137. vec4 directional_penumbra_shadow_kernel[32];
  138. vec4 directional_soft_shadow_kernel[32];
  139. vec4 penumbra_shadow_kernel[32];
  140. vec4 soft_shadow_kernel[32];
  141. uint directional_penumbra_shadow_samples;
  142. uint directional_soft_shadow_samples;
  143. uint penumbra_shadow_samples;
  144. uint soft_shadow_samples;
  145. vec4 ambient_light_color_energy;
  146. float ambient_color_sky_mix;
  147. bool use_ambient_light;
  148. bool use_ambient_cubemap;
  149. bool use_reflection_cubemap;
  150. mat3 radiance_inverse_xform;
  151. vec2 shadow_atlas_pixel_size;
  152. vec2 directional_shadow_pixel_size;
  153. uint directional_light_count;
  154. float dual_paraboloid_side;
  155. float z_far;
  156. float z_near;
  157. bool ssao_enabled;
  158. float ssao_light_affect;
  159. float ssao_ao_affect;
  160. bool roughness_limiter_enabled;
  161. float roughness_limiter_amount;
  162. float roughness_limiter_limit;
  163. uvec2 roughness_limiter_pad;
  164. vec4 ao_color;
  165. mat4 sdf_to_bounds;
  166. ivec3 sdf_offset;
  167. bool material_uv2_mode;
  168. ivec3 sdf_size;
  169. bool gi_upscale_for_msaa;
  170. bool volumetric_fog_enabled;
  171. float volumetric_fog_inv_length;
  172. float volumetric_fog_detail_spread;
  173. uint volumetric_fog_pad;
  174. bool fog_enabled;
  175. float fog_density;
  176. float fog_height;
  177. float fog_height_density;
  178. vec3 fog_light_color;
  179. float fog_sun_scatter;
  180. float fog_aerial_perspective;
  181. float time;
  182. float reflection_multiplier; // one normally, zero when rendering reflections
  183. bool pancake_shadows;
  184. }
  185. scene_data;
  186. struct InstanceData {
  187. mat4 transform;
  188. uint flags;
  189. uint instance_uniforms_ofs; //base offset in global buffer for instance variables
  190. uint gi_offset; //GI information when using lightmapping (VCT or lightmap index)
  191. uint layer_mask;
  192. vec4 lightmap_uv_scale;
  193. };
  194. layout(set = 1, binding = 1, std430) buffer restrict readonly InstanceDataBuffer {
  195. InstanceData data[];
  196. }
  197. instances;
  198. #ifdef USE_RADIANCE_CUBEMAP_ARRAY
  199. layout(set = 1, binding = 2) uniform textureCubeArray radiance_cubemap;
  200. #else
  201. layout(set = 1, binding = 2) uniform textureCube radiance_cubemap;
  202. #endif
  203. layout(set = 1, binding = 3) uniform textureCubeArray reflection_atlas;
  204. layout(set = 1, binding = 4) uniform texture2D shadow_atlas;
  205. layout(set = 1, binding = 5) uniform texture2D directional_shadow_atlas;
  206. layout(set = 1, binding = 6) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES];
  207. #ifndef LOW_END_MOD
  208. layout(set = 1, binding = 7) uniform texture3D gi_probe_textures[MAX_GI_PROBES];
  209. #endif
  210. layout(set = 1, binding = 8, std430) buffer restrict readonly ClusterBuffer {
  211. uint data[];
  212. }
  213. cluster_buffer;
  214. #ifdef MODE_RENDER_SDF
  215. layout(r16ui, set = 1, binding = 9) uniform restrict writeonly uimage3D albedo_volume_grid;
  216. layout(r32ui, set = 1, binding = 10) uniform restrict writeonly uimage3D emission_grid;
  217. layout(r32ui, set = 1, binding = 11) uniform restrict writeonly uimage3D emission_aniso_grid;
  218. layout(r32ui, set = 1, binding = 12) uniform restrict uimage3D geom_facing_grid;
  219. //still need to be present for shaders that use it, so remap them to something
  220. #define depth_buffer shadow_atlas
  221. #define color_buffer shadow_atlas
  222. #define normal_roughness_buffer shadow_atlas
  223. #else
  224. layout(set = 1, binding = 9) uniform texture2D depth_buffer;
  225. layout(set = 1, binding = 10) uniform texture2D color_buffer;
  226. #ifndef LOW_END_MODE
  227. layout(set = 1, binding = 11) uniform texture2D normal_roughness_buffer;
  228. layout(set = 1, binding = 12) uniform texture2D ao_buffer;
  229. layout(set = 1, binding = 13) uniform texture2D ambient_buffer;
  230. layout(set = 1, binding = 14) uniform texture2D reflection_buffer;
  231. layout(set = 1, binding = 15) uniform texture2DArray sdfgi_lightprobe_texture;
  232. layout(set = 1, binding = 16) uniform texture3D sdfgi_occlusion_cascades;
  233. struct GIProbeData {
  234. mat4 xform;
  235. vec3 bounds;
  236. float dynamic_range;
  237. float bias;
  238. float normal_bias;
  239. bool blend_ambient;
  240. uint texture_slot;
  241. float anisotropy_strength;
  242. float ambient_occlusion;
  243. float ambient_occlusion_size;
  244. uint mipmaps;
  245. };
  246. layout(set = 1, binding = 17, std140) uniform GIProbes {
  247. GIProbeData data[MAX_GI_PROBES];
  248. }
  249. gi_probes;
  250. layout(set = 1, binding = 18) uniform texture3D volumetric_fog_texture;
  251. #endif // LOW_END_MODE
  252. #endif
  253. /* Set 2 Skeleton & Instancing (can change per item) */
  254. layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
  255. vec4 data[];
  256. }
  257. transforms;
  258. /* Set 3 User Material */