// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "../RendererPass.h" #include "Engine/Graphics/GPUContext.h" #include "Engine/Graphics/GPUPipelineStatePermutations.h" /// /// Scales an input texture to an output texture (down or up, depending on the relative size between input and output). Can perform image blurring. /// class MultiScaler : public RendererPass { private: AssetReference _shader; GPUPipelineStatePermutationsPs<2> _psBlur5; GPUPipelineStatePermutationsPs<2> _psBlur9; GPUPipelineStatePermutationsPs<2> _psBlur13; GPUPipelineStatePermutationsPs<3> _psHalfDepth; GPUPipelineState* _psUpscale = nullptr; public: /// /// Filter mode /// enum class FilterMode { /// /// Optimized 5-tap gaussian blur with linear sampling (3 texture fetches). /// GaussianBlur5 = 1, /// /// Optimized 9-tap gaussian blur with linear sampling (5 texture fetches). /// GaussianBlur9 = 2, /// /// Optimized 13-tap gaussian blur with linear sampling (7 texture fetches). /// GaussianBlur13 = 3, }; /// /// Performs texture filtering. /// /// The filter mode. /// The context. /// The output width. /// The output height. /// The source texture. /// The destination texture. /// The temporary texture (should have the same size as destination texture). void Filter(FilterMode mode, GPUContext* context, int32 width, int32 height, GPUTextureView* src, GPUTextureView* dst, GPUTextureView* tmp); /// /// Performs texture filtering. /// /// The filter mode. /// The context. /// The output width. /// The output height. /// The source and destination texture. /// The temporary texture (should have the same size as destination texture). void Filter(FilterMode mode, GPUContext* context, int32 width, int32 height, GPUTextureView* srcDst, GPUTextureView* tmp); /// /// Downscales the depth buffer (to half resolution). Uses `min` operator (`max` for inverted depth) to output the furthest depths for conservative usage. /// /// The context. /// The width of the destination texture (in pixels). /// The height of the destination texture (in pixels). /// The source texture (has to have ShaderResource flag). /// The destination texture (has to have DepthStencil or RenderTarget flag). void DownscaleDepth(GPUContext* context, int32 dstWidth, int32 dstHeight, GPUTexture* src, GPUTextureView* dst); /// /// Generates the Hierarchical Z-Buffer (HiZ). Uses `min` operator (`max` for inverted depth) to output the furthest depths for conservative usage. /// /// The context. /// The source depth buffer texture (has to have ShaderResource flag). /// The destination HiZ texture (has to have DepthStencil or RenderTarget flag). void BuildHiZ(GPUContext* context, GPUTexture* srcDepth, GPUTexture* dstHiZ); /// /// Upscales the texture. /// /// The context. /// The viewport of the destination texture. /// The source texture. /// The destination texture. void Upscale(GPUContext* context, const Viewport& viewport, GPUTexture* src, GPUTextureView* dst); public: // [RendererPass] String ToString() const override; bool Init() override; void Dispose() override; #if COMPILE_WITH_DEV_ENV void OnShaderReloading(Asset* obj) { _psUpscale->ReleaseGPU(); _psBlur5.Release(); _psBlur9.Release(); _psBlur13.Release(); _psHalfDepth.Release(); invalidateResources(); } #endif protected: // [RendererPass] bool setupResources() override; };