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


Defocus post-process shader More...

Inherits G3D::ReferenceCountedObject.

Public Types

enum  DebugOption {
  NONE,
  SHOW_COC,
  SHOW_REGION,
  SHOW_NEAR,
  SHOW_BLURRY,
  SHOW_INPUT,
  SHOW_MID_AND_FAR,
  SHOW_SIGNED_COC
}
 

Public Member Functions

virtual void apply (RenderDevice *rd, shared_ptr< Texture > color, shared_ptr< Texture > depth, const shared_ptr< Camera > &camera, Vector2int16 trimBandThickness, DebugOption debugOption=NONE)
 Applies depth of field blur to supplied images and renders to the currently-bound framebuffer. More...
 

Static Public Member Functions

static shared_ptr< DepthOfFieldcreate (const String &debugName="G3D::DepthOfField")
 

Protected Member Functions

 DepthOfField (const String &debugName)
 
void blurPass (RenderDevice *rd, const shared_ptr< Texture > &blurInput, const shared_ptr< Texture > &nearInput, const shared_ptr< Framebuffer > &output, bool horizontal, const shared_ptr< Camera > &camera, const Rect2D &fullViewport, float maxCoCRadiusPixels, bool diskFramebuffer)
 
void composite (RenderDevice *rd, shared_ptr< Texture > packedBuffer, shared_ptr< Texture > blurBuffer, shared_ptr< Texture > nearBuffer, DebugOption d, Vector2int16 trimBandThickness, float farRadiusRescale, bool diskFramebuffer)
 Writes to the currently-bound framebuffer. More...
 
void computeCoC (RenderDevice *rd, const shared_ptr< Texture > &color, const shared_ptr< Texture > &depth, const shared_ptr< Camera > &camera, Vector2int16 inputGuardBand, float &farRadiusRescale, float maxCoCRadiusPixels)
 Writes m_packedBuffer. More...
 
void resizeBuffers (shared_ptr< Texture > target, int reducedResolutionFactor, Vector2int16 trimBandThickness)
 Allocates and resizes buffers. More...
 

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< Texturem_blurBuffer
 
String m_debugName
 
shared_ptr< Framebufferm_horizontalFramebuffer
 
shared_ptr< Texturem_nearBuffer
 
shared_ptr< Texturem_packedBuffer
 Color in RGB, circle of confusion and 'near field' bit in A. More...
 
shared_ptr< Framebufferm_packedFramebuffer
 
shared_ptr< Texturem_tempBlurBuffer
 
shared_ptr< Texturem_tempNearBuffer
 
shared_ptr< Framebufferm_verticalFramebuffer
 

Detailed Description


Defocus post-process shader

Referenced Code: Based on
Bukowski, Hennessy, Osman, and McGuire, The Skylanders SWAP Force Depth-of-Field Shader, GPU Pro4, 175-184, A K Peters / CRC Press, April 26, 2013

Member Enumeration Documentation

◆ DebugOption

Enumerator
NONE 
SHOW_COC 
SHOW_REGION 
SHOW_NEAR 
SHOW_BLURRY 
SHOW_INPUT 
SHOW_MID_AND_FAR 
SHOW_SIGNED_COC 

Constructor & Destructor Documentation

◆ DepthOfField()

G3D::DepthOfField::DepthOfField ( const String debugName)
protected

Member Function Documentation

◆ apply()

virtual void G3D::DepthOfField::apply ( RenderDevice rd,
shared_ptr< Texture color,
shared_ptr< Texture depth,
const shared_ptr< Camera > &  camera,
Vector2int16  trimBandThickness,
DebugOption  debugOption = NONE 
)
virtual

Applies depth of field blur to supplied images and renders to the currently-bound framebuffer.

The current framebuffer may have the color and depth values bound to it.

Reads depth reconstruction and circle of confusion parameters from camera.

Centers the output on the target framebuffer, so no explicit output guard band is specified.

◆ blurPass()

void G3D::DepthOfField::blurPass ( RenderDevice rd,
const shared_ptr< Texture > &  blurInput,
const shared_ptr< Texture > &  nearInput,
const shared_ptr< Framebuffer > &  output,
bool  horizontal,
const shared_ptr< Camera > &  camera,
const Rect2D fullViewport,
float  maxCoCRadiusPixels,
bool  diskFramebuffer 
)
protected

◆ composite()

void G3D::DepthOfField::composite ( RenderDevice rd,
shared_ptr< Texture packedBuffer,
shared_ptr< Texture blurBuffer,
shared_ptr< Texture nearBuffer,
DebugOption  d,
Vector2int16  trimBandThickness,
float  farRadiusRescale,
bool  diskFramebuffer 
)
protected

Writes to the currently-bound framebuffer.

◆ computeCoC()

void G3D::DepthOfField::computeCoC ( RenderDevice rd,
const shared_ptr< Texture > &  color,
const shared_ptr< Texture > &  depth,
const shared_ptr< Camera > &  camera,
Vector2int16  inputGuardBand,
float &  farRadiusRescale,
float  maxCoCRadiusPixels 
)
protected

Writes m_packedBuffer.

◆ create()

static shared_ptr<DepthOfField> G3D::DepthOfField::create ( const String debugName = "G3D::DepthOfField")
static
Parameters
debugNameUsed for naming textures. Does not affect which shaders are loaded.

◆ 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>.

◆ resizeBuffers()

void G3D::DepthOfField::resizeBuffers ( shared_ptr< Texture target,
int  reducedResolutionFactor,
Vector2int16  trimBandThickness 
)
protected

Allocates and resizes buffers.

Member Data Documentation

◆ m_blurBuffer

shared_ptr<Texture> G3D::DepthOfField::m_blurBuffer
protected

◆ m_debugName

String G3D::DepthOfField::m_debugName
protected

◆ m_horizontalFramebuffer

shared_ptr<Framebuffer> G3D::DepthOfField::m_horizontalFramebuffer
protected

◆ m_nearBuffer

shared_ptr<Texture> G3D::DepthOfField::m_nearBuffer
protected

◆ m_packedBuffer

shared_ptr<Texture> G3D::DepthOfField::m_packedBuffer
protected

Color in RGB, circle of confusion and 'near field' bit in A.

Precision determined by the input, RGB8, RGB16F, or RGB32F.

The A channel values are always written with only 8 bits of effective precision.

The radius (A channel) values are scaled and biased to [0, 1]. Unpack them to pixel radii with:

r = ((a * 2) - 1) * maxRadius

Where maxRadius the larger of the maximum near and far field blurs. The decoded radius is negative in the far field (the packed alpha channel should look like a head lamp on a dark night, with nearby objects bright, the focus field gray, and the distance black).

◆ m_packedFramebuffer

shared_ptr<Framebuffer> G3D::DepthOfField::m_packedFramebuffer
protected

◆ m_tempBlurBuffer

shared_ptr<Texture> G3D::DepthOfField::m_tempBlurBuffer
protected

◆ m_tempNearBuffer

shared_ptr<Texture> G3D::DepthOfField::m_tempNearBuffer
protected

◆ m_verticalFramebuffer

shared_ptr<Framebuffer> G3D::DepthOfField::m_verticalFramebuffer
protected

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