Add support for rendering percentage scale with upscaling to backbuffer
This commit is contained in:
@@ -90,7 +90,7 @@ GPUTexture* RenderBuffers::RequestHalfResDepth(GPUContext* context)
|
||||
}
|
||||
|
||||
// Generate depth
|
||||
MultiScaler::Instance()->DownscaleDepth(context, halfDepthWidth, halfDepthHeight, DepthBuffer->View(), HalfResDepth->View());
|
||||
MultiScaler::Instance()->DownscaleDepth(context, halfDepthWidth, halfDepthHeight, DepthBuffer, HalfResDepth->View());
|
||||
|
||||
return HalfResDepth;
|
||||
}
|
||||
|
||||
@@ -296,13 +296,27 @@ void SceneRenderTask::OnPostRender(GPUContext* context, RenderContext& renderCon
|
||||
|
||||
Viewport SceneRenderTask::GetViewport() const
|
||||
{
|
||||
Viewport viewport;
|
||||
if (Output)
|
||||
viewport = Viewport(0, 0, static_cast<float>(Output->Width()), static_cast<float>(Output->Height()));
|
||||
else if (SwapChain)
|
||||
viewport = Viewport(0, 0, static_cast<float>(SwapChain->GetWidth()), static_cast<float>(SwapChain->GetHeight()));
|
||||
else if (Buffers != nullptr)
|
||||
viewport = Buffers->GetViewport();
|
||||
else
|
||||
viewport = Viewport(0, 0, 1280, 720);
|
||||
viewport.Width *= RenderingPercentage;
|
||||
viewport.Height *= RenderingPercentage;
|
||||
return viewport;
|
||||
}
|
||||
|
||||
Viewport SceneRenderTask::GetOutputViewport() const
|
||||
{
|
||||
if (Output && Output->IsAllocated())
|
||||
return Viewport(0, 0, static_cast<float>(Output->Width()), static_cast<float>(Output->Height()));
|
||||
if (SwapChain)
|
||||
return Viewport(0, 0, static_cast<float>(SwapChain->GetWidth()), static_cast<float>(SwapChain->GetHeight()));
|
||||
if (Buffers != nullptr)
|
||||
return Buffers->GetViewport();
|
||||
return Viewport(0, 0, 1280, 720);
|
||||
return GetViewport();
|
||||
}
|
||||
|
||||
GPUTextureView* SceneRenderTask::GetOutputView() const
|
||||
@@ -352,11 +366,11 @@ void SceneRenderTask::OnBegin(GPUContext* context)
|
||||
// Setup render buffers for the output rendering resolution
|
||||
if (Output)
|
||||
{
|
||||
Buffers->Init(Output->Width(), Output->Height());
|
||||
Buffers->Init((int32)((float)Output->Width() * RenderingPercentage), (int32)((float)Output->Height() * RenderingPercentage));
|
||||
}
|
||||
else if (SwapChain)
|
||||
{
|
||||
Buffers->Init(SwapChain->GetWidth(), SwapChain->GetHeight());
|
||||
Buffers->Init((int32)((float)SwapChain->GetWidth() * RenderingPercentage), (int32)((float)SwapChain->GetHeight() * RenderingPercentage));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,7 +399,7 @@ bool SceneRenderTask::Resize(int32 width, int32 height)
|
||||
{
|
||||
if (Output && Output->Resize(width, height))
|
||||
return true;
|
||||
if (Buffers && Buffers->Init(width, height))
|
||||
if (Buffers && Buffers->Init((int32)((float)width * RenderingPercentage), (int32)((float)height * RenderingPercentage)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -423,7 +437,7 @@ void MainRenderTask::OnBegin(GPUContext* context)
|
||||
#if !USE_EDITOR
|
||||
// Sync render buffers size with the backbuffer
|
||||
const auto size = Screen::GetSize();
|
||||
Buffers->Init((int32)size.X, (int32)size.Y);
|
||||
Buffers->Init((int32)(size.X * RenderingPercentage), (int32)(size.Y * RenderingPercentage));
|
||||
#endif
|
||||
|
||||
SceneRenderTask::OnBegin(context);
|
||||
|
||||
@@ -263,6 +263,11 @@ public:
|
||||
/// </summary>
|
||||
API_FIELD() ActorsSources ActorsSource = ActorsSources::Scenes;
|
||||
|
||||
/// <summary>
|
||||
/// The scale of the rendering resolution relative to the output dimensions. If lower than 1 the scene and postprocessing will be rendered at a lower resolution and upscaled to the output backbuffer.
|
||||
/// </summary>
|
||||
API_FIELD() float RenderingPercentage = 1.0f;
|
||||
|
||||
/// <summary>
|
||||
/// The custom set of actors to render.
|
||||
/// </summary>
|
||||
@@ -336,10 +341,15 @@ public:
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendering render task viewport.
|
||||
/// Gets the rendering render task viewport (before upsampling).
|
||||
/// </summary>
|
||||
API_PROPERTY() Viewport GetViewport() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendering output viewport (after upsampling).
|
||||
/// </summary>
|
||||
API_PROPERTY() Viewport GetOutputViewport() const;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rendering output view.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user