// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
#pragma once
#include "RendererPass.h"
#include "Engine/Graphics/GPUPipelineStatePermutations.h"
#include "Engine/Content/Assets/Model.h"
#include "Engine/Content/Assets/Shader.h"
///
/// Screen Space Reflections rendering service
///
///
/// The following implementation is using Stochastic Screen-Space Reflections algorithm based on:
/// https://www.slideshare.net/DICEStudio/stochastic-screenspace-reflections
/// It's well optimized and provides solid visual effect.
///
/// Algorithm steps:
/// 1) Downscale depth [optional]
/// 2) Ray trace
/// 3) Resolve rays
/// 4) Temporal blur [optional]
/// 5) Combine final image (alpha blend into reflections buffer)
///
///
class ScreenSpaceReflectionsPass : public RendererPass
{
private:
AssetReference _shader;
GPUPipelineState* _psRayTracePass;
GPUPipelineState* _psCombinePass;
GPUPipelineStatePermutationsPs<4> _psResolvePass;
GPUPipelineState* _psTemporalPass;
GPUPipelineState* _psMixPass;
AssetReference _preIntegratedGF;
public:
///
/// Init
///
ScreenSpaceReflectionsPass();
public:
///
/// Determinates whenever this pass requires motion vectors rendering.
///
/// The rendering context.
/// True if need to render motion vectors, otherwise false.
static bool NeedMotionVectors(RenderContext& renderContext);
///
/// Perform SSR rendering for the input task (blends reflections to given texture using alpha blending).
///
/// The rendering context.
/// Temporary buffer to use for the reflections pass
/// Light buffer
void Render(RenderContext& renderContext, GPUTextureView* reflectionsRT, GPUTextureView* lightBuffer);
private:
#if COMPILE_WITH_DEV_ENV
void OnShaderReloading(Asset* obj)
{
_psRayTracePass->ReleaseGPU();
_psCombinePass->ReleaseGPU();
_psResolvePass.Release();
_psTemporalPass->ReleaseGPU();
_psMixPass->ReleaseGPU();
invalidateResources();
}
#endif
public:
// [RendererPass]
String ToString() const override;
bool Init() override;
void Dispose() override;
protected:
// [RendererPass]
bool setupResources() override;
};