// Copyright (c) 2012-2023 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; GPUPipelineState* _psHalfDepth = nullptr; GPUPipelineStatePermutationsPs<2> _psBlur5; GPUPipelineStatePermutationsPs<2> _psBlur9; GPUPipelineStatePermutationsPs<2> _psBlur13; 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(const FilterMode mode, GPUContext* context, const int32 width, const 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(const FilterMode mode, GPUContext* context, const int32 width, const int32 height, GPUTextureView* srcDst, GPUTextureView* tmp); /// /// Downscales the depth buffer (to half resolution). /// /// The context. /// The width of the destination texture (in pixels). /// The height of the destination texture (in pixels). /// The source texture. /// The destination texture. void DownscaleDepth(GPUContext* context, int32 dstWidth, int32 dstHeight, GPUTexture* src, GPUTextureView* dst); /// /// 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) { _psHalfDepth->ReleaseGPU(); _psUpscale->ReleaseGPU(); _psBlur5.Release(); _psBlur9.Release(); _psBlur13.Release(); invalidateResources(); } #endif protected: // [RendererPass] bool setupResources() override; };