Fix render debug modes.

* Ovedraw debug works again
* Lighting debug works again
This commit is contained in:
reduz 2021-07-03 14:50:36 -03:00
parent e849dc1791
commit fe17a6c907
6 changed files with 66 additions and 31 deletions

View file

@ -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;

View file

@ -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;
}
{

View file

@ -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();

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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();