Merge pull request #78499 from BastiaanOlij/fix_stereo_decals

Apply reprojection in multiview for our cluster lookup
This commit is contained in:
Rémi Verschelde 2023-06-21 21:51:52 +02:00
commit 1e44b47970
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 14 additions and 2 deletions

View File

@ -1451,6 +1451,11 @@ void RenderForwardClustered::_pre_opaque_render(RenderDataRD *p_render_data, boo
RD::get_singleton()->barrier(RD::BARRIER_MASK_ALL_BARRIERS, RD::BARRIER_MASK_ALL_BARRIERS); RD::get_singleton()->barrier(RD::BARRIER_MASK_ALL_BARRIERS, RD::BARRIER_MASK_ALL_BARRIERS);
if (current_cluster_builder) { if (current_cluster_builder) {
// Note: when rendering stereoscopic (multiview) we are using our combined frustum projection to create
// our cluster data. We use reprojection in the shader to adjust for our left/right eye.
// This only works as we don't filter our cluster by depth buffer.
// If we ever make this optimisation we should make it optional and only use it in mono.
// What we win by filtering out a few lights, we loose by having to do the work double for stereo.
current_cluster_builder->begin(p_render_data->scene_data->cam_transform, p_render_data->scene_data->cam_projection, !p_render_data->reflection_probe.is_valid()); current_cluster_builder->begin(p_render_data->scene_data->cam_transform, p_render_data->scene_data->cam_projection, !p_render_data->reflection_probe.is_valid());
} }

View File

@ -735,6 +735,10 @@ void fragment_shader(in SceneData scene_data) {
#ifdef USE_MULTIVIEW #ifdef USE_MULTIVIEW
vec3 eye_offset = scene_data.eye_offset[ViewIndex].xyz; vec3 eye_offset = scene_data.eye_offset[ViewIndex].xyz;
vec3 view = -normalize(vertex_interp - eye_offset); vec3 view = -normalize(vertex_interp - eye_offset);
// UV in our combined frustum space is used for certain screen uv processes where it's
// overkill to render separate left and right eye views
vec2 combined_uv = (combined_projected.xy / combined_projected.w) * 0.5 + 0.5;
#else #else
vec3 eye_offset = vec3(0.0, 0.0, 0.0); vec3 eye_offset = vec3(0.0, 0.0, 0.0);
vec3 view = -normalize(vertex_interp); vec3 view = -normalize(vertex_interp);
@ -921,8 +925,7 @@ void fragment_shader(in SceneData scene_data) {
if (implementation_data.volumetric_fog_enabled) { if (implementation_data.volumetric_fog_enabled) {
#ifdef USE_MULTIVIEW #ifdef USE_MULTIVIEW
vec2 center_uv = (combined_projected.xy / combined_projected.w) * 0.5 + 0.5; vec4 volumetric_fog = volumetric_fog_process(combined_uv, -vertex.z);
vec4 volumetric_fog = volumetric_fog_process(center_uv, -vertex.z);
#else #else
vec4 volumetric_fog = volumetric_fog_process(screen_uv, -vertex.z); vec4 volumetric_fog = volumetric_fog_process(screen_uv, -vertex.z);
#endif #endif
@ -952,7 +955,11 @@ void fragment_shader(in SceneData scene_data) {
#ifndef MODE_RENDER_DEPTH #ifndef MODE_RENDER_DEPTH
#ifdef USE_MULTIVIEW
uvec2 cluster_pos = uvec2(combined_uv.xy / scene_data.screen_pixel_size) >> implementation_data.cluster_shift;
#else
uvec2 cluster_pos = uvec2(gl_FragCoord.xy) >> implementation_data.cluster_shift; uvec2 cluster_pos = uvec2(gl_FragCoord.xy) >> implementation_data.cluster_shift;
#endif
uint cluster_offset = (implementation_data.cluster_width * cluster_pos.y + cluster_pos.x) * (implementation_data.max_cluster_element_count_div_32 + 32); uint cluster_offset = (implementation_data.cluster_width * cluster_pos.y + cluster_pos.x) * (implementation_data.max_cluster_element_count_div_32 + 32);
uint cluster_z = uint(clamp((-vertex.z / scene_data.z_far) * 32.0, 0.0, 31.0)); uint cluster_z = uint(clamp((-vertex.z / scene_data.z_far) * 32.0, 0.0, 31.0));