diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-07-03 20:18:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-03 20:18:50 +0200 |
commit | d4e081bfe3f371aa825327e03c5373ffea578cb8 (patch) | |
tree | f0edd50a5dca194630bcfa6f984597b9ae89c33e /servers | |
parent | 435a853bc9a27da1b6fc40ca2b2685498cba1fad (diff) | |
parent | fe17a6c907b8e49ab88af80951dc31fad5634a49 (diff) |
Merge pull request #50133 from reduz/fix-render-debug-modes
Fix render debug modes.
Diffstat (limited to 'servers')
6 files changed, 66 insertions, 31 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 2c913ca295..3ab2f0eed2 100644 --- a/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp +++ b/servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp @@ -345,8 +345,20 @@ void RenderForwardClustered::_render_list_template(RenderingDevice::DrawListID p mesh_surface = surf->surface_shadow; } else { - material_uniform_set = surf->material_uniform_set; - shader = surf->shader; +#ifdef DEBUG_ENABLED + if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_LIGHTING)) { + material_uniform_set = scene_shader.default_material_uniform_set; + shader = scene_shader.default_material_shader_ptr; + } else if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) { + material_uniform_set = scene_shader.overdraw_material_uniform_set; + shader = scene_shader.overdraw_material_shader_ptr; + } else { +#endif + material_uniform_set = surf->material_uniform_set; + shader = surf->shader; +#ifdef DEBUG_ENABLED + } +#endif mesh_surface = surf->surface; } @@ -1048,10 +1060,15 @@ void RenderForwardClustered::_fill_render_list(RenderListType p_render_list, con // ADD Element if (p_pass_mode == PASS_MODE_COLOR) { - if (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE)) { +#ifdef DEBUG_ENABLED + bool force_alpha = unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW); +#else + bool force_alpha = false; +#endif + if (!force_alpha && (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE))) { rl->add_element(surf); } - if (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA) { + if (force_alpha || (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA)) { render_list[RENDER_LIST_ALPHA].add_element(surf); if (uses_gi) { surf->sort.uses_forward_gi = 1; 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 f125931df8..3270e30ded 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 @@ -546,11 +546,9 @@ SceneShaderForwardClustered::~SceneShaderForwardClustered() { RD::get_singleton()->free(default_vec4_xform_buffer); RD::get_singleton()->free(shadow_sampler); - storage->free(wireframe_material_shader); storage->free(overdraw_material_shader); storage->free(default_shader); - storage->free(wireframe_material); storage->free(overdraw_material); storage->free(default_material); } @@ -775,6 +773,9 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin MaterialData *md = (MaterialData *)storage->material_get_data(default_material, RendererStorageRD::SHADER_TYPE_3D); default_shader_rd = shader.version_get_shader(md->shader_data->version, SHADER_VERSION_COLOR_PASS); default_shader_sdfgi_rd = shader.version_get_shader(md->shader_data->version, SHADER_VERSION_DEPTH_PASS_WITH_SDF); + + default_material_shader_ptr = md->shader_data; + default_material_uniform_set = md->uniform_set; } { @@ -785,12 +786,9 @@ void SceneShaderForwardClustered::init(RendererStorageRD *p_storage, const Strin storage->material_initialize(overdraw_material); storage->material_set_shader(overdraw_material, overdraw_material_shader); - wireframe_material_shader = storage->shader_allocate(); - storage->shader_initialize(wireframe_material_shader); - storage->shader_set_code(wireframe_material_shader, "shader_type spatial;\nrender_mode wireframe,unshaded;\n void fragment() { ALBEDO=vec3(0.0,0.0,0.0); }"); - wireframe_material = storage->material_allocate(); - storage->material_initialize(wireframe_material); - storage->material_set_shader(wireframe_material, wireframe_material_shader); + MaterialData *md = (MaterialData *)storage->material_get_data(overdraw_material, RendererStorageRD::SHADER_TYPE_3D); + overdraw_material_shader_ptr = md->shader_data; + overdraw_material_uniform_set = md->uniform_set; } { 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 8add9f8095..6d7cef68c6 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 @@ -192,8 +192,6 @@ public: RID default_material; RID overdraw_material_shader; RID overdraw_material; - RID wireframe_material_shader; - RID wireframe_material; RID default_shader_rd; RID default_shader_sdfgi_rd; @@ -202,6 +200,12 @@ public: RID shadow_sampler; + RID default_material_uniform_set; + ShaderData *default_material_shader_ptr = nullptr; + + RID overdraw_material_uniform_set; + ShaderData *overdraw_material_shader_ptr = nullptr; + SceneShaderForwardClustered(); ~SceneShaderForwardClustered(); diff --git a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp index 10dce7ff0f..e7521e6bef 100644 --- a/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.cpp @@ -1078,14 +1078,16 @@ void RenderForwardMobile::_fill_render_list(RenderListType p_render_list, const // ADD Element if (p_pass_mode == PASS_MODE_COLOR) { - if (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE)) { +#ifdef DEBUG_ENABLED + bool force_alpha = unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW); +#else + bool force_alpha = false; +#endif + if (!force_alpha && (surf->flags & (GeometryInstanceSurfaceDataCache::FLAG_PASS_DEPTH | GeometryInstanceSurfaceDataCache::FLAG_PASS_OPAQUE))) { rl->add_element(surf); } - if (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA) { + if (force_alpha || (surf->flags & GeometryInstanceSurfaceDataCache::FLAG_PASS_ALPHA)) { render_list[RENDER_LIST_ALPHA].add_element(surf); - // if (uses_gi) { - // surf->sort.uses_forward_gi = 1; - // } } if (uses_lightmap) { @@ -1451,8 +1453,20 @@ void RenderForwardMobile::_render_list_template(RenderingDevice::DrawListID p_dr mesh_surface = surf->surface_shadow; } else { - material_uniform_set = surf->material_uniform_set; - shader = surf->shader; +#ifdef DEBUG_ENABLED + if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_LIGHTING)) { + material_uniform_set = scene_shader.default_material_uniform_set; + shader = scene_shader.default_material_shader_ptr; + } else if (unlikely(get_debug_draw_mode() == RS::VIEWPORT_DEBUG_DRAW_OVERDRAW)) { + material_uniform_set = scene_shader.overdraw_material_uniform_set; + shader = scene_shader.overdraw_material_shader_ptr; + } else { +#endif + material_uniform_set = surf->material_uniform_set; + shader = surf->shader; +#ifdef DEBUG_ENABLED + } +#endif mesh_surface = surf->surface; } diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp index b5fb9fbc62..187bdf14e3 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.cpp @@ -759,6 +759,9 @@ void SceneShaderForwardMobile::init(RendererStorageRD *p_storage, const String p MaterialData *md = (MaterialData *)storage->material_get_data(default_material, RendererStorageRD::SHADER_TYPE_3D); default_shader_rd = shader.version_get_shader(md->shader_data->version, SHADER_VERSION_COLOR_PASS); + + default_material_shader_ptr = md->shader_data; + default_material_uniform_set = md->uniform_set; } { @@ -769,12 +772,9 @@ void SceneShaderForwardMobile::init(RendererStorageRD *p_storage, const String p storage->material_initialize(overdraw_material); storage->material_set_shader(overdraw_material, overdraw_material_shader); - wireframe_material_shader = storage->shader_allocate(); - storage->shader_initialize(wireframe_material_shader); - storage->shader_set_code(wireframe_material_shader, "shader_type spatial;\nrender_mode wireframe,unshaded;\n void fragment() { ALBEDO=vec3(0.0,0.0,0.0); }"); - wireframe_material = storage->material_allocate(); - storage->material_initialize(wireframe_material); - storage->material_set_shader(wireframe_material, wireframe_material_shader); + MaterialData *md = (MaterialData *)storage->material_get_data(overdraw_material, RendererStorageRD::SHADER_TYPE_3D); + overdraw_material_shader_ptr = md->shader_data; + overdraw_material_uniform_set = md->uniform_set; } { @@ -802,11 +802,9 @@ SceneShaderForwardMobile::~SceneShaderForwardMobile() { RD::get_singleton()->free(default_vec4_xform_buffer); RD::get_singleton()->free(shadow_sampler); - storage->free(wireframe_material_shader); storage->free(overdraw_material_shader); storage->free(default_shader); - storage->free(wireframe_material); storage->free(overdraw_material); storage->free(default_material); } diff --git a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h index f4f6ceeb1d..476bb57bc5 100644 --- a/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h +++ b/servers/rendering/renderer_rd/forward_mobile/scene_shader_forward_mobile.h @@ -189,8 +189,6 @@ public: RID default_material; RID overdraw_material_shader; RID overdraw_material; - RID wireframe_material_shader; - RID wireframe_material; RID default_shader_rd; RID default_vec4_xform_buffer; @@ -198,6 +196,12 @@ public: RID shadow_sampler; + RID default_material_uniform_set; + ShaderData *default_material_shader_ptr = nullptr; + + RID overdraw_material_uniform_set; + ShaderData *overdraw_material_shader_ptr = nullptr; + SceneShaderForwardMobile(); ~SceneShaderForwardMobile(); |