// Copyright (c) 2012-2023 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:
GPUPipelineStatePermutationsPs<2> _psRayTracePass;
GPUPipelineStatePermutationsPs<4> _psResolvePass;
GPUPipelineState* _psCombinePass = nullptr;
GPUPipelineState* _psTemporalPass = nullptr;
GPUPipelineState* _psMixPass = nullptr;
AssetReference _shader;
AssetReference _preIntegratedGF;
public:
///
/// 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);
#endif
public:
// [RendererPass]
String ToString() const override;
bool Init() override;
void Dispose() override;
protected:
// [RendererPass]
bool setupResources() override;
};