API Documentation
Public Member Functions | Static Public Member Functions | List of all members
nkAstraeus::SsaoEffect Class Referencefinal

A Screen Space Ambient Occlusion effect. More...

Inheritance diagram for nkAstraeus::SsaoEffect:
nkAstraeus::Effect

Public Member Functions

 SsaoEffect (System *system) noexcept
 
virtual ~SsaoEffect ()
 
virtual EFFECT_TYPE getType () const override
 
nkGraphics::TexturegetPositionBuffer () const
 
nkGraphics::TexturegetNormalBuffer () const
 
nkGraphics::TexturegetDepthBuffer () const
 
bool getLinearDepth () const
 
nkGraphics::CameragetCamera () const
 
float getSamplingRadius () const
 
float getMaxOcclusionDistance () const
 
float getStrength () const
 
float getDepthBias () const
 
unsigned int getKernelSampleCount () const
 
bool getOcclusionDrivesAlpha () const
 
void setEffectFromGBufferInfo (nkGraphics::Texture *positionBuffer, nkGraphics::Texture *normalBuffer=nullptr)
 
void setEffectFromDepthInfo (nkGraphics::Texture *depthBuffer, bool linearDepth=false)
 
void setCamera (nkGraphics::Camera *value)
 
void setSamplingRadius (float value)
 
void setMaxOcclusionDistance (float value)
 
void setStrength (float value)
 
void setDepthBias (float value)
 
void setKernelSampleCount (unsigned int value)
 
void setOcclusionDrivesAlpha (bool value)
 
virtual bool load () override
 
virtual void unload () override
 
- Public Member Functions inherited from nkAstraeus::Effect
 Effect (EFFECT_TYPE type) noexcept
 
virtual ~Effect ()
 
nkMemory::StringView getName () const
 
nkGraphics::ShadergetShader () const
 
EFFECT_TYPE getType () const
 
void setName (nkMemory::StringView value)
 

Static Public Member Functions

static nkMemory::UniquePtr< SsaoEffectcreate (System *system=nullptr)
 

Detailed Description

A Screen Space Ambient Occlusion effect.

This effect will darken edges on generally occluded spots, based on image information given. This helps in giving a sense of depth to the image, settling objects together as their contact points are made obvious.
However, this technique can suffer from artifacts and haloing around objects as an image lacks geometrical information usually needed with this kind of effects. But what it loses through approximations directly pours into performances, making it a very good effect for real-time applications.

Constructor & Destructor Documentation

◆ SsaoEffect()

nkAstraeus::SsaoEffect::SsaoEffect ( System system)
noexcept

Default constructor. Alternatively, see SsaoEffect::create(), or EffectManager::createOrRetrieve().

Parameters
systemThe system the resource should live in.

◆ ~SsaoEffect()

virtual nkAstraeus::SsaoEffect::~SsaoEffect ( )
virtual

Destructor.

Member Function Documentation

◆ getType()

virtual EFFECT_TYPE nkAstraeus::SsaoEffect::getType ( ) const
overridevirtual
Returns
The type of the effect, in this case EFFECT_TYPE::SSAO.

◆ getPositionBuffer()

nkGraphics::Texture* nkAstraeus::SsaoEffect::getPositionBuffer ( ) const
Returns
The G-Buffer part currently used as the position buffer.

◆ getNormalBuffer()

nkGraphics::Texture* nkAstraeus::SsaoEffect::getNormalBuffer ( ) const
Returns
The G-Buffer part currently used as the normal buffer.

◆ getDepthBuffer()

nkGraphics::Texture* nkAstraeus::SsaoEffect::getDepthBuffer ( ) const
Returns
The currently used depth buffer.

◆ getLinearDepth()

bool nkAstraeus::SsaoEffect::getLinearDepth ( ) const
Returns
Whether the depth is interpreted linearly (true) or not (false).

◆ getCamera()

nkGraphics::Camera* nkAstraeus::SsaoEffect::getCamera ( ) const
Returns
The camera used if any, nullptr else.

◆ getSamplingRadius()

float nkAstraeus::SsaoEffect::getSamplingRadius ( ) const
Returns
The current sampling radius.

◆ getMaxOcclusionDistance()

float nkAstraeus::SsaoEffect::getMaxOcclusionDistance ( ) const
Returns
The current max occlusion distance.

◆ getStrength()

float nkAstraeus::SsaoEffect::getStrength ( ) const
Returns
The current strength of the effect.

◆ getDepthBias()

float nkAstraeus::SsaoEffect::getDepthBias ( ) const
Returns
The current depth bias.

◆ getKernelSampleCount()

unsigned int nkAstraeus::SsaoEffect::getKernelSampleCount ( ) const
Returns
The current sample count used for the kernel.

◆ getOcclusionDrivesAlpha()

bool nkAstraeus::SsaoEffect::getOcclusionDrivesAlpha ( ) const
Returns
Whether the occlusion currently drives the alpha component (true) or not (false).

◆ setEffectFromGBufferInfo()

void nkAstraeus::SsaoEffect::setEffectFromGBufferInfo ( nkGraphics::Texture positionBuffer,
nkGraphics::Texture normalBuffer = nullptr 
)

Sets the position buffer, and potentially the normal buffer that the effect should use as a reference for geometry data. The buffers directly relate to G-Buffers used during deferred rendering. They need to be in world / view space.
If the normal buffer is left to nullptr, then the derivatives of positions are used to derive a normal. Else, the buffer is used, usually leading to cleaner results.
Expected clearing color for both targets is (0, 0, 0, 0). This is because pixels with no geometry information are expected to be in that setup. This ensures the best results and performances.

