1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-26 15:46:23 +00:00

Addition of SDFGI for open world global illumination

Move GI to a deferred pass
This commit is contained in:
Juan Linietsky
2020-06-25 10:33:28 -03:00
parent b92477d77e
commit 201d606b3d
53 changed files with 8966 additions and 1033 deletions

View File

@@ -1,6 +1,8 @@
#define M_PI 3.14159265359
#define ROUGHNESS_MAX_LOD 5
#define MAX_GI_PROBES 8
layout(push_constant, binding = 0, std430) uniform DrawCall {
uint instance_index;
uint pad; //16 bits minimum size
@@ -27,6 +29,8 @@ layout(set = 0, binding = 1) uniform sampler material_samplers[12];
layout(set = 0, binding = 2) uniform sampler shadow_sampler;
#define SDFGI_MAX_CASCADES 8
layout(set = 0, binding = 3, std140) uniform SceneData {
mat4 projection_matrix;
mat4 inv_projection_matrix;
@@ -76,11 +80,19 @@ layout(set = 0, binding = 3, std140) uniform SceneData {
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;
uint pad_material0;
uint pad_material1;
uint pad_material2;
ivec3 sdf_size;
bool gi_upscale_for_msaa;
#if 0
vec4 ambient_light_color;
@@ -120,6 +132,8 @@ layout(set = 0, binding = 3, std140) uniform SceneData {
scene_data;
#define INSTANCE_FLAGS_USE_GI_BUFFERS (1 << 6)
#define INSTANCE_FLAGS_USE_SDFGI (1 << 7)
#define INSTANCE_FLAGS_USE_LIGHTMAP_CAPTURE (1 << 8)
#define INSTANCE_FLAGS_USE_LIGHTMAP (1 << 9)
#define INSTANCE_FLAGS_USE_SH_LIGHTMAP (1 << 10)
@@ -175,13 +189,18 @@ layout(set = 0, binding = 5, std430) restrict readonly buffer Lights {
}
lights;
#define REFLECTION_AMBIENT_DISABLED 0
#define REFLECTION_AMBIENT_ENVIRONMENT 1
#define REFLECTION_AMBIENT_COLOR 2
struct ReflectionData {
vec3 box_extents;
float index;
vec3 box_offset;
uint mask;
vec4 params; // intensity, 0, interior , boxproject
vec4 ambient; // ambient color, energy
vec3 ambient; // ambient color
uint ambient_mode;
mat4 local_matrix; // up to here for spot and omni, rest is for directional
// notes: for ambientblend, use distance to edge to blend between already existing global environment
};
@@ -229,29 +248,6 @@ layout(set = 0, binding = 7, std140) uniform DirectionalLights {
}
directional_lights;
struct GIProbeData {
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;
uint pad2;
};
layout(set = 0, binding = 8, std140) uniform GIProbes {
GIProbeData data[MAX_GI_PROBES];
}
gi_probes;
layout(set = 0, binding = 9) uniform texture3D gi_probe_textures[MAX_GI_PROBE_TEXTURES];
#define LIGHTMAP_FLAG_USE_DIRECTION 1
#define LIGHTMAP_FLAG_USE_SPECULAR_DIRECTION 2
@@ -319,6 +315,41 @@ layout(set = 0, binding = 19, std430) restrict readonly buffer GlobalVariableDat
}
global_variables;
struct SDFGIProbeCascadeData {
vec3 position;
float to_probe;
ivec3 probe_world_offset;
float to_cell; // 1/bounds * grid_size
};
layout(set = 0, binding = 20, std140) uniform SDFGI {
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;
SDFGIProbeCascadeData cascades[SDFGI_MAX_CASCADES];
}
sdfgi;
// decal atlas
/* Set 1, Radiance */
@@ -339,13 +370,57 @@ layout(set = 2, binding = 0) uniform textureCubeArray reflection_atlas;
layout(set = 2, binding = 1) uniform texture2D shadow_atlas;
layout(set = 2, binding = 2) uniform texture3D gi_probe_textures[MAX_GI_PROBES];
/* Set 3, Render Buffers */
#ifdef MODE_RENDER_SDF
layout(r16ui, set = 3, binding = 0) uniform restrict writeonly uimage3D albedo_volume_grid;
layout(r32ui, set = 3, binding = 1) uniform restrict writeonly uimage3D emission_grid;
layout(r32ui, set = 3, binding = 2) uniform restrict writeonly uimage3D emission_aniso_grid;
layout(r32ui, set = 3, binding = 3) uniform restrict uimage3D geom_facing_grid;
//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
layout(set = 3, binding = 0) uniform texture2D depth_buffer;
layout(set = 3, binding = 1) uniform texture2D color_buffer;
layout(set = 3, binding = 2) uniform texture2D normal_buffer;
layout(set = 3, binding = 3) uniform texture2D roughness_buffer;
layout(set = 3, binding = 2) uniform texture2D normal_roughness_buffer;
layout(set = 3, binding = 4) uniform texture2D ao_buffer;
layout(set = 3, binding = 5) uniform texture2D ambient_buffer;
layout(set = 3, binding = 6) uniform texture2D reflection_buffer;
layout(set = 3, binding = 7) uniform texture2DArray sdfgi_lightprobe_texture;
layout(set = 3, binding = 8) uniform texture3D sdfgi_occlusion_cascades;
struct GIProbeData {
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;
uint pad2;
};
layout(set = 3, binding = 9, std140) uniform GIProbes {
GIProbeData data[MAX_GI_PROBES];
}
gi_probes;
#endif
/* Set 4 Skeleton & Instancing (Multimesh) */