Lysa  0.0
Lysa 3D Engine
Renderer Class Referenceabstract

Detailed Description

High-level scene renderer.

Owns and manages the set of render passes required by a rendering path (depth pre-pass, opaque/transparent color, shader-material passes, post-processing). Allocates per-frame color/depth attachments and exposes them to callers. Updates and rebuilds graphics pipelines when the set of materials changes.

+ Inheritance diagram for Renderer:

Classes

struct  FrameData
 

Public Member Functions

virtual std::shared_ptr< vireo::RenderTarget > getColorRenderTarget (const uint32 frameIndex) const
 
auto getColorAttachment (const uint32 frameIndex) const
 
auto getDepthAttachment (const uint32 frameIndex) const
 
std::shared_ptr< vireo::Image > getCurrentColorAttachment (uint32 frameIndex) const
 
virtual std::shared_ptr< vireo::Image > getBrightnessAttachment (uint32 frameIndex) const = 0
 
virtual void resize (const vireo::Extent &extent, const std::shared_ptr< vireo::CommandList > &commandList)
 
void updatePipelines (const SceneFrameData &scene)
 
virtual void updatePipelines (const std::unordered_map< pipeline_id, std::vector< unique_id >> &pipelineIds)
 
virtual void update (uint32 frameIndex)
 
void prepare (const std::shared_ptr< vireo::CommandList > &commandList, const SceneFrameData &scene, const vireo::Viewport &viewport, const vireo::Rect &scissors, uint32 frameIndex)
 
void render (const std::shared_ptr< vireo::CommandList > &commandList, const SceneFrameData &scene, const vireo::Viewport &viewport, const vireo::Rect &scissors, bool clearAttachment, uint32 frameIndex)
 
std::shared_ptr< vireo::Image > postprocessBloom (const std::shared_ptr< vireo::CommandList > &commandList, uint32 frameIndex) const
 
std::shared_ptr< vireo::Image > postprocess (const std::shared_ptr< vireo::CommandList > &commandList, const std::shared_ptr< vireo::Image > &colorAttachment, uint32 frameIndex)
 
std::shared_ptr< vireo::Image > postprocessAA (const std::shared_ptr< vireo::CommandList > &commandList, const std::shared_ptr< vireo::Image > &colorAttachment, uint32 frameIndex) const
 
void renderCustomRenderPasses (const std::shared_ptr< vireo::CommandList > &commandList, const SceneFrameData &scene, RenderingPhase stage, uint32 frameIndex)
 
void addPostprocessing (FullScreenCompute &postProcessingPass)
 
void removePostprocessing (const std::string &fragShaderName)
 
void removePostprocessing (const FullScreenCompute &postProcessingPass)
 
void addRenderPass (RenderingPhase phase, CustomRenderpass &pass)
 
void removeRenderPass (RenderingPhase phase, const CustomRenderpass &pass)
 
TransparencyPassgetTransparencyPass ()
 
FXAAPassgetFXAAPass () const
 
SMAAPassgetSMAAPass () const
 
BloomPassgetBloomPass () const
 
GammaCorrectionPassgetGammaCorrectionPass () const
 
vireo::ImageFormat getOutputFormat () const
 
const auto & getExtent () const
 
virtual ~Renderer () = default
 
 Renderer (Renderer &) = delete
 
Renderer & operator= (Renderer &) = delete
 

Static Public Member Functions

static std::unique_ptr< Renderer > create (const RendererConfiguration &config, vireo::ImageFormat outputFormat)
 

Protected Member Functions

 Renderer (const RendererConfiguration &config, vireo::ImageFormat outputFormat)
 
virtual void colorPass (const std::shared_ptr< vireo::CommandList > &commandList, const SceneFrameData &scene, const vireo::Viewport &viewport, const vireo::Rect &scissors, bool clearAttachment, uint32 frameIndex) = 0
 

Protected Attributes

const bool withStencil
 True if stencil testing must be enabled. More...
 
const RendererConfiguration config
 Global rendering configuration. More...
 
vireo::ImageFormat outputFormat
 Final output format after the gamma/tonemapping pass. More...
 
std::vector< FrameDataframesData
 Per-frame attachment data, one entry per frame in flight. More...
 
DepthPrepass depthPrePass
 Depth-only pre-pass shared by forward and deferred renderers. More...
 

Constructor & Destructor Documentation

virtual ~Renderer ( )
virtualdefault
Renderer ( Renderer &  )
delete
Renderer ( const RendererConfiguration config,
vireo::ImageFormat  outputFormat 
)
protected

Constructs the base renderer, allocating per-frame attachments.

