// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "RendererPass.h"
///
/// Global Surface Atlas rendering pass. Captures scene geometry into a single atlas texture which contains surface diffuse color, normal vector, emission light, and calculates direct+indirect lighting. Used by Global Illumination and Reflections.
///
class FLAXENGINE_API GlobalSurfaceAtlasPass : public RendererPass
{
public:
// Constant buffer data for Global Surface Atlas access on a GPU.
PACK_STRUCT(struct GlobalSurfaceAtlasData
{
Vector3 Padding;
uint32 ObjectsCount;
});
// Binding data for the GPU.
struct BindingData
{
GPUTexture* Atlas[5];
GPUBuffer* Objects;
GlobalSurfaceAtlasData GlobalSurfaceAtlas;
};
private:
bool _supported = false;
AssetReference _shader;
GPUPipelineState* _psClear = nullptr;
GPUPipelineState* _psDebug = nullptr;
GPUConstantBuffer* _cb0 = nullptr;
// Rasterization cache
class DynamicVertexBuffer* _vertexBuffer = nullptr;
Array> _dirtyObjectsBuffer;
public:
///
/// Renders the Global Surface Atlas.
///
/// The rendering context.
/// The GPU context.
/// The result Global Surface Atlas 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 Render(RenderContext& renderContext, GPUContext* context, BindingData& result);
///
/// Renders the debug view.
///
/// The rendering context.
/// The GPU context.
/// The output buffer.
void RenderDebug(RenderContext& renderContext, GPUContext* context, GPUTexture* output);
private:
#if COMPILE_WITH_DEV_ENV
void OnShaderReloading(Asset* obj);
#endif
public:
// [RendererPass]
String ToString() const override;
bool Init() override;
void Dispose() override;
protected:
// [RendererPass]
bool setupResources() override;
};