// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "RendererPass.h" #include "Engine/Graphics/GPUPipelineStatePermutations.h" #define GB_RADIUS 6 #define GB_KERNEL_SIZE (GB_RADIUS * 2 + 1) /// /// Post processing rendering service /// class PostProcessingPass : public RendererPass { private: PACK_STRUCT(struct Data { float BloomLimit; float BloomThreshold; float BloomMagnitude; float BloomBlurSigma; Float3 VignetteColor; float VignetteShapeFactor; Float2 InputSize; float InputAspect; float GrainAmount; float GrainTime; float GrainParticleSize; int32 Ghosts; float HaloWidth; float HaloIntensity; float Distortion; float GhostDispersal; float LensFlareIntensity; Float2 LensInputDistortion; float LensScale; float LensBias; Float2 InvInputSize; float ChromaticDistortion; float Time; float Dummy1; float PostExposure; float VignetteIntensity; float LensDirtIntensity; Color ScreenFadeColor; Matrix LensFlareStarMat; }); PACK_STRUCT(struct GaussianBlurData { Float2 Size; float Dummy3; float Dummy4; Float4 GaussianBlurCache[GB_KERNEL_SIZE]; // x-weight, y-offset }); // Post Processing AssetReference _shader; GPUPipelineState* _psThreshold; GPUPipelineState* _psScale; GPUPipelineState* _psBlurH; GPUPipelineState* _psBlurV; GPUPipelineState* _psGenGhosts; GPUPipelineStatePermutationsPs<3> _psComposite; GaussianBlurData _gbData; Float4 GaussianBlurCacheH[GB_KERNEL_SIZE]; Float4 GaussianBlurCacheV[GB_KERNEL_SIZE]; AssetReference _defaultLensColor; AssetReference _defaultLensStar; AssetReference _defaultLensDirt; public: /// /// Init /// PostProcessingPass(); public: /// /// Perform postFx rendering for the input task /// /// The rendering context. /// Target with rendered HDR frame to post process /// Output frame /// The prebaked LUT for color grading and tonemapping. void Render(RenderContext& renderContext, GPUTexture* input, GPUTexture* output, GPUTexture* colorGradingLUT); private: GPUTexture* getCustomOrDefault(Texture* customTexture, AssetReference& defaultTexture, const Char* defaultName); /// /// Calculates the Gaussian blur filter kernel. This implementation is /// ported from the original Java code appearing in chapter 16 of /// "Filthy Rich Clients: Developing Animated and Graphical Effects for Desktop Java". /// /// Gaussian Blur sigma parameter /// Texture to blur width in pixels /// Texture to blur height in pixels void GB_ComputeKernel(float sigma, float width, float height); #if COMPILE_WITH_DEV_ENV void OnShaderReloading(Asset* obj) { _psThreshold->ReleaseGPU(); _psScale->ReleaseGPU(); _psBlurH->ReleaseGPU(); _psBlurV->ReleaseGPU(); _psGenGhosts->ReleaseGPU(); _psComposite.Release(); invalidateResources(); } #endif public: // [RendererPass] String ToString() const override; bool Init() override; void Dispose() override; protected: // [RendererPass] bool setupResources() override; };