Parameters
configRendering configuration.
outputFormatColor format of the final output attachment.

Member Function Documentation

void addPostprocessing ( FullScreenCompute postProcessingPass)

Adds a full-screen compute post-processing pass to the pipeline. The pass is inserted after the color and bloom passes, but before the AA pass. The caller retains ownership; the pass must outlive the Renderer.

Parameters
postProcessingPassThe compute pass to add.
void addRenderPass ( RenderingPhase  phase,
CustomRenderpass pass 
)

Registers a custom render pass to be executed at the given RenderingPhase, after the built-in ShaderMaterialPass for that phase. The caller retains ownership; the pass must outlive the Renderer.

Parameters
phaseThe RenderingPhase slot to attach to.
passThe custom pass to register.
virtual void colorPass ( const std::shared_ptr< vireo::CommandList > &  commandList,
const SceneFrameData scene,
const vireo::Viewport &  viewport,
const vireo::Rect &  scissors,
bool  clearAttachment,
uint32  frameIndex 
)
protectedpure virtual

Records the pipeline-specific color pass for the concrete renderer. Implementations dispatch scene draws into colorAttachment and depthAttachment.

Parameters
commandListCommand list to record into.
scenePer-frame scene data.
viewportViewport rectangle for this frame.
scissorsScissor rectangle for this frame.
clearAttachmentIf true, the color attachment is cleared before rendering.
frameIndexIndex of the frame in flight.

Implemented in lysa::DeferredRenderer::colorPass(), lysa::ForwardRenderer::colorPass()

static std::unique_ptr<Renderer> create ( const RendererConfiguration config,
vireo::ImageFormat  outputFormat 
)
static

Factory method: creates a concrete Renderer (forward or deferred) from configuration.

Parameters
configRendering configuration (attachments, frames in flight, feature flags).
outputFormatColor format of the final output attachment after tonemapping.
Returns
Owning pointer to the newly created Renderer instance.
BloomPass& getBloomPass ( ) const
inline

Returns the bloom post-processing pass.

virtual std::shared_ptr<vireo::Image> getBrightnessAttachment ( uint32  frameIndex) const
pure virtual

Returns the brightness buffer used as input for the bloom extraction pass.

Parameters
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the brightness image.

Implemented in lysa::DeferredRenderer::getBrightnessAttachment(), lysa::ForwardRenderer::getBrightnessAttachment()

auto getColorAttachment ( const uint32  frameIndex) const
inline

Returns the raw color image attachment for a given frame.

Parameters
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the color image.
virtual std::shared_ptr<vireo::RenderTarget> getColorRenderTarget ( const uint32  frameIndex) const
inlinevirtual

Returns the color render target for a given frame. Overridden by subclasses that apply a TAA or sharpening pass as the final step.

Parameters
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the color render target.

Reimplemented in lysa::DeferredRenderer::getColorRenderTarget()

std::shared_ptr<vireo::Image> getCurrentColorAttachment ( uint32  frameIndex) const

Returns the color attachment that will be consumed by the next post-processing step. This may differ from the raw color attachment when a TAA or sharpening pass is active.

Parameters
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the current color image.
auto getDepthAttachment ( const uint32  frameIndex) const
inline

Returns the depth render target for a given frame.

Parameters
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the depth render target.
const auto& getExtent ( ) const
inline

Returns the current rendering extent (swap chain extent or configured rendering resolution).

FXAAPass& getFXAAPass ( ) const
inline

Returns the FXAA post-processing pass.

GammaCorrectionPass& getGammaCorrectionPass ( ) const
inline

Returns the gamma correction post-processing pass.

vireo::ImageFormat getOutputFormat ( ) const
inline

Returns the final output format, used after the tonemapping pass.

SMAAPass& getSMAAPass ( ) const
inline

Returns the SMAA post-processing pass.

TransparencyPass& getTransparencyPass ( )
inline

Returns the transparency (order-independent blending) pass.

Renderer& operator= ( Renderer &  )
delete
std::shared_ptr<vireo::Image> postprocess ( const std::shared_ptr< vireo::CommandList > &  commandList,
const std::shared_ptr< vireo::Image > &  colorAttachment,
uint32  frameIndex 
)

Applies the full post-processing chain, including tonemapping and gamma correction.

Parameters
commandListCommand list to record into.
colorAttachmentInput color image to process.
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the final tonemapped and gamma-corrected image.
std::shared_ptr<vireo::Image> postprocessAA ( const std::shared_ptr< vireo::CommandList > &  commandList,
const std::shared_ptr< vireo::Image > &  colorAttachment,
uint32  frameIndex 
) const

