mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 19:42:43 +00:00
Merge pull request #93630 from BastiaanOlij/scene_data_projection_correction
Make RenderSceneData take projection correction into account
This commit is contained in:
commit
6f9c0aa40d
@ -587,7 +587,7 @@ void RenderForwardClustered::_render_list_with_draw_list(RenderListParameters *p
|
||||
RD::get_singleton()->draw_list_end();
|
||||
}
|
||||
|
||||
void RenderForwardClustered::_setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier, bool p_pancake_shadows, int p_index) {
|
||||
void RenderForwardClustered::_setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, const Color &p_default_bg_color, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier, bool p_pancake_shadows, int p_index) {
|
||||
RendererRD::LightStorage *light_storage = RendererRD::LightStorage::get_singleton();
|
||||
|
||||
Ref<RenderSceneBuffersRD> rd = p_render_data->render_buffers;
|
||||
@ -603,7 +603,7 @@ void RenderForwardClustered::_setup_environment(const RenderDataRD *p_render_dat
|
||||
}
|
||||
}
|
||||
|
||||
p_render_data->scene_data->update_ubo(scene_state.uniform_buffers[p_index], get_debug_draw_mode(), env, reflection_probe_instance, p_render_data->camera_attributes, p_flip_y, p_pancake_shadows, p_screen_size, p_default_bg_color, _render_buffers_get_luminance_multiplier(), p_opaque_render_buffers, p_apply_alpha_multiplier);
|
||||
p_render_data->scene_data->update_ubo(scene_state.uniform_buffers[p_index], get_debug_draw_mode(), env, reflection_probe_instance, p_render_data->camera_attributes, p_pancake_shadows, p_screen_size, p_default_bg_color, _render_buffers_get_luminance_multiplier(), p_opaque_render_buffers, p_apply_alpha_multiplier);
|
||||
|
||||
// now do implementation UBO
|
||||
|
||||
@ -1732,7 +1732,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
|
||||
|
||||
_setup_lightmaps(p_render_data, *p_render_data->lightmaps, p_render_data->scene_data->cam_transform);
|
||||
_setup_voxelgis(*p_render_data->voxel_gi_instances);
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, !is_reflection_probe, p_default_bg_color, false);
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, p_default_bg_color, false);
|
||||
|
||||
// May have changed due to the above (light buffer enlarged, as an example).
|
||||
_update_render_base_uniform_set();
|
||||
@ -1995,7 +1995,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
|
||||
// Shadow pass can change the base uniform set samplers.
|
||||
_update_render_base_uniform_set();
|
||||
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, !is_reflection_probe, p_default_bg_color, true, using_motion_pass);
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, p_default_bg_color, true, using_motion_pass);
|
||||
|
||||
RID rp_uniform_set = _setup_render_pass_uniform_set(RENDER_LIST_OPAQUE, p_render_data, radiance_texture, samplers, true);
|
||||
|
||||
@ -2209,7 +2209,7 @@ void RenderForwardClustered::_render_scene(RenderDataRD *p_render_data, const Co
|
||||
|
||||
rp_uniform_set = _setup_render_pass_uniform_set(RENDER_LIST_ALPHA, p_render_data, radiance_texture, samplers, true);
|
||||
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, !is_reflection_probe, p_default_bg_color, false);
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, p_default_bg_color, false);
|
||||
|
||||
{
|
||||
uint32_t transparent_color_pass_flags = (color_pass_flags | COLOR_PASS_FLAG_TRANSPARENT) & ~(COLOR_PASS_FLAG_SEPARATE_SPECULAR);
|
||||
@ -2562,6 +2562,7 @@ void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const Page
|
||||
SceneState::ShadowPass shadow_pass;
|
||||
|
||||
RenderSceneDataRD scene_data;
|
||||
scene_data.flip_y = !p_flip_y; // Q: Why is this inverted? Do we assume flip in shadow logic?
|
||||
scene_data.cam_projection = p_projection;
|
||||
scene_data.cam_transform = p_transform;
|
||||
scene_data.view_projection[0] = p_projection;
|
||||
@ -2581,7 +2582,7 @@ void RenderForwardClustered::_render_shadow_append(RID p_framebuffer, const Page
|
||||
render_data.instances = &p_instances;
|
||||
render_data.render_info = p_render_info;
|
||||
|
||||
_setup_environment(&render_data, true, p_viewport_size, !p_flip_y, Color(), false, false, p_use_pancake, shadow_pass_index);
|
||||
_setup_environment(&render_data, true, p_viewport_size, Color(), false, false, p_use_pancake, shadow_pass_index);
|
||||
|
||||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_DISABLE_LOD) {
|
||||
scene_data.screen_mesh_lod_threshold = 0.0;
|
||||
@ -2654,6 +2655,7 @@ void RenderForwardClustered::_render_particle_collider_heightfield(RID p_fb, con
|
||||
RD::get_singleton()->draw_command_begin_label("Render Collider Heightfield");
|
||||
|
||||
RenderSceneDataRD scene_data;
|
||||
scene_data.flip_y = true;
|
||||
scene_data.cam_projection = p_cam_projection;
|
||||
scene_data.cam_transform = p_cam_transform;
|
||||
scene_data.view_projection[0] = p_cam_projection;
|
||||
@ -2673,7 +2675,7 @@ void RenderForwardClustered::_render_particle_collider_heightfield(RID p_fb, con
|
||||
|
||||
_update_render_base_uniform_set();
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), true, Color(), false, false, false);
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color(), false, false, false);
|
||||
|
||||
PassMode pass_mode = PASS_MODE_SHADOW;
|
||||
|
||||
@ -2720,7 +2722,7 @@ void RenderForwardClustered::_render_material(const Transform3D &p_cam_transform
|
||||
|
||||
_update_render_base_uniform_set();
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), false, Color());
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color());
|
||||
|
||||
PassMode pass_mode = PASS_MODE_DEPTH_MATERIAL;
|
||||
_fill_render_list(RENDER_LIST_SECONDARY, &render_data, pass_mode);
|
||||
@ -2771,7 +2773,7 @@ void RenderForwardClustered::_render_uv2(const PagedArray<RenderGeometryInstance
|
||||
|
||||
_update_render_base_uniform_set();
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), false, Color());
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color());
|
||||
|
||||
PassMode pass_mode = PASS_MODE_DEPTH_MATERIAL;
|
||||
_fill_render_list(RENDER_LIST_SECONDARY, &render_data, pass_mode);
|
||||
@ -2887,7 +2889,7 @@ void RenderForwardClustered::_render_sdfgi(Ref<RenderSceneBuffersRD> p_render_bu
|
||||
RendererRD::MaterialStorage::store_transform(to_bounds.affine_inverse() * scene_data.cam_transform, scene_state.ubo.sdf_to_bounds);
|
||||
|
||||
scene_data.emissive_exposure_normalization = p_exposure_normalization;
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), false, Color());
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color());
|
||||
|
||||
RID rp_uniform_set = _setup_sdfgi_render_pass_uniform_set(p_albedo_texture, p_emission_texture, p_emission_aniso_texture, p_geom_facing_texture, RendererRD::MaterialStorage::get_singleton()->samplers_rd_get_default());
|
||||
|
||||
|
@ -361,7 +361,7 @@ class RenderForwardClustered : public RendererSceneRenderRD {
|
||||
|
||||
static RenderForwardClustered *singleton;
|
||||
|
||||
void _setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_opaque_render_buffers = false, bool p_apply_alpha_multiplier = false, bool p_pancake_shadows = false, int p_index = 0);
|
||||
void _setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, const Color &p_default_bg_color, bool p_opaque_render_buffers = false, bool p_apply_alpha_multiplier = false, bool p_pancake_shadows = false, int p_index = 0);
|
||||
void _setup_voxelgis(const PagedArray<RID> &p_voxelgis);
|
||||
void _setup_lightmaps(const RenderDataRD *p_render_data, const PagedArray<RID> &p_lightmaps, const Transform3D &p_cam_transform);
|
||||
|
||||
|
@ -804,7 +804,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color
|
||||
RD::get_singleton()->draw_command_begin_label("Render Setup");
|
||||
|
||||
_setup_lightmaps(p_render_data, *p_render_data->lightmaps, p_render_data->scene_data->cam_transform);
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, !is_reflection_probe, p_default_bg_color, false);
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, p_default_bg_color, false);
|
||||
|
||||
// May have changed due to the above (light buffer enlarged, as an example).
|
||||
_update_render_base_uniform_set();
|
||||
@ -953,7 +953,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color
|
||||
// Shadow pass can change the base uniform set samplers.
|
||||
_update_render_base_uniform_set();
|
||||
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, !is_reflection_probe, p_default_bg_color, p_render_data->render_buffers.is_valid());
|
||||
_setup_environment(p_render_data, is_reflection_probe, screen_size, p_default_bg_color, p_render_data->render_buffers.is_valid());
|
||||
|
||||
if (merge_transparent_pass && using_subpass_post_process) {
|
||||
RENDER_TIMESTAMP("Render Opaque + Transparent + Tonemap");
|
||||
@ -1075,7 +1075,7 @@ void RenderForwardMobile::_render_scene(RenderDataRD *p_render_data, const Color
|
||||
rp_uniform_set = _setup_render_pass_uniform_set(RENDER_LIST_ALPHA, p_render_data, radiance_texture, samplers, true);
|
||||
|
||||
// this may be needed if we re-introduced steps that change info, not sure which do so in the previous implementation
|
||||
//_setup_environment(p_render_data, is_reflection_probe, screen_size, !is_reflection_probe, p_default_bg_color, false);
|
||||
//_setup_environment(p_render_data, is_reflection_probe, screen_size, p_default_bg_color, false);
|
||||
|
||||
RenderListParameters render_list_params(render_list[RENDER_LIST_ALPHA].elements.ptr(), render_list[RENDER_LIST_ALPHA].element_info.ptr(), render_list[RENDER_LIST_ALPHA].elements.size(), reverse_cull, PASS_MODE_COLOR, rp_uniform_set, spec_constant_base_flags, get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_WIREFRAME, Vector2(), p_render_data->scene_data->lod_distance_multiplier, p_render_data->scene_data->screen_mesh_lod_threshold, p_render_data->scene_data->view_count);
|
||||
render_list_params.framebuffer_format = fb_format;
|
||||
@ -1310,6 +1310,7 @@ void RenderForwardMobile::_render_shadow_append(RID p_framebuffer, const PagedAr
|
||||
}
|
||||
|
||||
RenderSceneDataRD scene_data;
|
||||
scene_data.flip_y = !p_flip_y; // Q: Why is this inverted? Do we assume flip in shadow logic?
|
||||
scene_data.cam_projection = p_projection;
|
||||
scene_data.cam_transform = p_transform;
|
||||
scene_data.view_projection[0] = p_projection;
|
||||
@ -1327,7 +1328,7 @@ void RenderForwardMobile::_render_shadow_append(RID p_framebuffer, const PagedAr
|
||||
render_data.instances = &p_instances;
|
||||
render_data.render_info = p_render_info;
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), !p_flip_y, Color(), false, p_use_pancake, shadow_pass_index);
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color(), false, p_use_pancake, shadow_pass_index);
|
||||
|
||||
if (get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_DISABLE_LOD) {
|
||||
scene_data.screen_mesh_lod_threshold = 0.0;
|
||||
@ -1415,7 +1416,7 @@ void RenderForwardMobile::_render_material(const Transform3D &p_cam_transform, c
|
||||
render_data.scene_data = &scene_data;
|
||||
render_data.instances = &p_instances;
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), false, Color());
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color());
|
||||
|
||||
PassMode pass_mode = PASS_MODE_DEPTH_MATERIAL;
|
||||
_fill_render_list(RENDER_LIST_SECONDARY, &render_data, pass_mode);
|
||||
@ -1460,7 +1461,7 @@ void RenderForwardMobile::_render_uv2(const PagedArray<RenderGeometryInstance *>
|
||||
render_data.scene_data = &scene_data;
|
||||
render_data.instances = &p_instances;
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), false, Color());
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color());
|
||||
|
||||
PassMode pass_mode = PASS_MODE_DEPTH_MATERIAL;
|
||||
_fill_render_list(RENDER_LIST_SECONDARY, &render_data, pass_mode);
|
||||
@ -1526,6 +1527,7 @@ void RenderForwardMobile::_render_particle_collider_heightfield(RID p_fb, const
|
||||
_update_render_base_uniform_set();
|
||||
|
||||
RenderSceneDataRD scene_data;
|
||||
scene_data.flip_y = true;
|
||||
scene_data.cam_projection = p_cam_projection;
|
||||
scene_data.cam_transform = p_cam_transform;
|
||||
scene_data.view_projection[0] = p_cam_projection;
|
||||
@ -1541,7 +1543,7 @@ void RenderForwardMobile::_render_particle_collider_heightfield(RID p_fb, const
|
||||
render_data.scene_data = &scene_data;
|
||||
render_data.instances = &p_instances;
|
||||
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), true, Color(), false, false);
|
||||
_setup_environment(&render_data, true, Vector2(1, 1), Color(), false, false);
|
||||
|
||||
PassMode pass_mode = PASS_MODE_SHADOW;
|
||||
|
||||
@ -1974,7 +1976,7 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const
|
||||
}
|
||||
}
|
||||
|
||||
void RenderForwardMobile::_setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_opaque_render_buffers, bool p_pancake_shadows, int p_index) {
|
||||
void RenderForwardMobile::_setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, const Color &p_default_bg_color, bool p_opaque_render_buffers, bool p_pancake_shadows, int p_index) {
|
||||
RID env = is_environment(p_render_data->environment) ? p_render_data->environment : RID();
|
||||
RID reflection_probe_instance = p_render_data->reflection_probe.is_valid() ? RendererRD::LightStorage::get_singleton()->reflection_probe_instance_get_probe(p_render_data->reflection_probe) : RID();
|
||||
|
||||
@ -1987,7 +1989,7 @@ void RenderForwardMobile::_setup_environment(const RenderDataRD *p_render_data,
|
||||
}
|
||||
}
|
||||
|
||||
p_render_data->scene_data->update_ubo(scene_state.uniform_buffers[p_index], get_debug_draw_mode(), env, reflection_probe_instance, p_render_data->camera_attributes, p_flip_y, p_pancake_shadows, p_screen_size, p_default_bg_color, _render_buffers_get_luminance_multiplier(), p_opaque_render_buffers, false);
|
||||
p_render_data->scene_data->update_ubo(scene_state.uniform_buffers[p_index], get_debug_draw_mode(), env, reflection_probe_instance, p_render_data->camera_attributes, p_pancake_shadows, p_screen_size, p_default_bg_color, _render_buffers_get_luminance_multiplier(), p_opaque_render_buffers, false);
|
||||
}
|
||||
|
||||
/// RENDERING ///
|
||||
|
@ -197,7 +197,7 @@ private:
|
||||
void _fill_instance_data(RenderListType p_render_list, uint32_t p_offset = 0, int32_t p_max_elements = -1, bool p_update_buffer = true);
|
||||
void _fill_render_list(RenderListType p_render_list, const RenderDataRD *p_render_data, PassMode p_pass_mode, bool p_append = false);
|
||||
|
||||
void _setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, bool p_flip_y, const Color &p_default_bg_color, bool p_opaque_render_buffers = false, bool p_pancake_shadows = false, int p_index = 0);
|
||||
void _setup_environment(const RenderDataRD *p_render_data, bool p_no_fog, const Size2i &p_screen_size, const Color &p_default_bg_color, bool p_opaque_render_buffers = false, bool p_pancake_shadows = false, int p_index = 0);
|
||||
void _setup_lightmaps(const RenderDataRD *p_render_data, const PagedArray<RID> &p_lightmaps, const Transform3D &p_cam_transform);
|
||||
|
||||
RID render_base_uniform_set;
|
||||
|
@ -1124,6 +1124,7 @@ void RendererSceneRenderRD::render_scene(const Ref<RenderSceneBuffers> &p_render
|
||||
scene_data.camera_visible_layers = p_camera_data->visible_layers;
|
||||
scene_data.taa_jitter = p_camera_data->taa_jitter;
|
||||
scene_data.main_cam_transform = p_camera_data->main_transform;
|
||||
scene_data.flip_y = !p_reflection_probe.is_valid();
|
||||
|
||||
scene_data.view_count = p_camera_data->view_count;
|
||||
for (uint32_t v = 0; v < p_camera_data->view_count; v++) {
|
||||
|
@ -42,7 +42,11 @@ Transform3D RenderSceneDataRD::get_cam_transform() const {
|
||||
}
|
||||
|
||||
Projection RenderSceneDataRD::get_cam_projection() const {
|
||||
return cam_projection;
|
||||
Projection correction;
|
||||
correction.set_depth_correction(flip_y);
|
||||
correction.add_jitter_offset(taa_jitter);
|
||||
|
||||
return correction * cam_projection;
|
||||
}
|
||||
|
||||
uint32_t RenderSceneDataRD::get_view_count() const {
|
||||
@ -58,14 +62,18 @@ Vector3 RenderSceneDataRD::get_view_eye_offset(uint32_t p_view) const {
|
||||
Projection RenderSceneDataRD::get_view_projection(uint32_t p_view) const {
|
||||
ERR_FAIL_UNSIGNED_INDEX_V(p_view, view_count, Projection());
|
||||
|
||||
return view_projection[p_view];
|
||||
Projection correction;
|
||||
correction.set_depth_correction(flip_y);
|
||||
correction.add_jitter_offset(taa_jitter);
|
||||
|
||||
return correction * view_projection[p_view];
|
||||
}
|
||||
|
||||
RID RenderSceneDataRD::create_uniform_buffer() {
|
||||
return RD::get_singleton()->uniform_buffer_create(sizeof(UBODATA));
|
||||
}
|
||||
|
||||
void RenderSceneDataRD::update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p_debug_mode, RID p_env, RID p_reflection_probe_instance, RID p_camera_attributes, bool p_flip_y, bool p_pancake_shadows, const Size2i &p_screen_size, const Color &p_default_bg_color, float p_luminance_multiplier, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier) {
|
||||
void RenderSceneDataRD::update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p_debug_mode, RID p_env, RID p_reflection_probe_instance, RID p_camera_attributes, bool p_pancake_shadows, const Size2i &p_screen_size, const Color &p_default_bg_color, float p_luminance_multiplier, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier) {
|
||||
RendererSceneRenderRD *render_scene_render = RendererSceneRenderRD::get_singleton();
|
||||
|
||||
UBODATA ubo_data;
|
||||
@ -76,7 +84,7 @@ void RenderSceneDataRD::update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p
|
||||
UBO &prev_ubo = ubo_data.prev_ubo;
|
||||
|
||||
Projection correction;
|
||||
correction.set_depth_correction(p_flip_y);
|
||||
correction.set_depth_correction(flip_y);
|
||||
correction.add_jitter_offset(taa_jitter);
|
||||
Projection projection = correction * cam_projection;
|
||||
|
||||
|
@ -50,6 +50,7 @@ public:
|
||||
Vector2 taa_jitter;
|
||||
uint32_t camera_visible_layers;
|
||||
bool cam_orthogonal = false;
|
||||
bool flip_y = false;
|
||||
|
||||
// For billboards to cast correct shadows.
|
||||
Transform3D main_cam_transform;
|
||||
@ -90,7 +91,7 @@ public:
|
||||
virtual Projection get_view_projection(uint32_t p_view) const override;
|
||||
|
||||
RID create_uniform_buffer();
|
||||
void update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p_debug_mode, RID p_env, RID p_reflection_probe_instance, RID p_camera_attributes, bool p_flip_y, bool p_pancake_shadows, const Size2i &p_screen_size, const Color &p_default_bg_color, float p_luminance_multiplier, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier);
|
||||
void update_ubo(RID p_uniform_buffer, RS::ViewportDebugDraw p_debug_mode, RID p_env, RID p_reflection_probe_instance, RID p_camera_attributes, bool p_pancake_shadows, const Size2i &p_screen_size, const Color &p_default_bg_color, float p_luminance_multiplier, bool p_opaque_render_buffers, bool p_apply_alpha_multiplier);
|
||||
virtual RID get_uniform_buffer() const override;
|
||||
|
||||
private:
|
||||
|
Loading…
Reference in New Issue
Block a user