Support Forum       G3D Web Page     
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
G3D::AmbientOcclusion Class Reference


Screen-space ambient obscurance. More...

Inherits G3D::ReferenceCountedObject.

Classes

class  PerViewBuffers
 

Public Member Functions

const Stringname () const
 For debugging and visualization purposes. More...
 
void setShaderArgs (UniformTable &args, const String &prefix="ambientOcclusion_", const Sampler &sampler=Sampler::buffer())
 
Binds:
    sampler2D   <prefix>##buffer;
    ivec2       <prefix>##offset;
    #define     <prefix>##notNull 1;

to args. More...

 
shared_ptr< Texturetexture () const
 Returns the ao buffer texture, or Texture::white() if AO is disabled or supported on this GPU. More...
 
void update (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Camera > &camera, const shared_ptr< Texture > &depthTexture, const shared_ptr< Texture > &peeledDepthBuffer=nullptr, const shared_ptr< Texture > &normalBuffer=nullptr, const shared_ptr< Texture > &ssVelocityBuffer=nullptr, const Vector2int16 guardBandSize=Vector2int16(0, 0))
 Convenience method for resizing the AO texture from aoFramebuffer to match the size of its depth buffer and then computing AO from the depth buffer. More...
 

Static Public Member Functions

static shared_ptr< AmbientOcclusioncreate (const String &name="G3D::AmbientOcclusion")
 Create a new AmbientOcclusion instance. More...
 
static bool supported ()
 Returns false if this graphics card is known to perform AmbientOcclusion abnormally slowly. More...
 

Protected Member Functions

 AmbientOcclusion (const String &name)
 
void blurHorizontal (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const float farPlaneZ, const Vector4 &projConstant=Vector4::zero(), const shared_ptr< Texture > &normalBuffer=shared_ptr< Texture >())
 normalBuffer and normalReadScaleBias are only used if settings.useNormalsInBlur is true and normalBuffer is non-null. More...
 
void blurOneDirection (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const float farPlaneZ, const Vector4 &projConstant, const shared_ptr< Texture > &normalBuffer, const Vector2int16 &axis, const shared_ptr< Framebuffer > &framebuffer, const shared_ptr< Texture > &source)
 Shared code for the vertical and horizontal blur passes. More...
 
void blurVertical (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const float farPlaneZ, const Vector4 &projConstant=Vector4::zero(), const shared_ptr< Texture > &normalBuffer=shared_ptr< Texture >())
 normalBuffer and normalReadScaleBias are only used if settings.useNormalsInBlur is true and normalBuffer is non-null. More...
 
void compute (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const Vector3 &clipConstant, const Vector4 &projConstant, float projScale, const float farPlaneZ, const CoordinateFrame &currentCameraFrame, const CoordinateFrame &prevCameraFrame, const shared_ptr< Texture > &peeledDepthBuffer=nullptr, const shared_ptr< Texture > &normalBuffer=nullptr, const shared_ptr< Texture > &ssVelocityBuffer=nullptr)
 
Render the obscurance constant at each pixel to the currently-bound framebuffer. More...
 
void compute (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const shared_ptr< Camera > &camera, const shared_ptr< Texture > &peeledDepthBuffer=nullptr, const shared_ptr< Texture > &normalBuffer=nullptr, const shared_ptr< Texture > &ssVelocityBuffer=nullptr)
 Convenience wrapper for the full version of compute(). More...
 
void computeCSZ (RenderDevice *rd, const Array< shared_ptr< Framebuffer > > &cszFramebuffers, const shared_ptr< Texture > &csZBuffer, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const Vector3 &clipInfo, const shared_ptr< Texture > &peeledDepthBuffer)
 
virtual void computeRawAO (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const Vector3 &clipConstant, const Vector4 &projConstant, float projScale, const float farPlaneZ, const shared_ptr< Texture > &csZBuffer, const shared_ptr< Texture > &peeledCSZBuffer=shared_ptr< Texture >(), const shared_ptr< Texture > &normalBuffer=shared_ptr< Texture >())
 
void initializePerViewBuffers (int size)
 Creates the per view buffers if necessary. More...
 
void packBlurKeys (RenderDevice *rd, const AmbientOcclusionSettings &settings, const shared_ptr< Texture > &depthBuffer, const Vector3 &clipInfo, const float farPlaneZ, const shared_ptr< Texture > &normalBuffer)
 
