1#include "PostProcessTask.h"
2#include "Resources/VertexFormats.h"
5#include "Renderer/Renderer.h"
6#include "Renderer/RenderTarget.h"
7#include "Systems/Core/CameraSystem.h"
9#include "Rendering/IGraphicsDevice.h"
10#include "Rendering/IContext.h"
11#include "Rendering/IBuffers.h"
13#include "Resources/ShaderBuilderPostProcess.h"
15#include <glm/gtc/type_ptr.hpp>
17#include "Foundation/Logging/Logger.h"
23 const char * names[] = {
33void Cogs::Core::PostProcessTask::initialize(RenderTaskContext* context)
35 ProcessTask::initialize(context);
38void Cogs::Core::PostProcessTask::initialize(RenderTaskContext * context,
const RenderTaskDefinition& taskDefinition)
40 ProcessTask::initialize(context, taskDefinition);
42 auto effects = context->device->getEffects();
45 desc.vs =
"Engine/FullscreenV3T2VS.hlsl";
47 for (
auto & p : effectParameter.values) {
48 if (p.key ==
"definitions") {
49 for (
auto & d : p.values) {
50 desc.definitions.push_back({ d.key, d.value });
53 if (p.key ==
"source") {
61 switch (graphicsDeviceType)
64 success = Cogs::Core::buildPostProcessEffectES3(context, desc,
this);
67 success = buildPostProcessEffectWebGPU(context, desc,
this);
70 success = buildPostProcessEffect(context, desc,
this);
74 LOG_ERROR(logger,
"Failed to build post processing shader source");
78 effect = context->renderer->getEffectCache().loadEffect(context, desc);
83 auto * buffers = context->device->getBuffers();
84 inputLayout = buffers->loadInputLayout(&VertexFormats::Pos4f, 1, effect->handle);
86 for (
size_t i = 0; i < 4; ++i) {
87 auto binding = effects->getSamplerStateBinding(effect->handle, names[i], 0);
90 samplerStateBindings[i] = binding;
91 samplerStates[i] = context->states->commonSamplerStates[i];
98void Cogs::Core::PostProcessTask::apply(RenderTaskContext * context)
100 if (scopeName.empty()) {
101 scopeName = std::string(
"PostProcessTask<") + name +
">::apply";
104 DynamicRenderInstrumentationScope(context->device->getImmediateContext(), SCOPE_RENDERING,
"PostProcessTask", scopeName.c_str());
106 RenderTarget* renderTarget = output.get(RenderResourceType::RenderTarget)->renderTarget;
116 auto deviceContext = context->device->getImmediateContext();
117 deviceContext->setEffect(effect->handle);
118 deviceContext->setRenderTarget(renderTarget->renderTargetHandle, renderTarget->depthTargetHandle);
121 if (clearToDefault) {
122 deviceContext->clearRenderTarget(glm::value_ptr(context->renderer->getBackgroundColor()));
124 deviceContext->clearRenderTarget(glm::value_ptr(renderTarget->getClearColor()));
129 deviceContext->clearDepth(context->renderer->getClearDepth());
133 if (viewportFromTarget) {
134 deviceContext->setViewport(0.0f, 0.0f,
static_cast<float>(renderTarget->width),
static_cast<float>(renderTarget->height));
138 deviceContext->setViewport(
139 context->cameraData->viewportOrigin.x, context->cameraData->viewportOrigin.y,
140 context->cameraData->viewportSize.x, context->cameraData->viewportSize.y
145 deviceContext->setDepthStencilState(context->states->noTestDepthStencilStateHandle);
147 deviceContext->setDepthStencilState(context->states->noDepthStencilStateHandle);
150 deviceContext->setRasterizerState(context->states->defaultRasterizerStateHandle);
152 for (
size_t i = 0; i < 4; ++i) {
154 deviceContext->setSamplerState(samplerStateBindings[i], samplerStates[i]);
158 setProperties(context);
161 deviceContext->setBlendState(context->states->blendStates[
size_t(
BlendMode::Zero)].handle);
164 deviceContext->setVertexBuffers(&context->states->fullScreenTriangle, 1);
166 deviceContext->setInputLayout(inputLayout);
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.
@ Zero
Disable all color writes.
constexpr Log getLogger(const char(&name)[LEN]) noexcept
Contains all Cogs related functionality.
GraphicsDeviceType
Contains types of graphics devices that may be supported.
@ OpenGLES30
Graphics device using the OpenGLES 3.0 API.
@ WebGPU
Graphics device using the WebGPU API Backend.
@ TriangleList
List of triangles.
Contains an effect description used to load a single effect.
static const Handle_t NoHandle
Represents a handle to nothing.