// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. #pragma once #include "RendererPass.h" #if USE_EDITOR #include "Engine/Core/Collections/Dictionary.h" #endif /// /// Rendering scene to the GBuffer /// class GBufferPass : public RendererPass { private: AssetReference _gBufferShader; GPUPipelineState* _psDebug = nullptr; AssetReference _skyModel; AssetReference _boxModel; #if USE_EDITOR class LightmapUVsDensityMaterialShader* _lightmapUVsDensity = nullptr; class VertexColorsMaterialShader* _vertexColors = nullptr; class LODPreviewMaterialShader* _lodPreview = nullptr; class MaterialComplexityMaterialShader* _materialComplexity = nullptr; #endif public: /// /// Fill GBuffer /// /// The rendering context. /// Light buffer to output material emissive light and precomputed indirect lighting void Fill(RenderContext& renderContext, GPUTexture* lightBuffer); /// /// Render debug view /// /// The rendering context. void RenderDebug(RenderContext& renderContext); /// /// Renders the sky or skybox into low-resolution cubemap. Can be used to sample realtime sky lighting in GI passes. /// /// The rendering context. /// The GPU context. /// Rendered cubemap or null if not ready or failed. GPUTextureView* RenderSkybox(RenderContext& renderContext, GPUContext* context); #if USE_EDITOR // Temporary cache for faster debug previews drawing (used only during frame rendering). static Dictionary IndexBufferToModelLOD; static CriticalSection Locker; FORCE_INLINE static void AddIndexBufferToModelLOD(GPUBuffer* indexBuffer, const ModelLOD* modelLod) { Locker.Lock(); IndexBufferToModelLOD[indexBuffer] = modelLod; Locker.Unlock(); } void PreOverrideDrawCalls(RenderContext& renderContext); void OverrideDrawCalls(RenderContext& renderContext); void DrawMaterialComplexity(RenderContext& renderContext, GPUContext* context, GPUTextureView* lightBuffer); #endif public: static bool IsDebugView(ViewMode mode); /// /// Set GBuffer inputs structure for given render task /// /// The rendering view. /// GBuffer input to setup static void SetInputs(const RenderView& view, GBufferData& gBuffer); private: void DrawSky(RenderContext& renderContext, GPUContext* context); void DrawDecals(RenderContext& renderContext, GPUTextureView* lightBuffer); #if COMPILE_WITH_DEV_ENV void OnShaderReloading(Asset* obj) { _psDebug->ReleaseGPU(); invalidateResources(); } #endif public: // [RendererPass] String ToString() const override; bool Init() override; void Dispose() override; protected: // [RendererPass] bool setupResources() override; };