1#include "TransparencyUpscaleTask.h"
4#include "Renderer/Renderer.h"
5#include "Renderer/RenderTarget.h"
6#include "Renderer/RenderStateUpdater.h"
7#include "Services/Time.h"
8#include "Services/Variables.h"
10#include "Rendering/IBuffers.h"
11#include "Rendering/IEffects.h"
12#include "Rendering/IGraphicsDevice.h"
14#include "Foundation/Logging/Logger.h"
22 struct UpscaleParameters
24 uint32_t width, height;
30void Cogs::Core::TransparencyUpscaleTask::initialize(RenderTaskContext * context)
36 desc.vs =
"Engine/FullscreenV3T2VS.hlsl";
37 desc.ps =
"Engine/TransparencyUpscalePS.hlsl";
38 effect = context->renderer->getEffectCache().loadEffect(context, desc);
41 buffers->
annotate(parameterHandle,
"UpscaleParameters");
44void Cogs::Core::TransparencyUpscaleTask::cleanup(RenderTaskContext * context)
46 auto device = context->renderer->getDevice();
48 context->renderer->getEffectCache().release(context, effect);
59 LOG_ERROR(logger,
"Invalid transparency upscale effect handle.");
62 effectStatus = status;
68 RenderInstrumentationScope(taskContext->device->
getImmediateContext(), SCOPE_RENDERING,
"TransparencyUpscaleTask::apply");
72 uint32_t frame = taskContext->context->
time->getFrame();
74 RenderTexture *color = (frame%2==0) ? input.resources[0].renderTexure : input.resources[1].renderTexure;
75 auto deferredRenderTarget = input.get(RenderResourceType::RenderTarget)->renderTarget;
76 auto renderTarget = output.get(RenderResourceType::RenderTarget)->renderTarget;
78 auto device = taskContext->renderer->
getDevice();
83 deviceContext->setRenderTarget(renderTarget->renderTargetHandle, renderTarget->depthTargetHandle);
84 deviceContext->setViewport(0, 0,
static_cast<float>(renderTarget->width),
static_cast<float>(renderTarget->height));
86 deviceContext->setDepthStencilState(taskContext->states->commonDepthStates[RenderStates::noTestDepthStencilState]);
87 deviceContext->setRasterizerState(taskContext->states->defaultRasterizerStateHandle);
89 deviceContext->setTexture(
"oitTexture", 0, color->textureHandle);
90 deviceContext->setTexture(
"colorTexture", 0, deferredRenderTarget->textures[0]->textureHandle);
91 deviceContext->setTexture(
"depthTexture", 1, deferredRenderTarget->depth->textureHandle);
97 parameters->width = taskContext->context->
variables->get(
"renderer.oit.UpscaleWidth", 1);
98 parameters->height = taskContext->context->
variables->get(
"renderer.oit.UpscaleHeight", 1);
102 deviceContext->setConstantBuffer(
"UpscaleParameters", parameterHandle);
104 deviceContext->setVertexBuffers(
nullptr, 0,
nullptr,
nullptr);
std::unique_ptr< class Variables > variables
Variables service instance.
std::unique_ptr< class Time > time
Time service instance.
IGraphicsDevice * getDevice() override
Get the graphics device used by the renderer.
Represents a graphics device used to manage graphics resources and issue drawing commands.
virtual IEffects * getEffects()=0
Get a pointer to the effect management interface.
virtual IContext * getImmediateContext()=0
Get a pointer to the immediate context used to issue commands to the graphics device.
virtual IBuffers * getBuffers()=0
Get a pointer to the buffer management interface.
Log implementation class.
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains all Cogs related functionality.
ResourceStatus
Status of an asynchronously loaded resource, such as an effect or a pipeline.
@ Error
The resource failed to load.
@ Ready
The resource has loaded successfully and is ready for use.
@ TriangleList
List of triangles.
@ Write
The buffer can be mapped and written to by the CPU after creation.
@ ConstantBuffer
The buffer can be bound as input to effects as a constant buffer.
Cogs::ResourceStatus checkReady(RenderTaskContext *context) override
Check if the task is ready to be applied, e.g.
Contains an effect description used to load a single effect.
static const Handle_t NoHandle
Represents a handle to nothing.
Provides buffer management functionality.
virtual void annotate(BufferHandle handle, const StringView &name)
Associate a name with an object for use in graphics debugging.
virtual BufferHandle loadBuffer(const void *data, const size_t size, Usage::EUsage usage, uint32_t accessMode, uint32_t bindFlags, uint32_t stride=0)=0
Loads a new buffer using the given data to populate the buffer.
virtual void releaseBuffer(BufferHandle bufferHandle)=0
Releases the buffer with the given bufferHandle.
virtual void setEffect(EffectHandle handle)=0
Set the current effect.
Provides effects and shader management functionality.
virtual ResourceStatus checkEffect(EffectHandle effectHandle)=0
Check the load status of the effect with the given effectHandle.
@ WriteDiscard
Write access. When unmapping the graphics system will discard the old contents of the resource.
Provides RAII style mapping of a buffer resource.
@ Dynamic
Buffer will be loaded and modified with some frequency.