void resizeBuffers (const shared_ptr< Texture > &depthTexture, bool packKey)
 

Static Protected Member Functions

template<class T , class ... ArgTypes>
static shared_ptr< T > createShared (ArgTypes &&... args)
 Like std::make_shared, but works for protected constructors. More...
 

Protected Attributes

shared_ptr< Shaderm_aoShader
 
int m_guardBandSize
 For raw and temporally-filtered buffers. More...
 
shared_ptr< Texturem_hBlurredBuffer
 Has AO in R and depth in G. More...
 
shared_ptr< Framebufferm_hBlurredFramebuffer
 
shared_ptr< Shaderm_minifyShader
 
String m_name
 Used for debugging and visualization purposes. More...
 
int m_outputGuardBandSize
 For spatially blurred and output buffers. More...
 
shared_ptr< Framebufferm_packedKeyBuffer
 If normals enabled, RGBA8, RG is CSZ, and BA is normal in Oct16. More...
 
Array< shared_ptr< PerViewBuffers > > m_perViewBuffers
 For now, can only be 1 or 2 in size. More...
 
shared_ptr< Texturem_rawAOBuffer
 Has AO in R and depth in G * 256 + B. More...
 
shared_ptr< Framebufferm_rawAOFramebuffer
 
shared_ptr< Texturem_resultBuffer
 
shared_ptr< Framebufferm_resultFramebuffer
 
String m_shaderFilenamePrefix
 Prefix for the shaders. More...
 
TemporalFilter m_temporalFilter
 
shared_ptr< Texturem_temporallyFilteredBuffer
 Has AO in R and depth in G * 256 + B. More...
 
shared_ptr< Texturem_texture
 As of the last call to update. More...
 
shared_ptr< UniformTablem_uniformTable
 Appended to all Args for shader passes run by this class. More...
 

Detailed Description


Screen-space ambient obscurance.

Create one instance of AmbientObscurance per viewport or Framebuffer rendered in the frame. Otherwise every update() call will trigger significant texture reallocation.

Author
Morgan McGuire and Michael Mara, NVIDIA and Williams College, http://research.nvidia.com, http://graphics.cs.williams.edu

Constructor & Destructor Documentation

◆ AmbientOcclusion()

G3D::AmbientOcclusion::AmbientOcclusion ( const String name)
inlineprotected

Member Function Documentation

◆ blurHorizontal()

void G3D::AmbientOcclusion::blurHorizontal ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const float  farPlaneZ,
const Vector4 projConstant = Vector4::zero(),
const shared_ptr< Texture > &  normalBuffer = shared_ptr< Texture >() 
)
protected

normalBuffer and normalReadScaleBias are only used if settings.useNormalsInBlur is true and normalBuffer is non-null.

projConstant is only used if settings.useNormalsInBlur is true and normalBuffer is null

◆ blurOneDirection()

void G3D::AmbientOcclusion::blurOneDirection ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const float  farPlaneZ,
const Vector4 projConstant,
const shared_ptr< Texture > &  normalBuffer,
const Vector2int16 axis,
const shared_ptr< Framebuffer > &  framebuffer,
const shared_ptr< Texture > &  source 
)
protected

Shared code for the vertical and horizontal blur passes.

◆ blurVertical()

void G3D::AmbientOcclusion::blurVertical ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const float  farPlaneZ,
const Vector4 projConstant = Vector4::zero(),
const shared_ptr< Texture > &  normalBuffer = shared_ptr< Texture >() 
)
protected

normalBuffer and normalReadScaleBias are only used if settings.useNormalsInBlur is true and normalBuffer is non-null.

projConstant is only used if settings.useNormalsInBlur is true and normalBuffer is null

◆ compute() [1/2]

void G3D::AmbientOcclusion::compute ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const Vector3 clipConstant,
const Vector4 projConstant,
float  projScale,
const float  farPlaneZ,
const CoordinateFrame currentCameraFrame,
const CoordinateFrame prevCameraFrame,
const shared_ptr< Texture > &  peeledDepthBuffer = nullptr,
const shared_ptr< Texture > &  normalBuffer = nullptr,
const shared_ptr< Texture > &  ssVelocityBuffer = nullptr 
)
protected


Render the obscurance constant at each pixel to the currently-bound framebuffer.

