Merge pull request #61221 from BastiaanOlij/split_gi_effects
This commit is contained in:
commit
051fb86fb0
52 changed files with 2149 additions and 1275 deletions
|
|
@ -17,3 +17,4 @@ if "RD_GLSL" in env["BUILDERS"]:
|
|||
env.RD_GLSL(glsl_file)
|
||||
|
||||
SConscript("effects/SCsub")
|
||||
SConscript("environment/SCsub")
|
||||
|
|
|
|||
17
servers/rendering/renderer_rd/shaders/environment/SCsub
Normal file
17
servers/rendering/renderer_rd/shaders/environment/SCsub
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
Import("env")
|
||||
|
||||
if "RD_GLSL" in env["BUILDERS"]:
|
||||
# find all include files
|
||||
gl_include_files = [str(f) for f in Glob("*_inc.glsl")]
|
||||
|
||||
# find all shader code(all glsl files excluding our include files)
|
||||
glsl_files = [str(f) for f in Glob("*.glsl") if str(f) not in gl_include_files]
|
||||
|
||||
# make sure we recompile shaders if include files change
|
||||
env.Depends([f + ".gen.h" for f in glsl_files], gl_include_files)
|
||||
|
||||
# compile shaders
|
||||
for glsl_file in glsl_files:
|
||||
env.RD_GLSL(glsl_file)
|
||||
|
|
@ -86,19 +86,29 @@ voxel_gi_instances;
|
|||
|
||||
layout(set = 0, binding = 17) uniform texture3D voxel_gi_textures[MAX_VOXEL_GI_INSTANCES];
|
||||
|
||||
layout(push_constant, std430) uniform Params {
|
||||
layout(set = 0, binding = 18, std140) uniform SceneData {
|
||||
mat4x4 inv_projection[2];
|
||||
mat4x4 cam_transform;
|
||||
vec4 eye_offset[2];
|
||||
|
||||
ivec2 screen_size;
|
||||
float z_near;
|
||||
float z_far;
|
||||
|
||||
vec4 proj_info;
|
||||
float pad1;
|
||||
float pad2;
|
||||
}
|
||||
scene_data;
|
||||
|
||||
layout(push_constant, std430) uniform Params {
|
||||
uint view_index;
|
||||
uint max_voxel_gi_instances;
|
||||
bool high_quality_vct;
|
||||
bool orthogonal;
|
||||
uint pad;
|
||||
|
||||
mat3x4 cam_rotation;
|
||||
vec4 proj_info;
|
||||
|
||||
float z_near;
|
||||
float z_far;
|
||||
float pad1;
|
||||
float pad2;
|
||||
}
|
||||
params;
|
||||
|
||||
|
|
@ -130,6 +140,16 @@ vec4 blend_color(vec4 src, vec4 dst) {
|
|||
}
|
||||
|
||||
vec3 reconstruct_position(ivec2 screen_pos) {
|
||||
#ifdef USE_MULTIVIEW
|
||||
vec4 pos;
|
||||
pos.xy = (2.0 * vec2(screen_pos) / vec2(scene_data.screen_size)) - 1.0;
|
||||
pos.z = texelFetch(sampler2D(depth_buffer, linear_sampler), screen_pos, 0).r * 2.0 - 1.0;
|
||||
pos.w = 1.0;
|
||||
|
||||
pos = scene_data.inv_projection[params.view_index] * pos;
|
||||
|
||||
return pos.xyz / pos.w;
|
||||
#else
|
||||
vec3 pos;
|
||||
pos.z = texelFetch(sampler2D(depth_buffer, linear_sampler), screen_pos, 0).r;
|
||||
|
||||
|
|
@ -147,6 +167,7 @@ vec3 reconstruct_position(ivec2 screen_pos) {
|
|||
}
|
||||
|
||||
return pos;
|
||||
#endif
|
||||
}
|
||||
|
||||
void sdfvoxel_gi_process(uint cascade, vec3 cascade_pos, vec3 cam_pos, vec3 cam_normal, vec3 cam_specular_normal, float roughness, out vec3 diffuse_light, out vec3 specular_light) {
|
||||
|
|
@ -579,9 +600,10 @@ void process_gi(ivec2 pos, vec3 vertex, inout vec4 ambient_light, inout vec4 ref
|
|||
if (normal.length() > 0.5) {
|
||||
//valid normal, can do GI
|
||||
float roughness = normal_roughness.w;
|
||||
vertex = mat3(params.cam_rotation) * vertex;
|
||||
normal = normalize(mat3(params.cam_rotation) * normal);
|
||||
vec3 reflection = normalize(reflect(normalize(vertex), normal));
|
||||
vec3 view = -normalize(mat3(scene_data.cam_transform) * (vertex - scene_data.eye_offset[params.view_index].xyz));
|
||||
vertex = mat3(scene_data.cam_transform) * vertex;
|
||||
normal = normalize(mat3(scene_data.cam_transform) * normal);
|
||||
vec3 reflection = normalize(reflect(-view, normal));
|
||||
|
||||
#ifdef USE_SDFGI
|
||||
sdfgi_process(vertex, normal, reflection, roughness, ambient_light, reflection_light);
|
||||
|
|
@ -629,7 +651,7 @@ void main() {
|
|||
#ifdef MODE_HALF_RES
|
||||
pos <<= 1;
|
||||
#endif
|
||||
if (any(greaterThanEqual(pos, params.screen_size))) { //too large, do nothing
|
||||
if (any(greaterThanEqual(pos, scene_data.screen_size))) { //too large, do nothing
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -40,10 +40,13 @@ layout(push_constant, std430) uniform Params {
|
|||
bool use_occlusion;
|
||||
float y_mult;
|
||||
|
||||
vec3 cam_extent;
|
||||
int probe_axis_size;
|
||||
float z_near;
|
||||
float reserved1;
|
||||
float reserved2;
|
||||
|
||||
mat4 cam_transform;
|
||||
mat4 inv_projection;
|
||||
}
|
||||
params;
|
||||
|
||||
|
|
@ -81,8 +84,9 @@ void main() {
|
|||
{
|
||||
ray_pos = params.cam_transform[3].xyz;
|
||||
|
||||
ray_dir.xy = params.cam_extent.xy * ((vec2(screen_pos) / vec2(params.screen_size)) * 2.0 - 1.0);
|
||||
ray_dir.z = params.cam_extent.z;
|
||||
ray_dir.xy = ((vec2(screen_pos) / vec2(params.screen_size)) * 2.0 - 1.0);
|
||||
ray_dir.z = params.z_near;
|
||||
ray_dir = (params.inv_projection * vec4(ray_dir, 1.0)).xyz;
|
||||
|
||||
ray_dir = normalize(mat3(params.cam_transform) * ray_dir);
|
||||
}
|
||||
|
|
@ -2,13 +2,28 @@
|
|||
|
||||
#version 450
|
||||
|
||||
#if defined(USE_MULTIVIEW) && defined(has_VK_KHR_multiview)
|
||||
#extension GL_EXT_multiview : enable
|
||||
#endif
|
||||
|
||||
#ifdef USE_MULTIVIEW
|
||||
#ifdef has_VK_KHR_multiview
|
||||
#define ViewIndex gl_ViewIndex
|
||||
#else // has_VK_KHR_multiview
|
||||
// !BAS! This needs to become an input once we implement our fallback!
|
||||
#define ViewIndex 0
|
||||
#endif // has_VK_KHR_multiview
|
||||
#else // USE_MULTIVIEW
|
||||
// Set to zero, not supported in non stereo
|
||||
#define ViewIndex 0
|
||||
#endif //USE_MULTIVIEW
|
||||
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define MAX_CASCADES 8
|
||||
#define MAX_VIEWS 2
|
||||
|
||||
layout(push_constant, std430) uniform Params {
|
||||
mat4 projection;
|
||||
|
||||
uint band_power;
|
||||
uint sections_in_band;
|
||||
uint band_mask;
|
||||
|
|
@ -68,6 +83,11 @@ cascades;
|
|||
layout(set = 0, binding = 4) uniform texture3D occlusion_texture;
|
||||
layout(set = 0, binding = 3) uniform sampler linear_sampler;
|
||||
|
||||
layout(set = 0, binding = 5, std140) uniform SceneData {
|
||||
mat4 projection[MAX_VIEWS];
|
||||
}
|
||||
scene_data;
|
||||
|
||||
void main() {
|
||||
#ifdef MODE_PROBES
|
||||
probe_index = gl_InstanceIndex;
|
||||
|
|
@ -85,7 +105,7 @@ void main() {
|
|||
|
||||
vertex += (cascades.data[params.cascade].offset + vec3(probe_cell) * probe_cell_size) / vec3(1.0, params.y_mult, 1.0);
|
||||
|
||||
gl_Position = params.projection * vec4(vertex, 1.0);
|
||||
gl_Position = scene_data.projection[ViewIndex] * vec4(vertex, 1.0);
|
||||
#endif
|
||||
|
||||
#ifdef MODE_VISIBILITY
|
||||
|
|
@ -144,7 +164,7 @@ void main() {
|
|||
|
||||
visibility = dot(texelFetch(sampler3D(occlusion_texture, linear_sampler), tex_pos, 0), layer_axis[occlusion_layer]);
|
||||
|
||||
gl_Position = params.projection * vec4(vertex, 1.0);
|
||||
gl_Position = scene_data.projection[ViewIndex] * vec4(vertex, 1.0);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
|
@ -153,16 +173,32 @@ void main() {
|
|||
|
||||
#version 450
|
||||
|
||||
#if defined(USE_MULTIVIEW) && defined(has_VK_KHR_multiview)
|
||||
#extension GL_EXT_multiview : enable
|
||||
#endif
|
||||
|
||||
#ifdef USE_MULTIVIEW
|
||||
#ifdef has_VK_KHR_multiview
|
||||
#define ViewIndex gl_ViewIndex
|
||||
#else // has_VK_KHR_multiview
|
||||
// !BAS! This needs to become an input once we implement our fallback!
|
||||
#define ViewIndex 0
|
||||
#endif // has_VK_KHR_multiview
|
||||
#else // USE_MULTIVIEW
|
||||
// Set to zero, not supported in non stereo
|
||||
#define ViewIndex 0
|
||||
#endif //USE_MULTIVIEW
|
||||
|
||||
#VERSION_DEFINES
|
||||
|
||||
#define MAX_VIEWS 2
|
||||
|
||||
layout(location = 0) out vec4 frag_color;
|
||||
|
||||
layout(set = 0, binding = 2) uniform texture2DArray lightprobe_texture;
|
||||
layout(set = 0, binding = 3) uniform sampler linear_sampler;
|
||||
|
||||
layout(push_constant, std430) uniform Params {
|
||||
mat4 projection;
|
||||
|
||||
uint band_power;
|
||||
uint sections_in_band;
|
||||
uint band_mask;
|
||||
|
|
@ -1238,12 +1238,20 @@ void fragment_shader(in SceneData scene_data) {
|
|||
if (scene_data.gi_upscale_for_msaa) {
|
||||
vec2 base_coord = screen_uv;
|
||||
vec2 closest_coord = base_coord;
|
||||
#ifdef USE_MULTIVIEW
|
||||
float closest_ang = dot(normal, textureLod(sampler2DArray(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(base_coord, ViewIndex), 0.0).xyz * 2.0 - 1.0);
|
||||
#else // USE_MULTIVIEW
|
||||
float closest_ang = dot(normal, textureLod(sampler2D(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), base_coord, 0.0).xyz * 2.0 - 1.0);
|
||||
#endif // USE_MULTIVIEW
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
const vec2 neighbours[4] = vec2[](vec2(-1, 0), vec2(1, 0), vec2(0, -1), vec2(0, 1));
|
||||
vec2 neighbour_coord = base_coord + neighbours[i] * scene_data.screen_pixel_size;
|
||||
#ifdef USE_MULTIVIEW
|
||||
float neighbour_ang = dot(normal, textureLod(sampler2DArray(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(neighbour_coord, ViewIndex), 0.0).xyz * 2.0 - 1.0);
|
||||
#else // USE_MULTIVIEW
|
||||
float neighbour_ang = dot(normal, textureLod(sampler2D(normal_roughness_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), neighbour_coord, 0.0).xyz * 2.0 - 1.0);
|
||||
#endif // USE_MULTIVIEW
|
||||
if (neighbour_ang > closest_ang) {
|
||||
closest_ang = neighbour_ang;
|
||||
closest_coord = neighbour_coord;
|
||||
|
|
@ -1256,8 +1264,13 @@ void fragment_shader(in SceneData scene_data) {
|
|||
coord = screen_uv;
|
||||
}
|
||||
|
||||
#ifdef USE_MULTIVIEW
|
||||
vec4 buffer_ambient = textureLod(sampler2DArray(ambient_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(coord, ViewIndex), 0.0);
|
||||
vec4 buffer_reflection = textureLod(sampler2DArray(reflection_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), vec3(coord, ViewIndex), 0.0);
|
||||
#else // USE_MULTIVIEW
|
||||
vec4 buffer_ambient = textureLod(sampler2D(ambient_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), coord, 0.0);
|
||||
vec4 buffer_reflection = textureLod(sampler2D(reflection_buffer, material_samplers[SAMPLER_LINEAR_CLAMP]), coord, 0.0);
|
||||
#endif // USE_MULTIVIEW
|
||||
|
||||
ambient_light = mix(ambient_light, buffer_ambient.rgb, buffer_ambient.a);
|
||||
specular_light = mix(specular_light, buffer_reflection.rgb, buffer_reflection.a);
|
||||
|
|
|
|||
|
|
@ -317,10 +317,16 @@ layout(r32ui, set = 1, binding = 12) uniform restrict uimage3D geom_facing_grid;
|
|||
layout(set = 1, binding = 9) uniform texture2D depth_buffer;
|
||||
layout(set = 1, binding = 10) uniform texture2D color_buffer;
|
||||
|
||||
#ifdef USE_MULTIVIEW
|
||||
layout(set = 1, binding = 11) uniform texture2DArray normal_roughness_buffer;
|
||||
layout(set = 1, binding = 13) uniform texture2DArray ambient_buffer;
|
||||
layout(set = 1, binding = 14) uniform texture2DArray reflection_buffer;
|
||||
#else // USE_MULTIVIEW
|
||||
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;
|
||||
#endif
|
||||
layout(set = 1, binding = 12) uniform texture2D ao_buffer;
|
||||
layout(set = 1, binding = 15) uniform texture2DArray sdfgi_lightprobe_texture;
|
||||
layout(set = 1, binding = 16) uniform texture3D sdfgi_occlusion_cascades;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue