A Screen Space Ambient Occlusion effect. More...
Static Public Member Functions | |
static nkMemory::UniquePtr< SsaoEffect > | create (System *system=nullptr) |
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.
|
noexcept |
Default constructor. Alternatively, see SsaoEffect::create(), or EffectManager::createOrRetrieve().
system | The system the resource should live in. |
|
virtual |
Destructor.
|
overridevirtual |
nkGraphics::Texture* nkAstraeus::SsaoEffect::getPositionBuffer | ( | ) | const |
nkGraphics::Texture* nkAstraeus::SsaoEffect::getNormalBuffer | ( | ) | const |
nkGraphics::Texture* nkAstraeus::SsaoEffect::getDepthBuffer | ( | ) | const |
bool nkAstraeus::SsaoEffect::getLinearDepth | ( | ) | const |
nkGraphics::Camera* nkAstraeus::SsaoEffect::getCamera | ( | ) | const |
float nkAstraeus::SsaoEffect::getSamplingRadius | ( | ) | const |
float nkAstraeus::SsaoEffect::getMaxOcclusionDistance | ( | ) | const |
float nkAstraeus::SsaoEffect::getStrength | ( | ) | const |
float nkAstraeus::SsaoEffect::getDepthBias | ( | ) | const |
unsigned int nkAstraeus::SsaoEffect::getKernelSampleCount | ( | ) | const |
bool nkAstraeus::SsaoEffect::getOcclusionDrivesAlpha | ( | ) | const |
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.
positionBuffer | The position G-Buffer part to find the positions from. |
normalBuffer | The normal G-Buffer part to find the normals from. |
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.
depthBuffer | The buffer to use as input for geometrical information reconstruction. |
linearDepth | Whether the depth data is linear (true) or not (false). |
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.
value | The camera to use for the parameters. |
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.
value | The radius to use, in world units. |
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.
value | The distance to use, in world units. |
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.
value | The strength of the effect, in the interval of [0, 1]. |
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.
value | The depth bias to use, in world units. |
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.
value | The number of samples to take for a given pixel, in the range of [1, 16]. |
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.
value | Whether the occlusion should be merged in the alpha channel (true) or not (false). |
|
overridevirtual |
Loads the effect and make it ready for rendering.
Implements nkAstraeus::Effect.
|
overridevirtual |
Unloads the effect and its internal memory. After that, the effect is unusable for rendering.
Implements nkAstraeus::Effect.
|
static |
Creates an instance of the class, and returns ownership over it.
system | The system the resource should live in. If left to nullptr, will seek the singleton instance of the system. |