2019-08-19 00:40:52 +02:00
|
|
|
#define M_PI 3.14159265359
|
|
|
|
#define ROUGHNESS_MAX_LOD 5
|
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
#define MAX_VOXEL_GI_INSTANCES 8
|
2020-06-25 15:33:28 +02:00
|
|
|
|
2021-03-31 12:31:27 +02:00
|
|
|
#if defined(has_GL_KHR_shader_subgroup_ballot) && defined(has_GL_KHR_shader_subgroup_arithmetic)
|
2021-01-17 17:25:38 +01:00
|
|
|
|
|
|
|
#extension GL_KHR_shader_subgroup_ballot : enable
|
|
|
|
#extension GL_KHR_shader_subgroup_arithmetic : enable
|
|
|
|
|
|
|
|
#define USE_SUBGROUPS
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-08-13 03:21:01 +02:00
|
|
|
#include "cluster_data_inc.glsl"
|
2021-03-10 12:23:55 +01:00
|
|
|
#include "decal_data_inc.glsl"
|
2020-08-13 03:21:01 +02:00
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
#if !defined(MODE_RENDER_DEPTH) || defined(MODE_RENDER_MATERIAL) || defined(MODE_RENDER_SDF) || defined(MODE_RENDER_NORMAL_ROUGHNESS) || defined(MODE_RENDER_VOXEL_GI) || defined(TANGENT_USED) || defined(NORMAL_MAP_USED)
|
2020-12-18 22:56:14 +01:00
|
|
|
#ifndef NORMAL_USED
|
|
|
|
#define NORMAL_USED
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-09-07 03:51:27 +02:00
|
|
|
layout(push_constant, binding = 0, std430) uniform DrawCall {
|
2021-02-02 20:51:36 +01:00
|
|
|
uint instance_index;
|
|
|
|
uint uv_offset;
|
|
|
|
uint pad0;
|
|
|
|
uint pad1;
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
|
|
|
draw_call;
|
2019-09-07 03:51:27 +02:00
|
|
|
|
2021-03-10 12:23:55 +01:00
|
|
|
#define SDFGI_MAX_CASCADES 8
|
|
|
|
|
|
|
|
/* Set 0: Base Pass (never changes) */
|
|
|
|
|
|
|
|
#include "light_data_inc.glsl"
|
2019-08-26 22:43:58 +02:00
|
|
|
|
|
|
|
#define SAMPLER_NEAREST_CLAMP 0
|
|
|
|
#define SAMPLER_LINEAR_CLAMP 1
|
2020-02-20 00:31:43 +01:00
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_CLAMP 2
|
2019-08-26 22:43:58 +02:00
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP 3
|
2020-02-20 00:31:43 +01:00
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_CLAMP 4
|
2019-08-26 22:43:58 +02:00
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_CLAMP 5
|
|
|
|
#define SAMPLER_NEAREST_REPEAT 6
|
|
|
|
#define SAMPLER_LINEAR_REPEAT 7
|
2020-02-20 00:31:43 +01:00
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_REPEAT 8
|
2019-08-26 22:43:58 +02:00
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_REPEAT 9
|
2020-02-20 00:31:43 +01:00
|
|
|
#define SAMPLER_NEAREST_WITH_MIPMAPS_ANISOTROPIC_REPEAT 10
|
2019-08-26 22:43:58 +02:00
|
|
|
#define SAMPLER_LINEAR_WITH_MIPMAPS_ANISOTROPIC_REPEAT 11
|
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 0, binding = 1) uniform sampler material_samplers[12];
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 0, binding = 2) uniform sampler shadow_sampler;
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 3) uniform sampler decal_sampler;
|
|
|
|
|
|
|
|
layout(set = 0, binding = 4) uniform sampler light_projector_sampler;
|
|
|
|
|
2021-06-29 16:45:07 +02:00
|
|
|
#define INSTANCE_FLAGS_NON_UNIFORM_SCALE (1 << 5)
|
2020-06-25 15:33:28 +02:00
|
|
|
#define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6)
|
|
|
|
#define INSTANCE_FLAGS_USE_SDFGI (1 << 7)
|
2020-05-01 14:34:23 +02:00
|
|
|
#define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8)
|
|
|
|
#define INSTANCE_FLAGS_USE_LIGHTMAP (1 << 9)
|
|
|
|
#define INSTANCE_FLAGS_USE_SH_LIGHTMAP (1 << 10)
|
2021-06-05 00:47:26 +02:00
|
|
|
#define INSTANCE_FLAGS_USE_VOXEL_GI (1 << 11)
|
2019-11-05 12:01:00 +01:00
|
|
|
#define INSTANCE_FLAGS_MULTIMESH (1 << 12)
|
|
|
|
#define INSTANCE_FLAGS_MULTIMESH_FORMAT_2D (1 << 13)
|
|
|
|
#define INSTANCE_FLAGS_MULTIMESH_HAS_COLOR (1 << 14)
|
|
|
|
#define INSTANCE_FLAGS_MULTIMESH_HAS_CUSTOM_DATA (1 << 15)
|
2021-04-27 17:43:49 +02:00
|
|
|
#define INSTANCE_FLAGS_PARTICLE_TRAIL_SHIFT 16
|
2019-09-14 05:37:42 +02:00
|
|
|
//3 bits of stride
|
2021-04-27 17:43:49 +02:00
|
|
|
#define INSTANCE_FLAGS_PARTICLE_TRAIL_MASK 0xFF
|
2019-09-14 05:37:42 +02:00
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 5, std430) restrict readonly buffer OmniLights {
|
2021-01-17 17:25:38 +01:00
|
|
|
LightData data[];
|
|
|
|
}
|
|
|
|
omni_lights;
|
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 6, std430) restrict readonly buffer SpotLights {
|
2020-04-08 03:51:52 +02:00
|
|
|
LightData data[];
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
2021-01-17 17:25:38 +01:00
|
|
|
spot_lights;
|
2019-09-07 03:51:27 +02:00
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 7, std430) restrict readonly buffer ReflectionProbeData {
|
2020-07-23 01:39:09 +02:00
|
|
|
ReflectionData data[];
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
|
|
|
reflections;
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 8, std140) uniform DirectionalLights {
|
2019-09-07 03:51:27 +02:00
|
|
|
DirectionalLightData data[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
|
|
|
directional_lights;
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
#define LIGHTMAP_FLAG_USE_DIRECTION 1
|
|
|
|
#define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2
|
|
|
|
|
|
|
|
struct Lightmap {
|
|
|
|
mat3 normal_xform;
|
|
|
|
};
|
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 9, std140) restrict readonly buffer Lightmaps {
|
2020-05-01 14:34:23 +02:00
|
|
|
Lightmap data[];
|
|
|
|
}
|
|
|
|
lightmaps;
|
|
|
|
|
|
|
|
struct LightmapCapture {
|
|
|
|
vec4 sh[9];
|
|
|
|
};
|
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 10, std140) restrict readonly buffer LightmapCaptures {
|
2020-05-01 14:34:23 +02:00
|
|
|
LightmapCapture data[];
|
|
|
|
}
|
|
|
|
lightmap_captures;
|
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 11) uniform texture2D decal_atlas;
|
|
|
|
layout(set = 0, binding = 12) uniform texture2D decal_atlas_srgb;
|
2020-04-14 05:05:21 +02:00
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 13, std430) restrict readonly buffer Decals {
|
2020-04-14 05:05:21 +02:00
|
|
|
DecalData data[];
|
|
|
|
}
|
|
|
|
decals;
|
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 14, std430) restrict readonly buffer GlobalVariableData {
|
2020-04-17 04:52:00 +02:00
|
|
|
vec4 data[];
|
|
|
|
}
|
|
|
|
global_variables;
|
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
struct SDFVoxelGICascadeData {
|
2020-06-25 15:33:28 +02:00
|
|
|
vec3 position;
|
|
|
|
float to_probe;
|
|
|
|
ivec3 probe_world_offset;
|
|
|
|
float to_cell; // 1/bounds * grid_size
|
|
|
|
};
|
|
|
|
|
2021-07-19 21:41:55 +02:00
|
|
|
layout(set = 0, binding = 15, std140) uniform SDFGI {
|
2020-06-25 15:33:28 +02:00
|
|
|
vec3 grid_size;
|
|
|
|
uint max_cascades;
|
|
|
|
|
|
|
|
bool use_occlusion;
|
|
|
|
int probe_axis_size;
|
|
|
|
float probe_to_uvw;
|
|
|
|
float normal_bias;
|
|
|
|
|
|
|
|
vec3 lightprobe_tex_pixel_size;
|
|
|
|
float energy;
|
|
|
|
|
|
|
|
vec3 lightprobe_uv_offset;
|
|
|
|
float y_mult;
|
|
|
|
|
|
|
|
vec3 occlusion_clamp;
|
|
|
|
uint pad3;
|
|
|
|
|
|
|
|
vec3 occlusion_renormalize;
|
|
|
|
uint pad4;
|
|
|
|
|
|
|
|
vec3 cascade_probe_size;
|
|
|
|
uint pad5;
|
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
SDFVoxelGICascadeData cascades[SDFGI_MAX_CASCADES];
|
2020-06-25 15:33:28 +02:00
|
|
|
}
|
|
|
|
sdfgi;
|
|
|
|
|
2021-03-10 12:23:55 +01:00
|
|
|
/* Set 1: Render Pass (changes per render pass) */
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 0, std140) uniform SceneData {
|
|
|
|
mat4 projection_matrix;
|
|
|
|
mat4 inv_projection_matrix;
|
|
|
|
|
|
|
|
mat4 camera_matrix;
|
|
|
|
mat4 inv_camera_matrix;
|
|
|
|
|
|
|
|
vec2 viewport_size;
|
|
|
|
vec2 screen_pixel_size;
|
|
|
|
|
|
|
|
uint cluster_shift;
|
|
|
|
uint cluster_width;
|
|
|
|
uint cluster_type_size;
|
|
|
|
uint max_cluster_element_count_div_32;
|
|
|
|
|
Fix various typos with codespell
Found via `codespell -q 3 -S ./thirdparty,*.po,./DONORS.md -L ackward,ang,ans,ba,beng,cas,childs,childrens,dof,doubleclick,fave,findn,hist,inout,leapyear,lod,nd,numer,ois,ony,paket,seeked,sinc,switchs,te,uint`
2021-07-07 17:17:32 +02:00
|
|
|
// Use vec4s because std140 doesn't play nice with vec2s, z and w are wasted.
|
2021-02-02 20:51:36 +01:00
|
|
|
vec4 directional_penumbra_shadow_kernel[32];
|
|
|
|
vec4 directional_soft_shadow_kernel[32];
|
|
|
|
vec4 penumbra_shadow_kernel[32];
|
|
|
|
vec4 soft_shadow_kernel[32];
|
|
|
|
|
|
|
|
vec4 ambient_light_color_energy;
|
|
|
|
|
|
|
|
float ambient_color_sky_mix;
|
|
|
|
bool use_ambient_light;
|
|
|
|
bool use_ambient_cubemap;
|
|
|
|
bool use_reflection_cubemap;
|
|
|
|
|
|
|
|
mat3 radiance_inverse_xform;
|
|
|
|
|
|
|
|
vec2 shadow_atlas_pixel_size;
|
|
|
|
vec2 directional_shadow_pixel_size;
|
|
|
|
|
|
|
|
uint directional_light_count;
|
|
|
|
float dual_paraboloid_side;
|
|
|
|
float z_far;
|
|
|
|
float z_near;
|
|
|
|
|
|
|
|
bool ssao_enabled;
|
|
|
|
float ssao_light_affect;
|
|
|
|
float ssao_ao_affect;
|
|
|
|
bool roughness_limiter_enabled;
|
|
|
|
|
|
|
|
float roughness_limiter_amount;
|
|
|
|
float roughness_limiter_limit;
|
|
|
|
uvec2 roughness_limiter_pad;
|
|
|
|
|
|
|
|
vec4 ao_color;
|
|
|
|
|
|
|
|
mat4 sdf_to_bounds;
|
|
|
|
|
|
|
|
ivec3 sdf_offset;
|
|
|
|
bool material_uv2_mode;
|
|
|
|
|
|
|
|
ivec3 sdf_size;
|
|
|
|
bool gi_upscale_for_msaa;
|
|
|
|
|
|
|
|
bool volumetric_fog_enabled;
|
|
|
|
float volumetric_fog_inv_length;
|
|
|
|
float volumetric_fog_detail_spread;
|
|
|
|
uint volumetric_fog_pad;
|
|
|
|
|
|
|
|
bool fog_enabled;
|
|
|
|
float fog_density;
|
|
|
|
float fog_height;
|
|
|
|
float fog_height_density;
|
|
|
|
|
|
|
|
vec3 fog_light_color;
|
|
|
|
float fog_sun_scatter;
|
|
|
|
|
|
|
|
float fog_aerial_perspective;
|
|
|
|
|
|
|
|
float time;
|
|
|
|
float reflection_multiplier; // one normally, zero when rendering reflections
|
|
|
|
|
|
|
|
bool pancake_shadows;
|
|
|
|
}
|
|
|
|
scene_data;
|
|
|
|
|
|
|
|
struct InstanceData {
|
|
|
|
mat4 transform;
|
|
|
|
uint flags;
|
|
|
|
uint instance_uniforms_ofs; //base offset in global buffer for instance variables
|
|
|
|
uint gi_offset; //GI information when using lightmapping (VCT or lightmap index)
|
|
|
|
uint layer_mask;
|
|
|
|
vec4 lightmap_uv_scale;
|
|
|
|
};
|
|
|
|
|
|
|
|
layout(set = 1, binding = 1, std430) buffer restrict readonly InstanceDataBuffer {
|
|
|
|
InstanceData data[];
|
|
|
|
}
|
|
|
|
instances;
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2019-09-07 03:51:27 +02:00
|
|
|
#ifdef USE_RADIANCE_CUBEMAP_ARRAY
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 2) uniform textureCubeArray radiance_cubemap;
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2019-09-07 03:51:27 +02:00
|
|
|
#else
|
2019-08-19 00:40:52 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 2) uniform textureCube radiance_cubemap;
|
2019-08-19 00:40:52 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 3) uniform textureCubeArray reflection_atlas;
|
2020-01-25 11:18:55 +01:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 4) uniform texture2D shadow_atlas;
|
2020-01-25 11:18:55 +01:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 5) uniform texture2D directional_shadow_atlas;
|
2021-01-24 20:00:20 +01:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 6) uniform texture2DArray lightmap_textures[MAX_LIGHTMAP_TEXTURES];
|
2020-12-31 13:42:56 +01:00
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
layout(set = 1, binding = 7) uniform texture3D voxel_gi_textures[MAX_VOXEL_GI_INSTANCES];
|
2020-06-25 15:33:28 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 8, std430) buffer restrict readonly ClusterBuffer {
|
2021-01-17 17:25:38 +01:00
|
|
|
uint data[];
|
|
|
|
}
|
|
|
|
cluster_buffer;
|
|
|
|
|
2020-06-25 15:33:28 +02:00
|
|
|
#ifdef MODE_RENDER_SDF
|
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(r16ui, set = 1, binding = 9) uniform restrict writeonly uimage3D albedo_volume_grid;
|
|
|
|
layout(r32ui, set = 1, binding = 10) uniform restrict writeonly uimage3D emission_grid;
|
|
|
|
layout(r32ui, set = 1, binding = 11) uniform restrict writeonly uimage3D emission_aniso_grid;
|
|
|
|
layout(r32ui, set = 1, binding = 12) uniform restrict uimage3D geom_facing_grid;
|
2020-06-25 15:33:28 +02:00
|
|
|
|
|
|
|
//still need to be present for shaders that use it, so remap them to something
|
|
|
|
#define depth_buffer shadow_atlas
|
|
|
|
#define color_buffer shadow_atlas
|
|
|
|
#define normal_roughness_buffer shadow_atlas
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 9) uniform texture2D depth_buffer;
|
|
|
|
layout(set = 1, binding = 10) uniform texture2D color_buffer;
|
2020-12-07 22:27:38 +01:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 11) uniform texture2D normal_roughness_buffer;
|
|
|
|
layout(set = 1, binding = 12) uniform texture2D ao_buffer;
|
|
|
|
layout(set = 1, binding = 13) uniform texture2D ambient_buffer;
|
|
|
|
layout(set = 1, binding = 14) uniform texture2D reflection_buffer;
|
|
|
|
layout(set = 1, binding = 15) uniform texture2DArray sdfgi_lightprobe_texture;
|
|
|
|
layout(set = 1, binding = 16) uniform texture3D sdfgi_occlusion_cascades;
|
2020-06-25 15:33:28 +02:00
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
struct VoxelGIData {
|
2020-06-25 15:33:28 +02:00
|
|
|
mat4 xform;
|
|
|
|
vec3 bounds;
|
|
|
|
float dynamic_range;
|
|
|
|
|
|
|
|
float bias;
|
|
|
|
float normal_bias;
|
|
|
|
bool blend_ambient;
|
|
|
|
uint texture_slot;
|
|
|
|
|
|
|
|
float anisotropy_strength;
|
|
|
|
float ambient_occlusion;
|
|
|
|
float ambient_occlusion_size;
|
2020-08-13 03:21:01 +02:00
|
|
|
uint mipmaps;
|
2020-06-25 15:33:28 +02:00
|
|
|
};
|
|
|
|
|
2021-06-05 00:47:26 +02:00
|
|
|
layout(set = 1, binding = 17, std140) uniform VoxelGIs {
|
|
|
|
VoxelGIData data[MAX_VOXEL_GI_INSTANCES];
|
2020-06-25 15:33:28 +02:00
|
|
|
}
|
2021-06-05 00:47:26 +02:00
|
|
|
voxel_gi_instances;
|
2020-06-25 15:33:28 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
layout(set = 1, binding = 18) uniform texture3D volumetric_fog_texture;
|
2020-12-07 22:27:38 +01:00
|
|
|
|
2020-06-25 15:33:28 +02:00
|
|
|
#endif
|
2019-10-03 22:39:08 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
/* Set 2 Skeleton & Instancing (can change per item) */
|
2019-10-03 22:39:08 +02:00
|
|
|
|
2020-12-07 22:27:38 +01:00
|
|
|
layout(set = 2, binding = 0, std430) restrict readonly buffer Transforms {
|
2019-11-05 12:01:00 +01:00
|
|
|
vec4 data[];
|
2020-02-11 14:01:43 +01:00
|
|
|
}
|
|
|
|
transforms;
|
2019-10-03 22:39:08 +02:00
|
|
|
|
2021-02-02 20:51:36 +01:00
|
|
|
/* Set 3 User Material */
|