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"
14 struct TemporalParameters
16 glm::mat4 inverseClipToWorldMatrix;
17 glm::mat4 prevWorldToClipMatrix;
27void Cogs::Core::TransparencyTemporalUpscaleTask::initialize(RenderTaskContext * context)
29 auto device = context->renderer->getDevice();
30 auto buffers = device->getBuffers();
31 auto textures = device->getTextures();
34 desc.vs =
"Engine/FullscreenV3T2VS.hlsl";
35 desc.ps =
"Engine/TransparencyTemporalUpscalePS.hlsl";
36 effect = context->renderer->getEffectCache().loadEffect(context, desc);
40 buffers->annotate(parameterHandle,
"TemporalParameters");
47 for (
unsigned i = 0; i < 4; i++)
48 samplerState.borderColor[i] = 0.f;
49 sampler = textures->loadSamplerState(samplerState);
52void Cogs::Core::TransparencyTemporalUpscaleTask::cleanup(RenderTaskContext * context)
54 auto device = context->renderer->getDevice();
55 auto buffers = device->getBuffers();
56 auto textures = device->getTextures();
57 context->renderer->getEffectCache().release(context, effect);
58 buffers->releaseBuffer(parameterHandle);
59 textures->releaseSamplerState(sampler);
62void Cogs::Core::TransparencyTemporalUpscaleTask::apply(RenderTaskContext * taskContext)
64 RenderInstrumentationScope(taskContext->device->getImmediateContext(), SCOPE_RENDERING,
"TransparencyTemporalUpscaleTask::apply");
66 uint32_t frame = taskContext->context->time->getFrame();
67 uint32_t widthDivisor = taskContext->context->variables->get(
"renderer.oit.TemporalUpscaleWidth", 1);
68 uint32_t heightDivisor = taskContext->context->variables->get(
"renderer.oit.TemporalUpscaleHeight", 1);
70 auto device = taskContext->renderer->getDevice();
71 auto deviceContext = device->getImmediateContext();
73 auto depthTarget = input.resources[0].renderTarget;
74 auto oitTarget = input.resources[1].renderTarget;
75 auto historyTarget = input.resources[(frame+1)%2+2].renderTarget;
76 auto renderTarget = output.resources[frame%2].renderTarget;
79 deviceContext->setEffect(effect->handle);
81 deviceContext->setRenderTarget(renderTarget->renderTargetHandle, renderTarget->depthTargetHandle);
82 deviceContext->setViewport(0, 0,
static_cast<float>(renderTarget->width),
static_cast<float>(renderTarget->height));
84 deviceContext->setDepthStencilState(taskContext->states->noTestDepthStencilStateHandle);
85 deviceContext->setRasterizerState(taskContext->states->defaultRasterizerStateHandle);
87 deviceContext->setTexture(
"depthTexture", 0, depthTarget->depth->textureHandle);
88 deviceContext->setTexture(
"oitTexture", 0, oitTarget->textures[0]->textureHandle);
89 deviceContext->setTexture(
"historyTexture", 0, historyTarget->textures[0]->textureHandle);
90 deviceContext->setSamplerState(
"historySampler", 0, sampler);
96 auto& cameraData = taskContext->context->cameraSystem->getMainCameraData();
97 uint32_t i = frame % (widthDivisor * heightDivisor);
99 parameters->inverseClipToWorldMatrix = cameraData.inverseViewProjectionMatrix;
100 parameters->prevWorldToClipMatrix = cameraData.prevViewProjection;
101 parameters->width = widthDivisor;
102 parameters->height = heightDivisor;
103 parameters->off_x = i % widthDivisor;
104 parameters->off_y = (i / widthDivisor) % heightDivisor;
105 parameters->size_x = historyTarget->width;
106 parameters->size_y = historyTarget->height;
109 deviceContext->setConstantBuffer(
"TemporalParameters", parameterHandle);
111 deviceContext->setVertexBuffers(
nullptr, 0,
nullptr,
nullptr);
bool HandleIsValid(const ResourceHandle_t< T > &handle)
Check if the given resource is valid, that is not equal to NoHandle or InvalidHandle.
Contains all Cogs related functionality.
@ 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.
Contains an effect description used to load a single effect.
static const Handle_t NoHandle
Represents a handle to nothing.
@ WriteDiscard
Write access. When unmapping the graphics system will discard the old contents of the resource.
Provides RAII style mapping of a buffer resource.
@ TriangleList
List of triangles.
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.