1#include "TransparencyTemporalUpscaleTask.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"
13#include "Rendering/ITextures.h"
15#include "Foundation/Logging/Logger.h"
23 struct TemporalParameters
25 glm::mat4 inverseClipToWorldMatrix;
26 glm::mat4 prevWorldToClipMatrix;
38void Cogs::Core::TransparencyTemporalUpscaleTask::initialize(RenderTaskContext * context)
45 desc.vs =
"Engine/FullscreenV3T2VS.hlsl";
46 desc.ps =
"Engine/TransparencyTemporalUpscalePS.hlsl";
47 effect = context->renderer->getEffectCache().loadEffect(context, desc);
50 buffers->
annotate(parameterHandle,
"TemporalParameters");
57 for (
unsigned i = 0; i < 4; i++)
58 samplerState.borderColor[i] = 0.f;
62void Cogs::Core::TransparencyTemporalUpscaleTask::cleanup(RenderTaskContext * context)
64 auto device = context->renderer->getDevice();
67 context->renderer->getEffectCache().release(context, effect);
79 LOG_ERROR(logger,
"Invalid transparency temporal upscale effect handle.");
82 effectStatus = status;
86void Cogs::Core::TransparencyTemporalUpscaleTask::apply(
RenderTaskContext * taskContext)
88 RenderInstrumentationScope(taskContext->device->
getImmediateContext(), SCOPE_RENDERING,
"TransparencyTemporalUpscaleTask::apply");
92 uint32_t frame = taskContext->context->
time->getFrame();
93 uint32_t widthDivisor = taskContext->context->
variables->get(
"renderer.oit.TemporalUpscaleWidth", 1);
94 uint32_t heightDivisor = taskContext->context->
variables->get(
"renderer.oit.TemporalUpscaleHeight", 1);
96 auto device = taskContext->renderer->
getDevice();
99 auto depthTarget = input.resources[0].renderTarget;
100 auto oitTarget = input.resources[1].renderTarget;
101 auto historyTarget = input.resources[(frame+1)%2+2].renderTarget;
102 auto renderTarget = output.resources[frame%2].renderTarget;
104 deviceContext->setEffect(effect->handle);
106 deviceContext->setRenderTarget(renderTarget->renderTargetHandle, renderTarget->depthTargetHandle);
107 deviceContext->setViewport(0, 0,
static_cast<float>(renderTarget->width),
static_cast<float>(renderTarget->height));
109 deviceContext->setDepthStencilState(taskContext->states->commonDepthStates[RenderStates::noTestDepthStencilState]);
110 deviceContext->setRasterizerState(taskContext->states->defaultRasterizerStateHandle);
112 deviceContext->setTexture(
"depthTexture", 0, depthTarget->depth->textureHandle);
113 deviceContext->setTexture(
"oitTexture", 0, oitTarget->textures[0]->textureHandle);
114 deviceContext->setTexture(
"historyTexture", 0, historyTarget->textures[0]->textureHandle);
115 deviceContext->setSamplerState(
"historySampler", 0, sampler);
121 auto& cameraData = taskContext->context->cameraSystem->getMainCameraData();
122 uint32_t i = frame % (widthDivisor * heightDivisor);
124 parameters->inverseClipToWorldMatrix = cameraData.inverseViewProjectionMatrix;
125 parameters->prevWorldToClipMatrix = cameraData.prevViewProjection;
126 parameters->width = widthDivisor;
127 parameters->height = heightDivisor;
128 parameters->off_x = i % widthDivisor;
129 parameters->off_y = (i / widthDivisor) % heightDivisor;
130 parameters->size_x = historyTarget->width;
131 parameters->size_y = historyTarget->height;
134 deviceContext->setConstantBuffer(
"TemporalParameters", parameterHandle);
136 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 ITextures * getTextures()=0
Get a pointer to the texture 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.
Provides effects and shader management functionality.
virtual ResourceStatus checkEffect(EffectHandle effectHandle)=0
Check the load status of the effect with the given effectHandle.
Provides texture management functionality.
virtual SamplerStateHandle loadSamplerState(const SamplerState &state)=0
Load a sampler state object.
virtual void releaseSamplerState(SamplerStateHandle handle)=0
Release the sampler state with the given handle.
@ WriteDiscard
Write access. When unmapping the graphics system will discard the old contents of the resource.
Provides RAII style mapping of a buffer resource.
Encapsulates state for texture sampling in a state object.
AddressMode addressModeS
Specifies the addressing mode along the S axis in texture coordinate space.
@ Clamp
Texture coordinates are clamped to the [0, 1] range.
@ MinMagMipLinear
Linear sampling for both minification and magnification.
@ Dynamic
Buffer will be loaded and modified with some frequency.