// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. #pragma once #include "../RendererPass.h" #include "Engine/Core/Math/Int4.h" #include "Engine/Graphics/Textures/GPUTexture.h" /// /// Dynamic Diffuse Global Illumination rendering pass. /// class FLAXENGINE_API DynamicDiffuseGlobalIlluminationPass : public RendererPass { public: // Constant buffer data for DDGI access on a GPU. PACK_STRUCT(struct ConstantsData { Float4 ProbesOriginAndSpacing[4]; Int4 ProbesScrollOffsets[4]; uint32 ProbesCounts[3]; uint32 CascadesCount; float IrradianceGamma; float ProbeHistoryWeight; float RayMaxDistance; float IndirectLightingIntensity; Float4 RaysRotation; Float3 ViewPos; uint32 RaysCount; Float3 FallbackIrradiance; float Padding0; }); // Binding data for the GPU. struct BindingData { ConstantsData Constants; GPUTextureView* ProbesData; GPUTextureView* ProbesDistance; GPUTextureView* ProbesIrradiance; }; private: bool _supported = false; AssetReference _shader; GPUConstantBuffer* _cb0 = nullptr; GPUConstantBuffer* _cb1 = nullptr; GPUShaderProgramCS* _csClassify; GPUShaderProgramCS* _csUpdateProbesInitArgs; GPUShaderProgramCS* _csTraceRays[4]; GPUShaderProgramCS* _csUpdateProbesIrradiance; GPUShaderProgramCS* _csUpdateProbesDistance; GPUShaderProgramCS* _csUpdateBordersIrradianceRow; GPUShaderProgramCS* _csUpdateBordersIrradianceCollumn; GPUShaderProgramCS* _csUpdateBordersDistanceRow; GPUShaderProgramCS* _csUpdateBordersDistanceCollumn; GPUPipelineState* _psIndirectLighting; #if USE_EDITOR AssetReference _debugModel; AssetReference _debugMaterial; #endif public: /// /// Gets the DDGI binding data (only if enabled). /// /// The rendering context buffers. /// The result DDGI data for binding to the shaders. /// True if failed to render (platform doesn't support it, out of video memory, disabled feature or effect is not ready), otherwise false. bool Get(const RenderBuffers* buffers, BindingData& result); /// /// Renders the DDGI. /// /// The rendering context. /// The GPU context. /// The light accumulation buffer (input and output). /// True if failed to render (platform doesn't support it, out of video memory, disabled feature or effect is not ready), otherwise false. bool Render(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer); private: #if COMPILE_WITH_DEV_ENV uint64 LastFrameShaderReload = 0; void OnShaderReloading(Asset* obj); #endif bool RenderInner(RenderContext& renderContext, GPUContext* context, class DDGICustomBuffer& ddgiData); public: // [RendererPass] String ToString() const override; bool Init() override; void Dispose() override; protected: // [RendererPass] bool setupResources() override; };