Parameters
positionBufferThe position G-Buffer part to find the positions from.
normalBufferThe normal G-Buffer part to find the normals from.
Remarks
If the effect was loaded with a depth buffer prior to calling this function, then the effect needs to be reloaded for this to take effect.
Also, if the normal buffer is switched from nullptr to a valid texture and vice-versa, the effect needs to be reloaded to account for the change.
Else, the position buffer, and potentially the normal buffer, will be updated right away without any reload being necessary.

◆ setEffectFromDepthInfo()

void nkAstraeus::SsaoEffect::setEffectFromDepthInfo ( nkGraphics::Texture depthBuffer,
bool  linearDepth = false 
)

Sets the depth buffer the effect should use as a reference for geometry data. The depth buffer does not need to be processed and can be the direct output of a TargetOperations's passes.
The positions of the pixels will be reconstructed using the active context's camera's projection parameters. The normals are reconstructed using derivatives of the positions recomputed.
The clearing color expected is 1.0. All pixels with this value will be considered with no geometry. This ensures best results and performances.

Parameters
depthBufferThe buffer to use as input for geometrical information reconstruction.
linearDepthWhether the depth data is linear (true) or not (false).
Remarks
If the effect was loaded with geometry space data prior to calling this function, then the effect needs to be reloaded for this to take effect.
Else, the depth buffer used will be switched live without the effect needing to be reloaded. However, the linear flag needs a reload if its state changes.

◆ setCamera()

void nkAstraeus::SsaoEffect::setCamera ( nkGraphics::Camera value)

Sets the camera to use when retrieving required projection parameters. Defaults to nullptr, for which the effect will work with the context camera.

Parameters
valueThe camera to use for the parameters.
Remarks
This parameter can be edited live without reloading an already loaded effect.

◆ setSamplingRadius()

void nkAstraeus::SsaoEffect::setSamplingRadius ( float  value)

Sets the sampling radius (in world units) used by the kernel hemisphere. An hemisphere is centered around the reference pixel for which occlusion is computed at a given time. The radius drives its scale in the virtual space, directly driving how far from the reference point the samples can be taken.
Defaults to 0.05.

Parameters
valueThe radius to use, in world units.
Remarks
This parameter can be edited live without reloading an already loaded effect.

◆ setMaxOcclusionDistance()

void nkAstraeus::SsaoEffect::setMaxOcclusionDistance ( float  value)

Sets the maximum distance, in world units, at which an occlusion can occur. For instance, if set to 1.0, then all samples further than 1.0 unit from the reference won't be counted as occluding samples (too far away). This helps in reducing haloing around objects.
Defaults to 1.0.

Parameters
valueThe distance to use, in world units.
Remarks
This parameter can be edited live without reloading an already loaded effect.

◆ setStrength()

void nkAstraeus::SsaoEffect::setStrength ( float  value)

Sets the strength of the effect. A stronger effect means that overall, occlusion will get stronger quicker.
Defaults to 0.8.

Parameters
valueThe strength of the effect, in the interval of [0, 1].
Remarks
This parameter can be edited live without reloading an already loaded effect.

◆ setDepthBias()

void nkAstraeus::SsaoEffect::setDepthBias ( float  value)

Sets the depth bias which helps in avoiding false positive and self-shadowing pixels. The bias being defined in the virtual space (world or view), it is exposed here to work with different scales.
Defaults to 0.00001.

Parameters
valueThe depth bias to use, in world units.
Remarks
Changing this parameter requires a reload of the effect, if the effect was already loaded.

◆ setKernelSampleCount()

void nkAstraeus::SsaoEffect::setKernelSampleCount ( unsigned int  value)

Sets the number of samples that should compose the kernel. The kernel will be sampling in the hemisphere of the normal direction. Having more samples mean that the effect will get smoother, at the cost of performances.
Defaults to 16.

Parameters
valueThe number of samples to take for a given pixel, in the range of [1, 16].
Remarks
Changing this parameter requires a reload of the effect, if the effect was already loaded.

◆ setOcclusionDrivesAlpha()

void nkAstraeus::SsaoEffect::setOcclusionDrivesAlpha ( bool  value)

Sets whether the occlusion factor computed should also drive the alpha of the color returned. If set to false, then the alpha is always 1 and the effect outputs a black (occluded) to white (non-occluded) color map. If set to true, the alpha will be merged in the alpha component, leading to the occlusion being blended in the target.
In the case blending is wanted, see SsaoEffectUtils::prepareBlendStateForAoBlending() to prepare a blend state compatible with the behaviour of the effect.
Defaults to false.

Parameters
valueWhether the occlusion should be merged in the alpha channel (true) or not (false).
Remarks
Changing this parameter requires a reload of the effect, if the effect was already loaded.

◆ load()

virtual bool nkAstraeus::SsaoEffect::load ( )
overridevirtual

Loads the effect and make it ready for rendering.

Returns
Whether the loading went well (true) or not (false).

Implements nkAstraeus::Effect.

◆ unload()

virtual void nkAstraeus::SsaoEffect::unload ( )
overridevirtual

Unloads the effect and its internal memory. After that, the effect is unusable for rendering.

Implements nkAstraeus::Effect.

◆ create()

static nkMemory::UniquePtr<SsaoEffect> nkAstraeus::SsaoEffect::create ( System system = nullptr)
static

Creates an instance of the class, and returns ownership over it.

Parameters
systemThe system the resource should live in. If left to nullptr, will seek the singleton instance of the system.
Returns
Ownership over the created instance of the class.
Remarks
The instance is not part of any manager if instantiated this way. If the resource's lifetime should be managed within the manager, then calling ComplexEffectManager::createOrRetrieve() might be a better option. Alternatively, registering it afterwards through ComplexEffectManager::record() is another option.

The documentation for this class was generated from the following file: