From 1270b542bb8746c881e0257e211a4bd86f22171c Mon Sep 17 00:00:00 2001 From: Joan Fons Date: Wed, 13 Apr 2022 17:31:40 +0200 Subject: Fix depth pre-pass on all face cull modes The default shadow material was used for depth rendering disregarding the cull mode of the original material. This commit adds a check so the default shadow material is only used when the original material has back-face culling. --- .../forward_clustered/render_forward_clustered.cpp | 2 +- .../forward_clustered/scene_shader_forward_clustered.cpp | 11 ++++++----- .../forward_clustered/scene_shader_forward_clustered.h | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp index 365bef896f..fba6d19945 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -2662,7 +2662,7 @@ void RenderForwardClustered::_geometry_instance_add_surface_with_material(Geomet SceneShaderForwardClustered::MaterialData *material_shadow = nullptr; void *surface_shadow = nullptr; - if (!p_material->shader_data->uses_particle_trails && !p_material->shader_data->writes_modelview_or_projection && !p_material->shader_data->uses_vertex && !p_material->shader_data->uses_position && !p_material->shader_data->uses_discard && !p_material->shader_data->uses_depth_pre_pass && !p_material->shader_data->uses_alpha_clip) { + if (!p_material->shader_data->uses_particle_trails && !p_material->shader_data->writes_modelview_or_projection && !p_material->shader_data->uses_vertex && !p_material->shader_data->uses_position && !p_material->shader_data->uses_discard && !p_material->shader_data->uses_depth_pre_pass && !p_material->shader_data->uses_alpha_clip && p_material->shader_data->cull_mode == SceneShaderForwardClustered::ShaderData::CULL_BACK) { flags |= GeometryInstanceSurfaceDataCache::FLAG_USES_SHARED_SHADOW_MATERIAL; material_shadow = static_cast(RendererRD::MaterialStorage::get_singleton()->material_get_data(scene_shader.default_material, RendererRD::SHADER_TYPE_3D)); diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp index 99a7fe6280..0280eb3077 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.cpp @@ -55,7 +55,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { int blend_mode = BLEND_MODE_MIX; int depth_testi = DEPTH_TEST_ENABLED; int alpha_antialiasing_mode = ALPHA_ANTIALIASING_OFF; - int cull = CULL_BACK; + int cull_modei = CULL_BACK; uses_point_size = false; uses_alpha = false; @@ -101,9 +101,9 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { actions.render_mode_values["depth_test_disabled"] = Pair(&depth_testi, DEPTH_TEST_DISABLED); - actions.render_mode_values["cull_disabled"] = Pair(&cull, CULL_DISABLED); - actions.render_mode_values["cull_front"] = Pair(&cull, CULL_FRONT); - actions.render_mode_values["cull_back"] = Pair(&cull, CULL_BACK); + actions.render_mode_values["cull_disabled"] = Pair(&cull_modei, CULL_DISABLED); + actions.render_mode_values["cull_front"] = Pair(&cull_modei, CULL_FRONT); + actions.render_mode_values["cull_back"] = Pair(&cull_modei, CULL_BACK); actions.render_mode_flags["unshaded"] = &unshaded; actions.render_mode_flags["wireframe"] = &wireframe; @@ -145,6 +145,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { depth_draw = DepthDraw(depth_drawi); depth_test = DepthTest(depth_testi); + cull_mode = Cull(cull_modei); #if 0 print_line("**compiling shader:"); @@ -258,7 +259,7 @@ void SceneShaderForwardClustered::ShaderData::set_code(const String &p_code) { { RD::POLYGON_CULL_DISABLED, RD::POLYGON_CULL_DISABLED, RD::POLYGON_CULL_DISABLED } }; - RD::PolygonCullMode cull_mode_rd = cull_mode_rd_table[i][cull]; + RD::PolygonCullMode cull_mode_rd = cull_mode_rd_table[i][cull_mode]; for (int j = 0; j < RS::PRIMITIVE_MAX; j++) { RD::RenderPrimitive primitive_rd_table[RS::PRIMITIVE_MAX] = { diff --git a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h index 1b7709bedb..6185fa7413 100644 --- a/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h +++ b/servers/rendering/renderer_rd/forward_clustered/scene_shader_forward_clustered.h @@ -171,6 +171,7 @@ public: bool uses_time; bool writes_modelview_or_projection; bool uses_world_coordinates; + Cull cull_mode; uint64_t last_pass = 0; uint32_t index = 0; -- cgit v1.2.3