Support Forum       G3D Web Page     
Public Member Functions | Public Attributes | List of all members
glsl::AmbientOcclusion_AO_pix Class Reference


Reference implementation of the Scalable Ambient Obscurance (AmbientOcclusion) screen-space ambient obscurance algorithm. More...

Public Member Functions

float aoValueFromPositionsAndNormal (vec3 C, vec3 n_C, vec3 Q)
 Compute the occlusion due to sample point Q about camera-space point C with unit normal n_C. More...
 
float CSZToKey (float z)
 Used for packing Z into the GB channels. More...
 
float fallOffFunction (float vv, float vn, float epsilon)
 Smaller return value = less occlusion. More...
 
int getMipLevel (float ssR)
 
vec3 getOffsetPosition (ivec2 ssC, vec2 unitOffset, float ssR, sampler2D cszBuffer, float invCszBufferScale)
 Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR. More...
 
void getOffsetPositions (ivec2 ssC, vec2 unitOffset, float ssR, sampler2D cszBuffer, out vec3 P0, out vec3 P1)
 Read the camera-space position of the points at screen-space pixel ssP + unitOffset * ssR in both channels of the packed csz buffer. More...
 
vec3 getPosition (ivec2 ssP, sampler2D cszBuffer)
 Read the camera-space position of the point at screen-space pixel ssP. More...
 
float lowPrecisionHash (vec2 p)
 
void main ()
 
float sampleAO (in ivec2 ssC, in vec3 C, in vec3 n_C, in float ssDiskRadius, in int tapIndex, in float randomPatternRotationAngle, in sampler2D cszBuffer, in float invCszBufferScale)
 Compute the occlusion due to sample with index i about the pixel at ssC that corresponds to camera-space point C with unit normal n_C, using maximum screen-space sampling radius ssDiskRadius. More...
 
vec2 tapLocation (int sampleNumber, float spinAngle, out float ssR)
 Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius) More...
 

Public Attributes

uniform float bias
 Bias to avoid AO in smooth corners, e.g., 0.015m. More...
 
uniform sampler2D CS_Z_buffer
 Negative, "linear" values in world-space units. More...
 
uniform float intensity
 
uniform float intensityDivR6
 intensity / radius^6 More...
 
const float MIN_RADIUS = 1.0
 
uniform float negInvRadius2
 
uniform ProjInfo projInfo
 
uniform float projScale
 The height in pixels of a 1m object if viewed from 1m away. More...
 
uniform float radius
 World-space AO radius in scene units (r). More...
 
uniform float radius2
 
out vec3 result
 

Detailed Description


Reference implementation of the Scalable Ambient Obscurance (AmbientOcclusion) screen-space ambient obscurance algorithm.

The optimized algorithmic structure of AmbientOcclusion was published in McGuire, Mara, and Luebke, Scalable Ambient Obscurance, HPG 2012, and was developed at NVIDIA with support from Louis Bavoil.

The mathematical ideas of AlchemyAO were first described in McGuire, Osman, Bukowski, and Hennessy, The Alchemy Screen-Space Ambient Obscurance Algorithm, HPG 2011 and were developed at Vicarious Visions.
DX11 HLSL port by Leonardo Zide of Treyarch


Open Source under the "BSD" license: http://www.opensource.org/licenses/bsd-license.php

Copyright (c) 2011-2012, NVIDIA All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Member Function Documentation

◆ aoValueFromPositionsAndNormal()

float glsl::AmbientOcclusion_AO_pix::aoValueFromPositionsAndNormal ( vec3  C,
vec3  n_C,
vec3  Q 
)
inline

Compute the occlusion due to sample point Q about camera-space point C with unit normal n_C.

◆ CSZToKey()

float glsl::AmbientOcclusion_AO_pix::CSZToKey ( float  z)
inline

Used for packing Z into the GB channels.

◆ fallOffFunction()

float glsl::AmbientOcclusion_AO_pix::fallOffFunction ( float  vv,
float  vn,
float  epsilon 
)
inline

Smaller return value = less occlusion.

◆ getMipLevel()

int glsl::AmbientOcclusion_AO_pix::getMipLevel ( float  ssR)
inline