Applies the configured anti-aliasing post-processing pass (FXAA or SMAA).

Parameters
commandListCommand list to record into.
colorAttachmentInput color image to anti-alias.
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the anti-aliased output image.
std::shared_ptr<vireo::Image> postprocessBloom ( const std::shared_ptr< vireo::CommandList > &  commandList,
uint32  frameIndex 
) const

Applies the bloom pass to the current color attachment.

Parameters
commandListCommand list to record into.
frameIndexIndex of the frame in flight.
Returns
Shared pointer to the image produced by the bloom pass.
void prepare ( const std::shared_ptr< vireo::CommandList > &  commandList,
const SceneFrameData scene,
const vireo::Viewport &  viewport,
const vireo::Rect &  scissors,
uint32  frameIndex 
)

Pre-render stage: uploads scene data, performs layout transitions, records the depth pre-pass, and renders shadow maps.

Parameters
commandListCommand list to record into.
scenePer-frame scene data (transforms, lights, camera).
viewportViewport rectangle for this frame.
scissorsScissor rectangle for this frame.
frameIndexIndex of the frame in flight.
void removePostprocessing ( const FullScreenCompute postProcessingPass)
inline

Removes a previously added post-processing pass. A pass not found is silently ignored.

Parameters
postProcessingPassThe pass to remove.
void removePostprocessing ( const std::string &  fragShaderName)

Removes a previously added post-processing pass identified by its compute shader name. A pass not found is silently ignored.

Parameters
fragShaderNameThe compute shader name used to identify the pass.
void removeRenderPass ( RenderingPhase  phase,
const CustomRenderpass pass 
)

Removes a previously registered custom render pass from the given phase. A pass not registered for that phase is silently ignored.

Parameters
phaseThe RenderingPhase slot to detach from.
passThe custom pass to remove.
void render ( const std::shared_ptr< vireo::CommandList > &  commandList,
const SceneFrameData scene,
const vireo::Viewport &  viewport,
const vireo::Rect &  scissors,
bool  clearAttachment,
uint32  frameIndex 
)

Main render stage: records opaque and transparent draw calls.

Parameters
commandListCommand list to record into.
scenePer-frame scene data (transforms, lights, camera).
viewportViewport rectangle for this frame.
scissorsScissor rectangle for this frame.
clearAttachmentIf true, the color attachment is cleared before rendering.
frameIndexIndex of the frame in flight.
void renderCustomRenderPasses ( const std::shared_ptr< vireo::CommandList > &  commandList,
const SceneFrameData scene,
RenderingPhase  stage,
uint32  frameIndex 
)

Executes all custom render passes registered for the given pipeline stage.

Parameters
commandListCommand list to record into.
scenePer-frame scene data.
stageThe RenderingPhase whose custom passes should be executed.
frameIndexIndex of the frame in flight.
virtual void resize ( const vireo::Extent &  extent,
const std::shared_ptr< vireo::CommandList > &  commandList 
)
virtual

Recreates attachments and pipelines after a render target resize.

Parameters
extentNew swap chain extent.
commandListCommand list used for any required layout transitions or copies.

Reimplemented in lysa::DeferredRenderer::resize(), lysa::ForwardRenderer::resize()

virtual void update ( uint32  frameIndex)
virtual

Performs per-frame housekeeping such as pass-local data uploads.

Parameters
frameIndexIndex of the frame in flight.

Reimplemented in lysa::ForwardRenderer::update(), lysa::DeferredRenderer::update()

void updatePipelines ( const SceneFrameData scene)

Updates graphics pipelines according to the Scene material mapping. Convenience overload that pulls the mapping from the provided SceneFrameData.

Parameters
sceneCurrent frame scene data containing the pipeline-to-material mapping.
virtual void updatePipelines ( const std::unordered_map< pipeline_id, std::vector< unique_id >> &  pipelineIds)
virtual

Updates graphics pipelines according to the provided materials mapping.

Parameters
pipelineIdsMap of pipeline family id to the list of material unique ids.

Reimplemented in lysa::DeferredRenderer::updatePipelines(), lysa::ForwardRenderer::updatePipelines()

Member Data Documentation

const RendererConfiguration config
protected

Global rendering configuration.

DepthPrepass depthPrePass
protected

Depth-only pre-pass shared by forward and deferred renderers.

std::vector<FrameData> framesData
protected

Per-frame attachment data, one entry per frame in flight.

vireo::ImageFormat outputFormat
protected

Final output format after the gamma/tonemapping pass.

const bool withStencil
protected

True if stencil testing must be enabled.