scene_forward_mobile_inc.glsl 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #define M_PI 3.14159265359
  2. #define MAX_VIEWS 2
  3. #if defined(USE_MULTIVIEW) && defined(has_VK_KHR_multiview)
  4. #extension GL_EXT_multiview : enable
  5. #endif
  6. #include "decal_data_inc.glsl"
  7. #if !defined(MODE_RENDER_DEPTH) || defined(MODE_RENDER_MATERIAL) || defined(TANGENT_USED) || defined(NORMAL_MAP_USED)
  8. #ifndef NORMAL_USED
  9. #define NORMAL_USED
  10. #endif
  11. #endif
  12. /* don't exceed 128 bytes!! */
  13. /* put instance data into our push content, not a array */
  14. layout(push_constant, binding = 0, std430) uniform DrawCall {
  15. highp mat4 transform; // 64 - 64
  16. uint flags; // 04 - 68
  17. uint instance_uniforms_ofs; //base offset in global buffer for instance variables // 04 - 72
  18. uint gi_offset; //GI information when using lightmapping (VCT or lightmap index) // 04 - 76
  19. uint layer_mask; // 04 - 80
  20. highp vec4 lightmap_uv_scale; // 16 - 96 doubles as uv_offset when needed
  21. uvec2 reflection_probes; // 08 - 104
  22. uvec2 omni_lights; // 08 - 112
  23. uvec2 spot_lights; // 08 - 120
  24. uvec2 decals; // 08 - 128
  25. }
  26. draw_call;
  27. /* Set 0: Base Pass (never changes) */
  28. #include "light_data_inc.glsl"
  29. #define SAMPLER_NEAREST_CLAMP 0
  30. #define SAMPLER_LINEAR_CLAMP 1
  31. #define SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP 2
  32. #define SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP 3
  33. #define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_CLAMP 4
  34. #define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_CLAMP 5
  35. #define SAMPLER_NEAREST_REPEAT 6
  36. #define SAMPLER_LINEAR_REPEAT 7
  37. #define SAMPLER_NEAREST_WITH_MIPMAPS_REPEAT 8
  38. #define SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT 9
  39. #define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_REPEAT 10
  40. #define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_REPEAT 11
  41. layout(set = 0, binding = 1) uniform sampler material_samplers[12];
  42. layout(set = 0, binding = 2) uniform sampler shadow_sampler;
  43. layout(set = 0, binding = 3) uniform sampler decal_sampler;
  44. layout(set = 0, binding = 4) uniform sampler light_projector_sampler;
  45. #define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 5)
  46. #define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6)
  47. #define INSTANCE_FLAGS_USE_SDFGI (1 << 7)
  48. #define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8)
  49. #define INSTANCE_FLAGS_USE_LIGHTMAP (1 << 9)
  50. #define INSTANCE_FLAGS_USE_SH_LIGHTMAP (1 << 10)
  51. #define INSTANCE_FLAGS_USE_VOXEL_GI (1 << 11)
  52. #define INSTANCE_FLAGS_MULTIMESH (1 << 12)
  53. #define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13)
  54. #define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14)
  55. #define INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA (1 << 15)
  56. #define INSTANCE_FLAGS_PARTICLE_TRAIL_SHIFT 16
  57. //3 bits of stride
  58. #define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF
  59. layout(set = 0, binding = 5, std430) restrict readonly buffer OmniLights {
  60. LightData data[];
  61. }
  62. omni_lights;
  63. layout(set = 0, binding = 6, std430) restrict readonly buffer SpotLights {
  64. LightData data[];
  65. }
  66. spot_lights;
  67. layout(set = 0, binding = 7, std430) restrict readonly buffer ReflectionProbeData {
  68. ReflectionData data[];
  69. }
  70. reflections;
  71. layout(set = 0, binding = 8, std140) uniform DirectionalLights {
  72. DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
  73. }
  74. directional_lights;
  75. #define LIGHTMAP_FLAG_USE_DIRECTION 1
  76. #define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2
  77. struct Lightmap {
  78. mediump mat3 normal_xform;
  79. };
  80. layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps {
  81. Lightmap data[];
  82. }
  83. lightmaps;
  84. struct LightmapCapture {
  85. mediump vec4 sh[9];
  86. };
  87. layout(set = 0, binding = 10, std140) restrict readonly buffer LightmapCaptures {
  88. LightmapCapture data[];
  89. }
  90. lightmap_captures;
  91. layout(set = 0, binding = 11) uniform mediump texture2D decal_atlas;
  92. layout(set = 0, binding = 12) uniform mediump texture2D decal_atlas_srgb;
  93. layout(set = 0, binding = 13, std430) restrict readonly buffer Decals {
  94. DecalData data[];
  95. }
  96. decals;
  97. layout(set = 0, binding = 14, std430) restrict readonly buffer GlobalVariableData {
  98. highp vec4 data[];
  99. }
  100. global_variables;
  101. /* Set 1: Render Pass (changes per render pass) */
  102. layout(set = 1, binding = 0, std140) uniform SceneData {
  103. highp mat4 projection_matrix;
  104. highp mat4 inv_projection_matrix;
  105. highp mat4 camera_matrix;
  106. highp mat4 inv_camera_matrix;
  107. // only used for multiview
  108. highp mat4 projection_matrix_view[MAX_VIEWS];
  109. highp mat4 inv_projection_matrix_view[MAX_VIEWS];
  110. highp vec2 viewport_size;
  111. highp vec2 screen_pixel_size;
  112. // Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
  113. highp vec4 directional_penumbra_shadow_kernel[32];
  114. highp vec4 directional_soft_shadow_kernel[32];
  115. highp vec4 penumbra_shadow_kernel[32];
  116. highp vec4 soft_shadow_kernel[32];
  117. mediump vec4 ambient_light_color_energy;
  118. mediump float ambient_color_sky_mix;
  119. bool use_ambient_light;
  120. bool use_ambient_cubemap;
  121. bool use_reflection_cubemap;
  122. mediump mat3 radiance_inverse_xform;
  123. highp vec2 shadow_atlas_pixel_size;
  124. highp vec2 directional_shadow_pixel_size;
  125. uint directional_light_count;
  126. mediump float dual_paraboloid_side;
  127. highp float z_far;
  128. highp float z_near;
  129. bool ssao_enabled;
  130. mediump float ssao_light_affect;
  131. mediump float ssao_ao_affect;
  132. bool roughness_limiter_enabled;
  133. mediump float roughness_limiter_amount;
  134. mediump float roughness_limiter_limit;
  135. uvec2 roughness_limiter_pad;
  136. bool fog_enabled;
  137. highp float fog_density;
  138. highp float fog_height;
  139. highp float fog_height_density;
  140. mediump vec3 fog_light_color;
  141. mediump float fog_sun_scatter;
  142. mediump float fog_aerial_perspective;
  143. bool material_uv2_mode;
  144. highp float time;
  145. mediump float reflection_multiplier; // one normally, zero when rendering reflections
  146. bool pancake_shadows;
  147. uint pad1;
  148. uint pad2;
  149. uint pad3;
  150. }
  151. scene_data;
  152. #ifdef USE_RADIANCE_CUBEMAP_ARRAY
  153. layout(set = 1, binding = 2) uniform mediump textureCubeArray radiance_cubemap;
  154. #else
  155. layout(set = 1, binding = 2) uniform mediump textureCube radiance_cubemap;
  156. #endif
  157. layout(set = 1, binding = 3) uniform mediump textureCubeArray reflection_atlas;
  158. layout(set = 1, binding = 4) uniform highp texture2D shadow_atlas;
  159. layout(set = 1, binding = 5) uniform highp texture2D directional_shadow_atlas;
  160. // this needs to change to providing just the lightmap we're using..
  161. layout(set = 1, binding = 6) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES];
  162. layout(set = 1, binding = 9) uniform highp texture2D depth_buffer;
  163. layout(set = 1, binding = 10) uniform mediump texture2D color_buffer;
  164. /* Set 2 Skeleton & Instancing (can change per item) */
  165. layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
  166. highp vec4 data[];
  167. }
  168. transforms;
  169. /* Set 3 User Material */