Fixes for overriden draw calls material in debug views
This commit is contained in:
@@ -19,9 +19,6 @@
|
||||
#include "Engine/Renderer/RenderList.h"
|
||||
#include "Engine/Renderer/Lightmaps.h"
|
||||
|
||||
// The limit for maximum material complexity (estimated based on shader textures, instructions and GPU stages usage).
|
||||
#define COMPLEXITY_LIMIT 1700
|
||||
|
||||
const MaterialInfo& MaterialComplexityMaterialShader::WrapperShader::GetInfo() const
|
||||
{
|
||||
if (MaterialAsset)
|
||||
@@ -77,7 +74,7 @@ void MaterialComplexityMaterialShader::WrapperShader::Bind(BindParameters& param
|
||||
ASSERT_LOW_LAYER(material && material->IsReady());
|
||||
material->Bind(params);
|
||||
GPUPipelineState* materialPs = params.GPUContext->GetState();
|
||||
const float complexity = (float)Math::Min(materialPs->Complexity, COMPLEXITY_LIMIT) / COMPLEXITY_LIMIT;
|
||||
const float complexity = (float)Math::Min(materialPs->Complexity, MATERIAL_COMPLEXITY_LIMIT) / MATERIAL_COMPLEXITY_LIMIT;
|
||||
|
||||
// Draw with custom color
|
||||
const Color color(complexity, complexity, complexity, 1.0f);
|
||||
@@ -103,7 +100,7 @@ MaterialComplexityMaterialShader::MaterialComplexityMaterialShader()
|
||||
#undef INIT_WRAPPER
|
||||
}
|
||||
|
||||
void MaterialComplexityMaterialShader::DebugOverrideDrawCallsMaterial(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer)
|
||||
void MaterialComplexityMaterialShader::DebugOverrideDrawCallsMaterial(RenderContext& renderContext)
|
||||
{
|
||||
// Cache 'ready' state for wrappers
|
||||
bool isReady[ARRAY_COUNT(_wrappers) + 1];
|
||||
@@ -116,16 +113,6 @@ void MaterialComplexityMaterialShader::DebugOverrideDrawCallsMaterial(RenderCont
|
||||
DebugOverrideDrawCallsMaterial(e, isReady);
|
||||
for (auto& e : renderContext.List->BatchedDrawCalls)
|
||||
DebugOverrideDrawCallsMaterial(e.DrawCall, isReady);
|
||||
|
||||
// Initialize background with complexity of the sky (uniform)
|
||||
if (renderContext.List->Sky)
|
||||
{
|
||||
renderContext.List->Sky->ApplySky(context, renderContext, Matrix::Identity);
|
||||
GPUPipelineState* materialPs = context->GetState();
|
||||
const float complexity = (float)Math::Min(materialPs->Complexity, COMPLEXITY_LIMIT) / COMPLEXITY_LIMIT;
|
||||
context->Clear(lightBuffer, Color(complexity, complexity, complexity, 1.0f));
|
||||
renderContext.List->Sky = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialComplexityMaterialShader::Draw(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer)
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
class GPUPipelineState;
|
||||
|
||||
// The limit for maximum material complexity (estimated based on shader textures, instructions and GPU stages usage).
|
||||
#define MATERIAL_COMPLEXITY_LIMIT 1700
|
||||
|
||||
/// <summary>
|
||||
/// Rendering material shaders complexity to visualize performance of pixels rendering in editor.
|
||||
/// </summary>
|
||||
@@ -39,7 +42,7 @@ private:
|
||||
public:
|
||||
|
||||
MaterialComplexityMaterialShader();
|
||||
void DebugOverrideDrawCallsMaterial(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer);
|
||||
void DebugOverrideDrawCallsMaterial(RenderContext& renderContext);
|
||||
void Draw(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer);
|
||||
|
||||
private:
|
||||
|
||||
@@ -102,7 +102,7 @@ void GBufferPass::Dispose()
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void DebugOverrideDrawCallsMaterial(RenderContext& renderContext, IMaterial* material)
|
||||
void DebugOverrideDrawCallsMaterial(const RenderContext& renderContext, IMaterial* material)
|
||||
{
|
||||
if (!material->IsReady())
|
||||
return;
|
||||
@@ -114,7 +114,7 @@ void DebugOverrideDrawCallsMaterial(RenderContext& renderContext, IMaterial* mat
|
||||
auto& drawCallsList = renderContext.List->DrawCallsLists[(int32)DrawCallsListType::GBuffer];
|
||||
for (int32 i : drawCallsList.Indices)
|
||||
{
|
||||
auto& drawCall = renderContext.List->DrawCalls[i];
|
||||
auto& drawCall = renderContext.List->DrawCalls.Get()[i];
|
||||
if (drawCall.Material->IsSurface())
|
||||
{
|
||||
drawCall.Material = material;
|
||||
@@ -127,7 +127,7 @@ void DebugOverrideDrawCallsMaterial(RenderContext& renderContext, IMaterial* mat
|
||||
auto& drawCallsList = renderContext.List->DrawCallsLists[(int32)DrawCallsListType::GBufferNoDecals];
|
||||
for (int32 i : drawCallsList.Indices)
|
||||
{
|
||||
auto& drawCall = renderContext.List->DrawCalls[i];
|
||||
auto& drawCall = renderContext.List->DrawCalls.Get()[i];
|
||||
if (drawCall.Material->IsSurface())
|
||||
{
|
||||
drawCall.Material = material;
|
||||
@@ -176,32 +176,20 @@ void GBufferPass::Fill(RenderContext& renderContext, GPUTextureView* lightBuffer
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
// Override draw calls material to use material debug shader
|
||||
if (renderContext.View.Mode == ViewMode::LightmapUVsDensity)
|
||||
// Special debug drawing
|
||||
if (renderContext.View.Mode == ViewMode::MaterialComplexity)
|
||||
{
|
||||
if (!_lightmapUVsDensity)
|
||||
_lightmapUVsDensity = New<LightmapUVsDensityMaterialShader>();
|
||||
DebugOverrideDrawCallsMaterial(renderContext, _lightmapUVsDensity);
|
||||
// Initialize background with complexity of the sky (uniform)
|
||||
if (renderContext.List->Sky)
|
||||
{
|
||||
renderContext.List->Sky->ApplySky(context, renderContext, Matrix::Identity);
|
||||
GPUPipelineState* materialPs = context->GetState();
|
||||
const float complexity = (float)Math::Min(materialPs->Complexity, MATERIAL_COMPLEXITY_LIMIT) / MATERIAL_COMPLEXITY_LIMIT;
|
||||
context->Clear(lightBuffer, Color(complexity, complexity, complexity, 1.0f));
|
||||
renderContext.List->Sky = nullptr;
|
||||
}
|
||||
}
|
||||
else if (renderContext.View.Mode == ViewMode::VertexColors)
|
||||
{
|
||||
if (!_vertexColors)
|
||||
_vertexColors = New<VertexColorsMaterialShader>();
|
||||
DebugOverrideDrawCallsMaterial(renderContext, _vertexColors);
|
||||
}
|
||||
else if (renderContext.View.Mode == ViewMode::LODPreview)
|
||||
{
|
||||
if (!_lodPreview)
|
||||
_lodPreview = New<LODPreviewMaterialShader>();
|
||||
DebugOverrideDrawCallsMaterial(renderContext, _lodPreview);
|
||||
}
|
||||
else if (renderContext.View.Mode == ViewMode::MaterialComplexity)
|
||||
{
|
||||
if (!_materialComplexity)
|
||||
_materialComplexity = New<MaterialComplexityMaterialShader>();
|
||||
_materialComplexity->DebugOverrideDrawCallsMaterial(renderContext, context, lightBuffer);
|
||||
}
|
||||
if (renderContext.View.Mode == ViewMode::PhysicsColliders)
|
||||
else if (renderContext.View.Mode == ViewMode::PhysicsColliders)
|
||||
{
|
||||
context->ResetRenderTarget();
|
||||
return;
|
||||
@@ -328,6 +316,35 @@ GPUTextureView* GBufferPass::RenderSkybox(RenderContext& renderContext, GPUConte
|
||||
return result;
|
||||
}
|
||||
|
||||
void GBufferPass::OverrideDrawCalls(RenderContext& renderContext)
|
||||
{
|
||||
// Override draw calls material to use material debug shader
|
||||
if (renderContext.View.Mode == ViewMode::LightmapUVsDensity)
|
||||
{
|
||||
if (!_lightmapUVsDensity)
|
||||
_lightmapUVsDensity = New<LightmapUVsDensityMaterialShader>();
|
||||
DebugOverrideDrawCallsMaterial(renderContext, _lightmapUVsDensity);
|
||||
}
|
||||
else if (renderContext.View.Mode == ViewMode::VertexColors)
|
||||
{
|
||||
if (!_vertexColors)
|
||||
_vertexColors = New<VertexColorsMaterialShader>();
|
||||
DebugOverrideDrawCallsMaterial(renderContext, _vertexColors);
|
||||
}
|
||||
else if (renderContext.View.Mode == ViewMode::LODPreview)
|
||||
{
|
||||
if (!_lodPreview)
|
||||
_lodPreview = New<LODPreviewMaterialShader>();
|
||||
DebugOverrideDrawCallsMaterial(renderContext, _lodPreview);
|
||||
}
|
||||
else if (renderContext.View.Mode == ViewMode::MaterialComplexity)
|
||||
{
|
||||
if (!_materialComplexity)
|
||||
_materialComplexity = New<MaterialComplexityMaterialShader>();
|
||||
_materialComplexity->DebugOverrideDrawCallsMaterial(renderContext);
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_EDITOR
|
||||
|
||||
void GBufferPass::DrawMaterialComplexity(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer)
|
||||
|
||||
@@ -46,6 +46,7 @@ public:
|
||||
GPUTextureView* RenderSkybox(RenderContext& renderContext, GPUContext* context);
|
||||
|
||||
#if USE_EDITOR
|
||||
void OverrideDrawCalls(RenderContext& renderContext);
|
||||
void DrawMaterialComplexity(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -356,6 +356,10 @@ void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderCont
|
||||
for (const int64 label : renderContextBatch.WaitLabels)
|
||||
JobSystem::Wait(label);
|
||||
renderContextBatch.WaitLabels.Clear();
|
||||
|
||||
#if USE_EDITOR
|
||||
GBufferPass::Instance()->OverrideDrawCalls(renderContext);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Sort draw calls
|
||||
|
||||
Reference in New Issue
Block a user