diff --git a/Source/Engine/Graphics/Materials/MaterialParams.cpp b/Source/Engine/Graphics/Materials/MaterialParams.cpp index 1e0da6213..87d4193ef 100644 --- a/Source/Engine/Graphics/Materials/MaterialParams.cpp +++ b/Source/Engine/Graphics/Materials/MaterialParams.cpp @@ -490,7 +490,7 @@ void MaterialParameter::Bind(BindMeta& meta) const Platform::MemoryClear(&bindingData, sizeof(bindingData)); for (int32 i = 0; i < 4; i++) meta.Context->BindSR(_registerIndex + i, bindingData.Cascades[i] ? bindingData.Cascades[i]->ViewVolume() : nullptr); - *((GlobalSignDistanceFieldPass::ConstantsData*)(meta.Constants.Get() + _offset)) = bindingData.GlobalSDF; + *((GlobalSignDistanceFieldPass::ConstantsData*)(meta.Constants.Get() + _offset)) = bindingData.Constants; break; } default: diff --git a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp index 87d979d62..8803c7e5b 100644 --- a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp +++ b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.cpp @@ -549,10 +549,10 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co } // Init constants - result.GlobalSurfaceAtlas.ViewPos = renderContext.View.Position; - result.GlobalSurfaceAtlas.Resolution = (float)resolution; - result.GlobalSurfaceAtlas.ChunkSize = distance / (float)GLOBAL_SURFACE_ATLAS_CHUNKS_RESOLUTION; - result.GlobalSurfaceAtlas.ObjectsCount = surfaceAtlasData.Objects.Count(); + result.Constants.ViewPos = renderContext.View.Position; + result.Constants.Resolution = (float)resolution; + result.Constants.ChunkSize = distance / (float)GLOBAL_SURFACE_ATLAS_CHUNKS_RESOLUTION; + result.Constants.ObjectsCount = surfaceAtlasData.Objects.Count(); // Cull objects into chunks (for faster Atlas sampling) if (surfaceAtlasData.Objects.Count() != 0) @@ -629,7 +629,7 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co data.ViewNearPlane = renderContext.View.Near; data.ViewFarPlane = renderContext.View.Far; data.CulledObjectsCapacity = objectsBufferCapacity; - data.GlobalSurfaceAtlas = result.GlobalSurfaceAtlas; + data.GlobalSurfaceAtlas = result.Constants; context->UpdateCB(_cb0, &data); context->BindCB(0, _cb0); static_assert(GLOBAL_SURFACE_ATLAS_CHUNKS_RESOLUTION % GLOBAL_SURFACE_ATLAS_CHUNKS_GROUP_SIZE == 0, "Invalid chunks resolution/groups setting."); @@ -710,8 +710,8 @@ bool GlobalSurfaceAtlasPass::Render(RenderContext& renderContext, GPUContext* co context->BindCB(0, _cb0); Data0 data; data.ViewWorldPos = renderContext.View.Position; - data.GlobalSDF = bindingDataSDF.GlobalSDF; - data.GlobalSurfaceAtlas = result.GlobalSurfaceAtlas; + data.GlobalSDF = bindingDataSDF.Constants; + data.GlobalSurfaceAtlas = result.Constants; // Shade object tiles influenced by lights to calculate direct lighting // TODO: reduce redraw frequency for static lights (StaticFlags::Lightmap) @@ -825,8 +825,8 @@ void GlobalSurfaceAtlasPass::RenderDebug(RenderContext& renderContext, GPUContex data.ViewFarPlane = renderContext.View.Far; for (int32 i = 0; i < 4; i++) data.ViewFrustumWorldRays[i] = Vector4(renderContext.List->FrustumCornersWs[i + 4], 0); - data.GlobalSDF = bindingDataSDF.GlobalSDF; - data.GlobalSurfaceAtlas = bindingData.GlobalSurfaceAtlas; + data.GlobalSDF = bindingDataSDF.Constants; + data.GlobalSurfaceAtlas = bindingData.Constants; context->UpdateCB(_cb0, &data); context->BindCB(0, _cb0); } @@ -837,7 +837,7 @@ void GlobalSurfaceAtlasPass::RenderDebug(RenderContext& renderContext, GPUContex } context->BindSR(8, bindingData.Chunks ? bindingData.Chunks->View() : nullptr); context->BindSR(9, bindingData.CulledObjects ? bindingData.CulledObjects->View() : nullptr); - context->BindSR(10, bindingData.Atlas[0]->View()); + context->BindSR(10, bindingData.AtlasDepth->View()); context->SetState(_psDebug); context->SetRenderTarget(output->View()); { @@ -845,23 +845,23 @@ void GlobalSurfaceAtlasPass::RenderDebug(RenderContext& renderContext, GPUContex Vector2 outputSizeTwoThird = outputSize * 0.666f; // Full screen - direct light - context->BindSR(11, bindingData.Atlas[4]->View()); + context->BindSR(11, bindingData.AtlasLighting->View()); context->SetViewport(outputSize.X, outputSize.Y); context->SetScissor(Rectangle(0, 0, outputSizeTwoThird.X, outputSize.Y)); context->DrawFullscreenTriangle(); // Bottom left - diffuse - context->BindSR(11, bindingData.Atlas[1]->View()); + context->BindSR(11, bindingData.AtlasGBuffer0->View()); context->SetViewportAndScissors(Viewport(outputSizeTwoThird.X, 0, outputSizeThird.X, outputSizeThird.Y)); context->DrawFullscreenTriangle(); // Bottom middle - normals - context->BindSR(11, bindingData.Atlas[2]->View()); + context->BindSR(11, bindingData.AtlasGBuffer1->View()); context->SetViewportAndScissors(Viewport(outputSizeTwoThird.X, outputSizeThird.Y, outputSizeThird.X, outputSizeThird.Y)); context->DrawFullscreenTriangle(); // Bottom right - roughness/metalness/ao - context->BindSR(11, bindingData.Atlas[3]->View()); + context->BindSR(11, bindingData.AtlasGBuffer2->View()); context->SetViewportAndScissors(Viewport(outputSizeTwoThird.X, outputSizeTwoThird.Y, outputSizeThird.X, outputSizeThird.Y)); context->DrawFullscreenTriangle(); } diff --git a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h index 81eba1bcb..ca33ddc68 100644 --- a/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h +++ b/Source/Engine/Renderer/GI/GlobalSurfaceAtlasPass.h @@ -24,10 +24,21 @@ public: // Binding data for the GPU. struct BindingData { - GPUTexture* Atlas[5]; + union + { + struct + { + GPUTexture* AtlasDepth; + GPUTexture* AtlasGBuffer0; + GPUTexture* AtlasGBuffer1; + GPUTexture* AtlasGBuffer2; + GPUTexture* AtlasLighting; + }; + GPUTexture* Atlas[5]; + }; GPUBuffer* Chunks; GPUBuffer* CulledObjects; - ConstantsData GlobalSurfaceAtlas; + ConstantsData Constants; }; private: diff --git a/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp b/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp index a36d780e6..c94b41b6f 100644 --- a/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp +++ b/Source/Engine/Renderer/GlobalSignDistanceFieldPass.cpp @@ -732,12 +732,12 @@ bool GlobalSignDistanceFieldPass::Render(RenderContext& renderContext, GPUContex const float maxDistance = distance * 2; const float voxelSize = maxDistance / resolution; const Vector3 center = cascade.Position; - result.GlobalSDF.CascadePosDistance[cascadeIndex] = Vector4(center, distance); - result.GlobalSDF.CascadeVoxelSize.Raw[cascadeIndex] = voxelSize; + result.Constants.CascadePosDistance[cascadeIndex] = Vector4(center, distance); + result.Constants.CascadeVoxelSize.Raw[cascadeIndex] = voxelSize; result.Cascades[cascadeIndex] = cascade.Texture; result.CascadeMips[cascadeIndex] = cascade.Mip; } - result.GlobalSDF.Resolution = (float)resolution; + result.Constants.Resolution = (float)resolution; sdfData.Result = result; return false; } @@ -760,7 +760,7 @@ void GlobalSignDistanceFieldPass::RenderDebug(RenderContext& renderContext, GPUC data.ViewFarPlane = renderContext.View.Far; for (int32 i = 0; i < 4; i++) data.ViewFrustumWorldRays[i] = Vector4(renderContext.List->FrustumCornersWs[i + 4], 0); - data.GlobalSDF = bindingData.GlobalSDF; + data.GlobalSDF = bindingData.Constants; context->UpdateCB(_cb0, &data); context->BindCB(0, _cb0); } diff --git a/Source/Engine/Renderer/GlobalSignDistanceFieldPass.h b/Source/Engine/Renderer/GlobalSignDistanceFieldPass.h index 6460980af..5e1f0461a 100644 --- a/Source/Engine/Renderer/GlobalSignDistanceFieldPass.h +++ b/Source/Engine/Renderer/GlobalSignDistanceFieldPass.h @@ -24,7 +24,7 @@ public: { GPUTexture* Cascades[4]; GPUTexture* CascadeMips[4]; - ConstantsData GlobalSDF; + ConstantsData Constants; }; private: diff --git a/Source/Shaders/GI/GlobalSurfaceAtlas.shader b/Source/Shaders/GI/GlobalSurfaceAtlas.shader index 16d569158..b9e805e80 100644 --- a/Source/Shaders/GI/GlobalSurfaceAtlas.shader +++ b/Source/Shaders/GI/GlobalSurfaceAtlas.shader @@ -22,7 +22,7 @@ GlobalSurfaceAtlasData GlobalSurfaceAtlas; LightData Light; META_CB_END -struct AtlasVertexIput +struct AtlasVertexInput { float2 Position : POSITION0; float2 TileUV : TEXCOORD0; @@ -41,7 +41,7 @@ META_VS(true, FEATURE_LEVEL_SM5) META_VS_IN_ELEMENT(POSITION, 0, R16G16_FLOAT, 0, ALIGN, PER_VERTEX, 0, true) META_VS_IN_ELEMENT(TEXCOORD, 0, R16G16_FLOAT, 0, ALIGN, PER_VERTEX, 0, true) META_VS_IN_ELEMENT(TEXCOORD, 1, R32_UINT, 0, ALIGN, PER_VERTEX, 0, true) -AtlasVertexOutput VS_Atlas(AtlasVertexIput input) +AtlasVertexOutput VS_Atlas(AtlasVertexInput input) { AtlasVertexOutput output; output.Position = float4(input.Position, 1, 1);