◆ getOffsetPosition()

vec3 glsl::AmbientOcclusion_AO_pix::getOffsetPosition ( ivec2  ssC,
vec2  unitOffset,
float  ssR,
sampler2D  cszBuffer,
float  invCszBufferScale 
)
inline

Read the camera-space position of the point at screen-space pixel ssP + unitOffset * ssR.

Assumes length(unitOffset) == 1. Use cszBufferScale if reading from the peeled depth buffer, which has been scaled by (1 / invCszBufferScale) from the original

◆ getOffsetPositions()

void glsl::AmbientOcclusion_AO_pix::getOffsetPositions ( ivec2  ssC,
vec2  unitOffset,
float  ssR,
sampler2D  cszBuffer,
out vec3  P0,
out vec3  P1 
)
inline

Read the camera-space position of the points at screen-space pixel ssP + unitOffset * ssR in both channels of the packed csz buffer.

Assumes length(unitOffset) == 1.

◆ getPosition()

vec3 glsl::AmbientOcclusion_AO_pix::getPosition ( ivec2  ssP,
sampler2D  cszBuffer 
)
inline

Read the camera-space position of the point at screen-space pixel ssP.

◆ lowPrecisionHash()

float glsl::AmbientOcclusion_AO_pix::lowPrecisionHash ( vec2  p)
inline

◆ main()

void glsl::AmbientOcclusion_AO_pix::main ( )
inline

◆ sampleAO()

float glsl::AmbientOcclusion_AO_pix::sampleAO ( in ivec2  ssC,
in vec3  C,
in vec3  n_C,
in float  ssDiskRadius,
in int  tapIndex,
in float  randomPatternRotationAngle,
in sampler2D  cszBuffer,
in float  invCszBufferScale 
)
inline

Compute the occlusion due to sample with index i about the pixel at ssC that corresponds to camera-space point C with unit normal n_C, using maximum screen-space sampling radius ssDiskRadius.

Note that units of H() in the HPG12 paper are meters, not unitless. The whole falloff/sampling function is therefore unitless. In this implementation, we factor out (9 / radius).

When sampling from the peeled depth buffer, make sure ssDiskRadius has been premultiplied by cszBufferScale

◆ tapLocation()

vec2 glsl::AmbientOcclusion_AO_pix::tapLocation ( int  sampleNumber,
float  spinAngle,
out float  ssR 
)
inline

Returns a unit vector and a screen-space radius for the tap on a unit disk (the caller should scale by the actual disk radius)

Member Data Documentation

◆ bias

uniform float glsl::AmbientOcclusion_AO_pix::bias

Bias to avoid AO in smooth corners, e.g., 0.015m.

◆ CS_Z_buffer

uniform sampler2D glsl::AmbientOcclusion_AO_pix::CS_Z_buffer

Negative, "linear" values in world-space units.

◆ intensity

uniform float glsl::AmbientOcclusion_AO_pix::intensity

◆ intensityDivR6

uniform float glsl::AmbientOcclusion_AO_pix::intensityDivR6

intensity / radius^6

◆ MIN_RADIUS

const float glsl::AmbientOcclusion_AO_pix::MIN_RADIUS = 1.0

◆ negInvRadius2

uniform float glsl::AmbientOcclusion_AO_pix::negInvRadius2

◆ projInfo

uniform ProjInfo glsl::AmbientOcclusion_AO_pix::projInfo

◆ projScale

uniform float glsl::AmbientOcclusion_AO_pix::projScale

The height in pixels of a 1m object if viewed from 1m away.

You can compute it from your projection matrix. The actual value is just a scale factor on radius; you can simply hardcode this to a constant (~500) and make your radius value unitless (...but resolution dependent.)

◆ radius

uniform float glsl::AmbientOcclusion_AO_pix::radius

World-space AO radius in scene units (r).

e.g., 1.0m

◆ radius2

uniform float glsl::AmbientOcclusion_AO_pix::radius2

◆ result

out vec3 glsl::AmbientOcclusion_AO_pix::result

documentation generated on Wed Nov 24 2021 08:02:03 using doxygen 1.8.15