Add RenderBuffers::LinkedCustomBuffers to reuse main game viewport rendered state (eg. GI) in sub-rendered view
This commit is contained in:
@@ -128,6 +128,8 @@ void RenderBuffers::SetUseAlpha(bool value)
|
|||||||
|
|
||||||
const RenderBuffers::CustomBuffer* RenderBuffers::FindCustomBuffer(const StringView& name) const
|
const RenderBuffers::CustomBuffer* RenderBuffers::FindCustomBuffer(const StringView& name) const
|
||||||
{
|
{
|
||||||
|
if (LinkedCustomBuffers)
|
||||||
|
return LinkedCustomBuffers->FindCustomBuffer(name);
|
||||||
for (const CustomBuffer* e : CustomBuffers)
|
for (const CustomBuffer* e : CustomBuffers)
|
||||||
{
|
{
|
||||||
if (e->Name == name)
|
if (e->Name == name)
|
||||||
@@ -196,6 +198,7 @@ bool RenderBuffers::Init(int32 width, int32 height)
|
|||||||
void RenderBuffers::Release()
|
void RenderBuffers::Release()
|
||||||
{
|
{
|
||||||
LastEyeAdaptationTime = 0;
|
LastEyeAdaptationTime = 0;
|
||||||
|
LinkedCustomBuffers = nullptr;
|
||||||
|
|
||||||
for (int32 i = 0; i < _resources.Count(); i++)
|
for (int32 i = 0; i < _resources.Count(); i++)
|
||||||
_resources[i]->ReleaseGPU();
|
_resources[i]->ReleaseGPU();
|
||||||
|
|||||||
@@ -178,6 +178,8 @@ public:
|
|||||||
template<class T>
|
template<class T>
|
||||||
T* GetCustomBuffer(const StringView& name)
|
T* GetCustomBuffer(const StringView& name)
|
||||||
{
|
{
|
||||||
|
if (LinkedCustomBuffers)
|
||||||
|
return LinkedCustomBuffers->GetCustomBuffer<T>(name);
|
||||||
CustomBuffer* result = (CustomBuffer*)FindCustomBuffer(name);
|
CustomBuffer* result = (CustomBuffer*)FindCustomBuffer(name);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
@@ -206,6 +208,11 @@ public:
|
|||||||
/// </remarks>
|
/// </remarks>
|
||||||
API_FIELD(ReadOnly) GPUTexture* MotionVectors;
|
API_FIELD(ReadOnly) GPUTexture* MotionVectors;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// External Render Buffers used to redirect FindCustomBuffer/GetCustomBuffer calls. Can be linked to other rendering task (eg. main game viewport) to reuse graphics effect state from it (eg. use GI from main game view in in-game camera renderer).
|
||||||
|
/// </summary>
|
||||||
|
API_FIELD() RenderBuffers* LinkedCustomBuffers = nullptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Allocates the buffers.
|
/// Allocates the buffers.
|
||||||
|
|||||||
@@ -117,6 +117,3 @@ PACK_STRUCT(struct ProbeData {
|
|||||||
|
|
||||||
// Default format for the shadow map textures
|
// Default format for the shadow map textures
|
||||||
#define SHADOW_MAPS_FORMAT PixelFormat::D16_UNorm
|
#define SHADOW_MAPS_FORMAT PixelFormat::D16_UNorm
|
||||||
|
|
||||||
// Material distortion offsets output pass (material uses PS_Distortion, ForwardPass resolves the offsets)
|
|
||||||
#define Distortion_Pass_Output_Format PixelFormat::R8G8B8A8_UNorm
|
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ void ForwardPass::Render(RenderContext& renderContext, GPUTexture* input, GPUTex
|
|||||||
const int32 height = renderContext.Buffers->GetHeight();
|
const int32 height = renderContext.Buffers->GetHeight();
|
||||||
const int32 distortionWidth = width;
|
const int32 distortionWidth = width;
|
||||||
const int32 distortionHeight = height;
|
const int32 distortionHeight = height;
|
||||||
const auto tempDesc = GPUTextureDescription::New2D(distortionWidth, distortionHeight, Distortion_Pass_Output_Format);
|
const auto tempDesc = GPUTextureDescription::New2D(distortionWidth, distortionHeight, PixelFormat::R8G8B8A8_UNorm);
|
||||||
auto distortionRT = RenderTargetPool::Get(tempDesc);
|
auto distortionRT = RenderTargetPool::Get(tempDesc);
|
||||||
RENDER_TARGET_POOL_SET_NAME(distortionRT, "Forward.Distortion");
|
RENDER_TARGET_POOL_SET_NAME(distortionRT, "Forward.Distortion");
|
||||||
|
|
||||||
@@ -119,15 +119,13 @@ void ForwardPass::Render(RenderContext& renderContext, GPUTexture* input, GPUTex
|
|||||||
// Render distortion pass
|
// Render distortion pass
|
||||||
view.Pass = DrawPass::Distortion;
|
view.Pass = DrawPass::Distortion;
|
||||||
mainCache->ExecuteDrawCalls(renderContext, distortionList);
|
mainCache->ExecuteDrawCalls(renderContext, distortionList);
|
||||||
|
|
||||||
|
// Copy combined frame with distortion from transparent materials
|
||||||
context->SetViewportAndScissors((float)width, (float)height);
|
context->SetViewportAndScissors((float)width, (float)height);
|
||||||
context->ResetRenderTarget();
|
context->ResetRenderTarget();
|
||||||
context->ResetSR();
|
context->ResetSR();
|
||||||
|
|
||||||
// Bind inputs
|
|
||||||
context->BindSR(0, input);
|
context->BindSR(0, input);
|
||||||
context->BindSR(1, distortionRT);
|
context->BindSR(1, distortionRT);
|
||||||
|
|
||||||
// Copy combined frame with distortion from transparent materials
|
|
||||||
context->SetRenderTarget(output->View());
|
context->SetRenderTarget(output->View());
|
||||||
context->SetState(_psApplyDistortion);
|
context->SetState(_psApplyDistortion);
|
||||||
context->DrawFullscreenTriangle();
|
context->DrawFullscreenTriangle();
|
||||||
|
|||||||
@@ -2,9 +2,6 @@
|
|||||||
|
|
||||||
#include "RenderList.h"
|
#include "RenderList.h"
|
||||||
#include "Engine/Core/Collections/Sorting.h"
|
#include "Engine/Core/Collections/Sorting.h"
|
||||||
#if !BUILD_RELEASE
|
|
||||||
#include "Engine/Core/Utilities.h"
|
|
||||||
#endif
|
|
||||||
#include "Engine/Graphics/Materials/IMaterial.h"
|
#include "Engine/Graphics/Materials/IMaterial.h"
|
||||||
#include "Engine/Graphics/RenderTask.h"
|
#include "Engine/Graphics/RenderTask.h"
|
||||||
#include "Engine/Graphics/GPUContext.h"
|
#include "Engine/Graphics/GPUContext.h"
|
||||||
@@ -649,9 +646,6 @@ void RenderList::ExecuteDrawCalls(const RenderContext& renderContext, DrawCallsL
|
|||||||
{
|
{
|
||||||
if (list.IsEmpty())
|
if (list.IsEmpty())
|
||||||
return;
|
return;
|
||||||
#if !BUILD_RELEASE
|
|
||||||
CHECK(Utilities::CountBits((uint32)renderContext.View.Pass) == 1); // Ensure proper pass is set (single bit flag)
|
|
||||||
#endif
|
|
||||||
PROFILE_GPU_CPU("Drawing");
|
PROFILE_GPU_CPU("Drawing");
|
||||||
const auto* drawCallsData = drawCalls.Get();
|
const auto* drawCallsData = drawCalls.Get();
|
||||||
const auto* listData = list.Indices.Get();
|
const auto* listData = list.Indices.Get();
|
||||||
|
|||||||
@@ -576,7 +576,7 @@ void PS_IndirectLighting(Quad_VS2PS input, out float4 output : SV_Target0)
|
|||||||
// Calculate lighting
|
// Calculate lighting
|
||||||
float3 diffuseColor = GetDiffuseColor(gBuffer);
|
float3 diffuseColor = GetDiffuseColor(gBuffer);
|
||||||
float3 diffuse = Diffuse_Lambert(diffuseColor);
|
float3 diffuse = Diffuse_Lambert(diffuseColor);
|
||||||
output = float4(diffuse * irradiance * gBuffer.AO, saturate(length(irradiance)));
|
output.rgb = diffuse * irradiance * gBuffer.AO;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user