Parameters
rdThe rendering device/graphics context. The currently-bound framebuffer must match the dimensions of depthBuffer.
settingsSee G3D::AmbientOcclusionSettings.
depthBufferStandard hyperbolic depth buffer. Can be from either an infinite or finite far plane depending on the values in projConstant and clipConstant.
clipConstantConstants based on clipping planes:
const double width = rd->width();
const double height = rd->height();
const double z_f = camera->farPlaneZ();
const double z_n = camera->nearPlaneZ();
const Vector3& clipConstant =
(z_f == -inf()) ?
Vector3(float(z_n), -1.0f, 1.0f) :
Vector3(float(z_n * z_f), float(z_n - z_f), float(z_f));
projConstantConstants based on the projection matrix:
camera->getProjectUnitMatrix(rd->viewport(), P);
const Vector4 projConstant
(float(-2.0 / (width * P[0][0])),
float(-2.0 / (height * P[1][1])),
float((1.0 - (double)P[0][2]) / P[0][0]),
float((1.0 + (double)P[1][2]) / P[1][1]));
projScalePixels-per-meter at z=-1, e.g., computed by:
-height / (2.0 * tan(verticalFieldOfView * 0.5))

This is usually around 500.

Parameters
peeledDepthBufferAn optional peeled depth texture, rendered from the same viewpoint as the depthBuffer, but not necessarily with the same resolution.

◆ compute() [2/2]

void G3D::AmbientOcclusion::compute ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const shared_ptr< Camera > &  camera,
const shared_ptr< Texture > &  peeledDepthBuffer = nullptr,
const shared_ptr< Texture > &  normalBuffer = nullptr,
const shared_ptr< Texture > &  ssVelocityBuffer = nullptr 
)
protected

Convenience wrapper for the full version of compute().

Parameters
cameraThe camera that the scene was rendered with.

◆ computeCSZ()

void G3D::AmbientOcclusion::computeCSZ ( RenderDevice rd,
const Array< shared_ptr< Framebuffer > > &  cszFramebuffers,
const shared_ptr< Texture > &  csZBuffer,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const Vector3 clipInfo,
const shared_ptr< Texture > &  peeledDepthBuffer 
)
protected

◆ computeRawAO()

virtual void G3D::AmbientOcclusion::computeRawAO ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const Vector3 clipConstant,
const Vector4 projConstant,
float  projScale,
const float  farPlaneZ,
const shared_ptr< Texture > &  csZBuffer,
const shared_ptr< Texture > &  peeledCSZBuffer = shared_ptr< Texture >(),
const shared_ptr< Texture > &  normalBuffer = shared_ptr< Texture >() 
)
protectedvirtual

◆ create()

static shared_ptr<AmbientOcclusion> G3D::AmbientOcclusion::create ( const String name = "G3D::AmbientOcclusion")
static

Create a new AmbientOcclusion instance.

Only one is ever needed, but if you are rendering to differently-sized framebuffers it is faster to create one instance per resolution than to constantly force AmbientOcclusion to resize its internal buffers.

◆ createShared()

template<class T , class ... ArgTypes>
static shared_ptr<T> G3D::ReferenceCountedObject::createShared ( ArgTypes &&...  args)
inlinestaticprotectedinherited

Like std::make_shared, but works for protected constructors.

Call as createShared<myclass>.

◆ initializePerViewBuffers()

void G3D::AmbientOcclusion::initializePerViewBuffers ( int  size)
protected

Creates the per view buffers if necessary.

◆ name()

const String& G3D::AmbientOcclusion::name ( ) const
inline

For debugging and visualization purposes.

◆ packBlurKeys()

void G3D::AmbientOcclusion::packBlurKeys ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Texture > &  depthBuffer,
const Vector3 clipInfo,
const float  farPlaneZ,
const shared_ptr< Texture > &  normalBuffer 
)
protected

◆ resizeBuffers()

void G3D::AmbientOcclusion::resizeBuffers ( const shared_ptr< Texture > &  depthTexture,
bool  packKey 
)
protected

◆ setShaderArgs()

void G3D::AmbientOcclusion::setShaderArgs ( UniformTable args,
const String prefix = "ambientOcclusion_",
const Sampler sampler = Sampler::buffer() 
)

Binds:
    sampler2D   <prefix>##buffer;
    ivec2       <prefix>##offset;
    #define     <prefix>##notNull 1;

