// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "Engine/Graphics/RenderView.h" #include "Engine/Graphics/GPUPipelineStatePermutations.h" #include "RendererPass.h" #include "Engine/Content/Assets/Shader.h" #include "Engine/Content/Assets/Model.h" /// /// Lighting rendering service. Handles dynamic lights diffuse and specular color calculations. /// class LightPass : public RendererPass { private: AssetReference _shader; GPUPipelineStatePermutationsPs<2> _psLightDir; GPUPipelineStatePermutationsPs<4> _psLightLocal; GPUPipelineStatePermutationsPs<4> _psLightLocalInside; GPUPipelineState* _psLightSky = nullptr; GPUPipelineState* _psLightSkyInside = nullptr; GPUPipelineState* _psClearDiffuse = nullptr; GPUPipelineState* _psComplexity = nullptr; GPUPipelineState* _psLightOverlap[2] = {}; AssetReference _sphereModel; PixelFormat _shadowMaskFormat; bool _depthBounds = false; public: /// /// Setups the lights rendering for batched scene drawing. /// void SetupLights(RenderContext& renderContext, RenderContextBatch& renderContextBatch); /// /// Performs the lighting rendering for the input task. /// /// The rendering context batch. /// The light accumulation buffer (input and output). void RenderLights(RenderContextBatch& renderContextBatch, GPUTextureView* lightBuffer); #if GPU_ENABLE_DEVELOPMENT /// /// Renders the debug view. /// /// The rendering context. /// The GPU context. /// The output buffer. void RenderDebug(RenderContext& renderContext, GPUContext* context, GPUTexture* output); #endif private: #if COMPILE_WITH_DEV_ENV void OnShaderReloading(Asset* obj) { _psLightDir.Release(); _psLightLocal.Release(); _psLightLocalInside.Release(); _psLightSky->ReleaseGPU(); _psLightSkyInside->ReleaseGPU(); if (_psClearDiffuse) _psClearDiffuse->ReleaseGPU(); SAFE_DELETE_GPU_RESOURCE(_psComplexity); SAFE_DELETE_GPU_RESOURCE(_psLightOverlap[0]); SAFE_DELETE_GPU_RESOURCE(_psLightOverlap[1]); invalidateResources(); } #endif #if GPU_ENABLE_DEVELOPMENT void RenderDebugSphere(RenderContext& renderContext, GPUContext* context, const struct RenderLightData& light, float radius) const; #endif public: // [RendererPass] String ToString() const override; bool Init() override; void Dispose() override; protected: // [RendererPass] bool setupResources() override; };