From 6a1378ebdb35b7640638fa8b29d2324b20c428ec Mon Sep 17 00:00:00 2001 From: Wojciech Figat Date: Tue, 9 Aug 2022 14:37:29 +0200 Subject: [PATCH] Fix Global Surface Atlas drawing of objects that are hidden in GBuffer pass but should be visible for GI --- Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp | 2 +- Source/Engine/Graphics/Materials/DeferredMaterialShader.h | 2 ++ Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp | 4 ++-- Source/Engine/Graphics/Materials/DeformableMaterialShader.h | 2 ++ Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp | 2 +- Source/Engine/Graphics/Materials/TerrainMaterialShader.h | 2 ++ Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp | 4 ++-- Source/Engine/Renderer/RenderList.cpp | 2 +- 8 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp b/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp index 7e7e6c562..6fdac4f2d 100644 --- a/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/DeferredMaterialShader.cpp @@ -42,7 +42,7 @@ PACK_STRUCT(struct DeferredMaterialShaderData { DrawPass DeferredMaterialShader::GetDrawModes() const { - return DrawPass::Depth | DrawPass::GBuffer | DrawPass::MotionVectors | DrawPass::QuadOverdraw; + return DrawPass::Depth | DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas | DrawPass::MotionVectors | DrawPass::QuadOverdraw; } bool DeferredMaterialShader::CanUseLightmap() const diff --git a/Source/Engine/Graphics/Materials/DeferredMaterialShader.h b/Source/Engine/Graphics/Materials/DeferredMaterialShader.h index 3e379ea01..af24ebba6 100644 --- a/Source/Engine/Graphics/Materials/DeferredMaterialShader.h +++ b/Source/Engine/Graphics/Materials/DeferredMaterialShader.h @@ -32,6 +32,8 @@ private: case DrawPass::Depth: return useSkinning ? &DepthSkinned : &Depth; case DrawPass::GBuffer: + case DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas: + case DrawPass::GlobalSurfaceAtlas: return useLightmap ? &DefaultLightmap : (useSkinning ? &DefaultSkinned : &Default); case DrawPass::MotionVectors: return useSkinning ? (perBoneMotionBlur ? &MotionVectorsSkinnedPerBone : &MotionVectorsSkinned) : &MotionVectors; diff --git a/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp b/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp index 46f969260..ec3b800fe 100644 --- a/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/DeformableMaterialShader.cpp @@ -153,7 +153,7 @@ bool DeformableMaterialShader::Load() if (_info.BlendMode == MaterialBlendMode::Opaque) { - _drawModes = DrawPass::GBuffer; + _drawModes |= DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas; // GBuffer Pass psDesc.VS = _shader->GetVS("VS_SplineModel"); @@ -162,7 +162,7 @@ bool DeformableMaterialShader::Load() } else { - _drawModes = DrawPass::Forward; + _drawModes |= DrawPass::Forward; // Forward Pass psDesc.VS = _shader->GetVS("VS_SplineModel"); diff --git a/Source/Engine/Graphics/Materials/DeformableMaterialShader.h b/Source/Engine/Graphics/Materials/DeformableMaterialShader.h index 26031f2ea..550c9be46 100644 --- a/Source/Engine/Graphics/Materials/DeformableMaterialShader.h +++ b/Source/Engine/Graphics/Materials/DeformableMaterialShader.h @@ -25,6 +25,8 @@ private: case DrawPass::Depth: return &Depth; case DrawPass::GBuffer: + case DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas: + case DrawPass::GlobalSurfaceAtlas: case DrawPass::Forward: return &Default; #if USE_EDITOR diff --git a/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp b/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp index 295c8c270..bcdb4ee83 100644 --- a/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp +++ b/Source/Engine/Graphics/Materials/TerrainMaterialShader.cpp @@ -39,7 +39,7 @@ PACK_STRUCT(struct TerrainMaterialShaderData { DrawPass TerrainMaterialShader::GetDrawModes() const { - return DrawPass::Depth | DrawPass::GBuffer; + return DrawPass::Depth | DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas; } bool TerrainMaterialShader::CanUseLightmap() const diff --git a/Source/Engine/Graphics/Materials/TerrainMaterialShader.h b/Source/Engine/Graphics/Materials/TerrainMaterialShader.h index 1faedc72d..5e050ea87 100644 --- a/Source/Engine/Graphics/Materials/TerrainMaterialShader.h +++ b/Source/Engine/Graphics/Materials/TerrainMaterialShader.h @@ -26,6 +26,8 @@ private: case DrawPass::Depth: return &Depth; case DrawPass::GBuffer: + case DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas: + case DrawPass::GlobalSurfaceAtlas: return useLightmap ? &DefaultLightmap : &Default; #if USE_EDITOR case DrawPass::QuadOverdraw: diff --git a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp index d9b77d978..87f5f102c 100644 --- a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp +++ b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp @@ -513,7 +513,7 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co RenderContext renderContextTiles = renderContext; renderContextTiles.List = RenderList::GetFromPool(); - renderContextTiles.View.Pass = DrawPass::GBuffer; + renderContextTiles.View.Pass = DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas; renderContextTiles.View.Mode = ViewMode::Default; renderContextTiles.View.ModelLODBias += 100000; renderContextTiles.View.ShadowModelLODBias += 100000; @@ -582,7 +582,7 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co // Fake projection matrix to disable Screen Size culling based on RenderTools::ComputeBoundsScreenRadiusSquared renderContextTiles.View.Projection.Values[0][0] = 10000.0f; - + // Collect draw calls for the object object.Actor->Draw(renderContextTiles); diff --git a/Source/Engine/Renderer/RenderList.cpp b/Source/Engine/Renderer/RenderList.cpp index 640f95c18..eb66ef98d 100644 --- a/Source/Engine/Renderer/RenderList.cpp +++ b/Source/Engine/Renderer/RenderList.cpp @@ -430,7 +430,7 @@ void RenderList::AddDrawCall(DrawPass drawModes, StaticFlags staticFlags, DrawCa { DrawCallsLists[(int32)DrawCallsListType::Depth].Indices.Add(index); } - if (mask & DrawPass::GBuffer) + if (mask & (DrawPass::GBuffer | DrawPass::GlobalSurfaceAtlas)) { if (receivesDecals) DrawCallsLists[(int32)DrawCallsListType::GBuffer].Indices.Add(index);