to args.

◆ supported()

static bool G3D::AmbientOcclusion::supported ( )
static

Returns false if this graphics card is known to perform AmbientOcclusion abnormally slowly.

◆ texture()

shared_ptr<Texture> G3D::AmbientOcclusion::texture ( ) const
inline

Returns the ao buffer texture, or Texture::white() if AO is disabled or supported on this GPU.

Modulate indirect illumination by this

◆ update()

void G3D::AmbientOcclusion::update ( RenderDevice rd,
const AmbientOcclusionSettings settings,
const shared_ptr< Camera > &  camera,
const shared_ptr< Texture > &  depthTexture,
const shared_ptr< Texture > &  peeledDepthBuffer = nullptr,
const shared_ptr< Texture > &  normalBuffer = nullptr,
const shared_ptr< Texture > &  ssVelocityBuffer = nullptr,
const Vector2int16  guardBandSize = Vector2int16(0, 0) 
)

Convenience method for resizing the AO texture from aoFramebuffer to match the size of its depth buffer and then computing AO from the depth buffer.

Parameters
guardBandSizeRequired to be the same in both dimensions and non-negative
See also
texture

Member Data Documentation

◆ m_aoShader

shared_ptr<Shader> G3D::AmbientOcclusion::m_aoShader
protected

◆ m_guardBandSize

int G3D::AmbientOcclusion::m_guardBandSize
protected

For raw and temporally-filtered buffers.

◆ m_hBlurredBuffer

shared_ptr<Texture> G3D::AmbientOcclusion::m_hBlurredBuffer
protected

Has AO in R and depth in G.

◆ m_hBlurredFramebuffer

shared_ptr<Framebuffer> G3D::AmbientOcclusion::m_hBlurredFramebuffer
protected

◆ m_minifyShader

shared_ptr<Shader> G3D::AmbientOcclusion::m_minifyShader
protected

◆ m_name

String G3D::AmbientOcclusion::m_name
protected

Used for debugging and visualization purposes.

Referenced by name().

◆ m_outputGuardBandSize

int G3D::AmbientOcclusion::m_outputGuardBandSize
protected

For spatially blurred and output buffers.

◆ m_packedKeyBuffer

shared_ptr<Framebuffer> G3D::AmbientOcclusion::m_packedKeyBuffer
protected

If normals enabled, RGBA8, RG is CSZ, and BA is normal in Oct16.

◆ m_perViewBuffers

Array<shared_ptr<PerViewBuffers> > G3D::AmbientOcclusion::m_perViewBuffers
protected

For now, can only be 1 or 2 in size.

◆ m_rawAOBuffer

shared_ptr<Texture> G3D::AmbientOcclusion::m_rawAOBuffer
protected

Has AO in R and depth in G * 256 + B.

◆ m_rawAOFramebuffer

shared_ptr<Framebuffer> G3D::AmbientOcclusion::m_rawAOFramebuffer
protected

◆ m_resultBuffer

shared_ptr<Texture> G3D::AmbientOcclusion::m_resultBuffer
protected

◆ m_resultFramebuffer

shared_ptr<Framebuffer> G3D::AmbientOcclusion::m_resultFramebuffer
protected

◆ m_shaderFilenamePrefix

String G3D::AmbientOcclusion::m_shaderFilenamePrefix
protected

Prefix for the shaders.

Default is "AmbientOcclusion_". This is useful when subclassing AmbientOcclusion to avoid a conflict with the default shaders.

◆ m_temporalFilter

TemporalFilter G3D::AmbientOcclusion::m_temporalFilter
protected

◆ m_temporallyFilteredBuffer

shared_ptr<Texture> G3D::AmbientOcclusion::m_temporallyFilteredBuffer
protected

Has AO in R and depth in G * 256 + B.

◆ m_texture

shared_ptr<Texture> G3D::AmbientOcclusion::m_texture
protected

As of the last call to update.

This is either m_resultBuffer or Texture::white()

Referenced by texture().

◆ m_uniformTable

shared_ptr<UniformTable> G3D::AmbientOcclusion::m_uniformTable
protected

Appended to all Args for shader passes run by this class.

Useful for prototyping minor variations; simply inherit from this class, modify the shaders and add any new uniforms/macros required here. Note that because of the inherent slowness of iterating over hash tables, such a modification is not as performant as possible.


documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15