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::GBuffer Class Reference

Saito and Takahashi's Geometry Buffers, typically used today for deferred and forward+ shading. More...

Inherits G3D::ReferenceCountedObject.

Classes

class  Field
 
Names of fields that may be present in a GBuffer. More...
 
class  Specification
 

Public Member Functions

Framebuffer::AttachmentPoint attachmentPoint (Field field) const
 Returns the attachment point on framebuffer() for field. More...
 
const shared_ptr< Cameracamera () const
 The camera from which these buffers were rendered. More...
 
Vector2int16 colorGuardBandThickness () const
 
Rect2D colorRect () const
 The region within the color guard band. More...
 
void connectToShader (String gbufferName, Args &args, Access access, const Sampler &textureSettings, int mipLevel=0)
 
int depth () const
 
Vector2int16 depthGuardBandThickness () const
 
Rect2D finalRect () const
 The region that will affect the final image, i.e., with the depth and color band stripped off. More...
 
const shared_ptr< Framebuffer > & framebuffer () const
 The other buffers are permanently bound to this framebuffer. More...
 
shared_ptr< Framebufferframebuffer ()
 The other buffers are permanently bound to this framebuffer.
More...
 
const Color4 getClearValue (Field field) const
 get the clear value of the given field More...
 
String getImageString (const Specification &spec, const ImageFormat *format)
 
String getSamplerStringFromTexDimension (const Specification &spec)
 
String getSwizzleComponents (int numComponents)
 
int getTexDimensionInt (Texture::Dimension dim)
 
bool hasFaceNormals () const
 True if this contains non-nullptr Field::CS_FACE_NORMAL or Field::WS_FACE_NORMAL in the specificationl. More...
 
int height () const
 
bool isDepthAndStencilOnly () const
 True iff this G-buffer renders only depth and stencil. More...
 
const Stringname () const
 For debugging in programs with many GBuffers. More...
 
void prepare (RenderDevice *rd, const shared_ptr< Camera > &camera, float timeOffset, float velocityStartTimeOffset, Vector2int16 depthGuardBandThickness, Vector2int16 colorGuardBandThickness)
 Bind the framebuffer and clear it, then set the camera and time offsets. More...
 
void prepare (RenderDevice *rd, float timeOffset, float velocityStartTimeOffset, Vector2int16 depthGuardBandThickness, Vector2int16 colorGuardBandThickness)
 Bind the framebuffer and clear it, then set the time offsets No camera version. More...
 
const String readDeclarations () const
 
Example: More...
 
Rect2D rect () const
 The actual framebuffer bounds out to the edge of the depth guard band. More...
 
Rect2D rect2DBounds () const
 The full bounds, including the depth guard band. More...
 
virtual void resize (int width, int height, int depth=1)
 Reallocate all buffers to this size if they are not already. More...
 
virtual void resize (Vector2int32 size, int depth=1)
 
void setCamera (const shared_ptr< Camera > &camera)
 Explicitly override the camera stored in the GBuffer. More...
 
void setColorClearValue (Field field, const Color4 &c)
 sets the clear value of the given field More...
 
void setImageStore (bool state)
 Enable/disable the image store api. More...
 
virtual void setShaderArgsRead (UniformTable &args, const String &prefix="") const
 Binds the readScaleBias values defined in readDeclarations(). More...
 
virtual void setShaderArgsWrite (UniformTable &args, const String &prefix="") const
 Binds the writeScaleBias values defined in writeDeclarations() in the form [prefix]FIELD_writeScaleBias = vec2(writeMultiplyFirst, writeAddSecond) More...
 
virtual void setShaderArgsWritePosition (CFrame &previousFrame, const RenderDevice *rd, Args &args) const
 Sets shader arguments related to position for a surface. More...
 
void setSpecification (const Specification &s)
 
Changes the specification. More...
 
void setTimeOffsets (float timeOffset, float velocityStartTimeOffset)
 
const Specificationspecification () const
 
shared_ptr< Texturetexture (Field f) const
 Returns the Texture bound to f, or nullptr if there is not one. More...
 
float timeOffset () const
 
Vector2int16 trimBandThickness ()
 
float velocityStartTimeOffset () const
 
int width () const
 
const String writeDeclarations () const
 
A series of macros to prepend before a Surface's shader for rendering to GBuffers. More...
 

Static Public Member Functions

static void bindReadArgs (UniformTable &args, Field field, const shared_ptr< Texture > &texture, const String &prefix="")
 Binds a single argument as [prefix] + fieldName + "_buffer" and fieldName + "_readScaleBias". More...
 
static void bindWriteUniform (UniformTable &args, Field f, const Texture::Encoding &encoding, const String &prefix="")
 Note that the framebuffer() automatically binds all write uniform arguments. More...
 
static shared_ptr< GBuffercreate (const Specification &specification, const String &name="G3D::GBuffer")
 
static bool supported ()
 Returns true if GBuffer is supported on this GPU. More...
 

Protected Member Functions

 GBuffer (const String &name, const Specification &specification)
 
 GBuffer (const GBuffer &)
 
StringgetShaderString (const String &gbufferName, Args &args, Access access, bool &needCreation)
 
GBufferoperator= (const GBuffer &)
 
void setSpecification (const Specification &s, bool forceAllFieldsToUpdate)
 

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

bool m_allTexturesAllocated
 True when the textures have been allocated. More...
 
shared_ptr< Cameram_camera
 
Vector2int16 m_colorGuardBandThickness
 
Vector2int16 m_depthGuardBandThickness
 
bool m_depthOnly
 
Framebuffer::AttachmentPoint m_fieldToAttachmentPoint [Field::COUNT]
 
shared_ptr< Framebufferm_framebuffer
 The other buffers are permanently bound to this framebuffer. More...
 
bool m_hasFaceNormals
 
String m_name
 Used for debugging and visualization. More...
 
String m_readDeclarationString
 
Table< String, Stringm_readShaderStringCache
 
Table< String, Stringm_readwriteShaderStringCache
 
Vector3int16 m_resolution
 
Specification m_specification
 
Sampler m_textureSettings
 Settings used to connect the GBuffer to a Shader. More...
 
float m_timeOffset
 
bool m_useImageStore
 
float m_velocityStartTimeOffset
 
String m_writeDeclarationString
 
Table< String, Stringm_writeShaderStringCache
 

Detailed Description

Saito and Takahashi's Geometry Buffers, typically used today for deferred and forward+ shading.

Optionally contains position, normal, depth, velocity, and BSDF parameters as well as depth and stencil.

Example:

See also
Surface, Texture, Framebuffer

Constructor & Destructor Documentation

◆ GBuffer() [1/2]

G3D::GBuffer::GBuffer ( const String name,
const Specification specification 
)
protected

◆ GBuffer() [2/2]

G3D::GBuffer::GBuffer ( const GBuffer )
protected

Member Function Documentation

◆ attachmentPoint()

Framebuffer::AttachmentPoint G3D::GBuffer::attachmentPoint ( Field  field) const
inline

Returns the attachment point on framebuffer() for field.

Referenced by getClearValue(), and setColorClearValue().

◆ bindReadArgs()

static void G3D::GBuffer::bindReadArgs ( UniformTable args,
Field  field,
const shared_ptr< Texture > &  texture,
const String prefix = "" 
)
static

Binds a single argument as [prefix] + fieldName + "_buffer" and fieldName + "_readScaleBias".

Used by setShaderArgsRead(), and available for writing your own shaders that use GBuffer encodings but may not directly use a GBuffer or all of its fields. Note that you can simply use setShaderArgsRead() to bind all GBuffer fields; G3D::Shader will ignore the ones that are not used by the actual shader.

Parameters
textureIf nullptr, no binding is made. Use Texture::blackIfNull and Texture::whiteIfNull to avoid this behavior.
encodingUsed for non-nullptr, non- Field::DEPTH_AND_STENCIL input

◆ bindWriteUniform()

static void G3D::GBuffer::bindWriteUniform ( UniformTable args,
Field  f,
const Texture::Encoding encoding,
const String prefix = "" 
)
static

Note that the framebuffer() automatically binds all write uniform arguments.

◆ camera()

const shared_ptr<Camera> G3D::GBuffer::camera ( ) const
inline

The camera from which these buffers were rendered.

Referenced by setCamera().

◆ colorGuardBandThickness()

Vector2int16 G3D::GBuffer::colorGuardBandThickness ( ) const
inline
See also
GApp::Settings::colorGuardBandThickness
guardBand.png

◆ colorRect()

Rect2D G3D::GBuffer::colorRect ( ) const
inline

The region within the color guard band.

◆ connectToShader()

void G3D::GBuffer::connectToShader ( String  gbufferName,
Args args,
Access  access,
const Sampler textureSettings,
int  mipLevel = 0 
)

◆ create()

static shared_ptr<GBuffer> G3D::GBuffer::create ( const Specification specification,
const String name = "G3D::GBuffer" 
)
static

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

◆ depth()

int G3D::GBuffer::depth ( ) const

Referenced by resize().

◆ depthGuardBandThickness()

Vector2int16 G3D::GBuffer::depthGuardBandThickness ( ) const
inline
See also
GApp::Settings::depthGuardBandThickness
guardBand.png

◆ finalRect()

Rect2D G3D::GBuffer::finalRect ( ) const
inline

The region that will affect the final image, i.e., with the depth and color band stripped off.

◆ framebuffer() [1/2]

const shared_ptr<Framebuffer>& G3D::GBuffer::framebuffer ( ) const
inline

The other buffers are permanently bound to this framebuffer.

Referenced by colorRect(), finalRect(), getClearValue(), and setColorClearValue().

◆ framebuffer() [2/2]

shared_ptr<Framebuffer> G3D::GBuffer::framebuffer ( )
inline

The other buffers are permanently bound to this framebuffer.

◆ getClearValue()

const Color4 G3D::GBuffer::getClearValue ( Field  field) const
inline

get the clear value of the given field

◆ getImageString()

String G3D::GBuffer::getImageString ( const Specification spec,
const ImageFormat format 
)

◆ getSamplerStringFromTexDimension()

String G3D::GBuffer::getSamplerStringFromTexDimension ( const Specification spec)

◆ getShaderString()

String& G3D::GBuffer::getShaderString ( const String gbufferName,
Args args,
Access  access,
bool &  needCreation 
)
protected
Deprecated:
Used by SVO

◆ getSwizzleComponents()

String G3D::GBuffer::getSwizzleComponents ( int  numComponents)

◆ getTexDimensionInt()

int G3D::GBuffer::getTexDimensionInt ( Texture::Dimension  dim)

◆ hasFaceNormals()

bool G3D::GBuffer::hasFaceNormals ( ) const
inline

True if this contains non-nullptr Field::CS_FACE_NORMAL or Field::WS_FACE_NORMAL in the specificationl.

◆ height()

int G3D::GBuffer::height ( ) const

◆ isDepthAndStencilOnly()

bool G3D::GBuffer::isDepthAndStencilOnly ( ) const
inline

True iff this G-buffer renders only depth and stencil.

◆ name()

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

For debugging in programs with many GBuffers.

◆ operator=()

GBuffer& G3D::GBuffer::operator= ( const GBuffer )
protected

◆ prepare() [1/2]

void G3D::GBuffer::prepare ( RenderDevice rd,
const shared_ptr< Camera > &  camera,
float  timeOffset,
float  velocityStartTimeOffset,
Vector2int16  depthGuardBandThickness,
Vector2int16  colorGuardBandThickness 
)

Bind the framebuffer and clear it, then set the camera and time offsets.

◆ prepare() [2/2]

void G3D::GBuffer::prepare ( RenderDevice rd,
float  timeOffset,
float  velocityStartTimeOffset,
Vector2int16  depthGuardBandThickness,
Vector2int16  colorGuardBandThickness 
)

Bind the framebuffer and clear it, then set the time offsets No camera version.

◆ readDeclarations()

const String G3D::GBuffer::readDeclarations ( ) const
inline


Example:

#define WS_NORMAL
uniform vec2 WS_NORMAL_readScaleBias;
#define LAMBERTIAN
uniform vec2 LAMBERTIAN_readScaleBias;
#define DEPTH

This helper is not always desirable–you may wish to manually bind the scaleBias values

◆ rect()

Rect2D G3D::GBuffer::rect ( ) const
inline

The actual framebuffer bounds out to the edge of the depth guard band.

See also
colorRect, finalRect

◆ rect2DBounds()

Rect2D G3D::GBuffer::rect2DBounds ( ) const

The full bounds, including the depth guard band.

Referenced by rect().

◆ resize() [1/2]

virtual void G3D::GBuffer::resize ( int  width,
int  height,
int  depth = 1 
)
virtual

Reallocate all buffers to this size if they are not already.

Referenced by resize().

◆ resize() [2/2]

virtual void G3D::GBuffer::resize ( Vector2int32  size,
int  depth = 1 
)
inlinevirtual

◆ setCamera()

void G3D::GBuffer::setCamera ( const shared_ptr< Camera > &  camera)
inline

Explicitly override the camera stored in the GBuffer.

◆ setColorClearValue()

void G3D::GBuffer::setColorClearValue ( Field  field,
const Color4 c 
)
inline

sets the clear value of the given field

◆ setImageStore()

void G3D::GBuffer::setImageStore ( bool  state)
inline

Enable/disable the image store api.

◆ setShaderArgsRead()

virtual void G3D::GBuffer::setShaderArgsRead ( UniformTable args,
const String prefix = "" 
) const
virtual

Binds the readScaleBias values defined in readDeclarations().

in the form [prefix]FIELD_...

Inside a shader, these arguments can be automatically defined using the macro:

See also
uniform_GBuffer, GBuffer::setShaderArgsWrite, Texture::SetShaderArgs

◆ setShaderArgsWrite()

virtual void G3D::GBuffer::setShaderArgsWrite ( UniformTable args,
const String prefix = "" 
) const
virtual

Binds the writeScaleBias values defined in writeDeclarations() in the form [prefix]FIELD_writeScaleBias = vec2(writeMultiplyFirst, writeAddSecond)

Note that the framebuffer() automatically binds all write uniform arguments.

◆ setShaderArgsWritePosition()

virtual void G3D::GBuffer::setShaderArgsWritePosition ( CFrame previousFrame,
const RenderDevice rd,
Args args 
) const
virtual

Sets shader arguments related to position for a surface.

CFrame& previousFrame is specific to the surface for which the arguments are being set. const CFrame& previousCameraFrame is previous camera frame for position change. const CFrame& expressivePreviousCameraFrame is the above for motion.

RenderDevice must be passed in case of scene inversion. Args is the shader argument list.

◆ setSpecification() [1/2]

void G3D::GBuffer::setSpecification ( const Specification s,
bool  forceAllFieldsToUpdate 
)
protected

◆ setSpecification() [2/2]

void G3D::GBuffer::setSpecification ( const Specification s)


Changes the specification.

If nothing changed from the previous specification, then no allocation or pointer changes will occur.

Otherwise, the GBuffer may optimize texture allocation, however the current implementation does not guarantee this.

◆ setTimeOffsets()

void G3D::GBuffer::setTimeOffsets ( float  timeOffset,
float  velocityStartTimeOffset 
)
inline
See also
renderIntoGBufferHomogeneous

◆ specification()

const Specification& G3D::GBuffer::specification ( ) const
inline

◆ supported()

static bool G3D::GBuffer::supported ( )
static

Returns true if GBuffer is supported on this GPU.

◆ texture()

shared_ptr<Texture> G3D::GBuffer::texture ( Field  f) const

Returns the Texture bound to f, or nullptr if there is not one.

◆ timeOffset()

float G3D::GBuffer::timeOffset ( ) const
inline
See also
renderIntoGBufferHomogeneous

Referenced by setTimeOffsets().

◆ trimBandThickness()

Vector2int16 G3D::GBuffer::trimBandThickness ( )
inline

◆ velocityStartTimeOffset()

float G3D::GBuffer::velocityStartTimeOffset ( ) const
inline
See also
renderIntoGBufferHomogeneous

Referenced by setTimeOffsets().

◆ width()

int G3D::GBuffer::width ( ) const

◆ writeDeclarations()

const String G3D::GBuffer::writeDeclarations ( ) const
inline


A series of macros to prepend before a Surface's shader for rendering to GBuffers.

Note that the framebuffer() automatically binds all write declarations to any shader invoked on it.

This defines each of the fields in use and maps it to a GLSL output variable. For example, it might contain:

#define WS_NORMAL gl_FragData[0]
uniform vec2 WS_NORMAL_writeScaleBias;
#define LAMBERTIAN gl_FragData[1]
uniform vec2 LAMBERTIAN_writeScaleBias;
#define DEPTH gl_FragDepth

Member Data Documentation

◆ m_allTexturesAllocated

bool G3D::GBuffer::m_allTexturesAllocated
protected

True when the textures have been allocated.

◆ m_camera

shared_ptr<Camera> G3D::GBuffer::m_camera
protected

Referenced by camera(), and setCamera().

◆ m_colorGuardBandThickness

Vector2int16 G3D::GBuffer::m_colorGuardBandThickness
protected

◆ m_depthGuardBandThickness

Vector2int16 G3D::GBuffer::m_depthGuardBandThickness
protected

◆ m_depthOnly

bool G3D::GBuffer::m_depthOnly
protected

Referenced by isDepthAndStencilOnly().

◆ m_fieldToAttachmentPoint

Framebuffer::AttachmentPoint G3D::GBuffer::m_fieldToAttachmentPoint[Field::COUNT]
protected

Referenced by attachmentPoint().

◆ m_framebuffer

shared_ptr<Framebuffer> G3D::GBuffer::m_framebuffer
protected

The other buffers are permanently bound to this framebuffer.

Referenced by framebuffer().

◆ m_hasFaceNormals

bool G3D::GBuffer::m_hasFaceNormals
protected

Referenced by hasFaceNormals().

◆ m_name

String G3D::GBuffer::m_name
protected

Used for debugging and visualization.

Referenced by name().

◆ m_readDeclarationString

String G3D::GBuffer::m_readDeclarationString
protected

Referenced by readDeclarations().

◆ m_readShaderStringCache

Table<String, String> G3D::GBuffer::m_readShaderStringCache
protected

◆ m_readwriteShaderStringCache

Table<String, String> G3D::GBuffer::m_readwriteShaderStringCache
protected

◆ m_resolution

Vector3int16 G3D::GBuffer::m_resolution
protected

◆ m_specification

Specification G3D::GBuffer::m_specification
protected

Referenced by specification().

◆ m_textureSettings

Sampler G3D::GBuffer::m_textureSettings
protected

Settings used to connect the GBuffer to a Shader.

◆ m_timeOffset

float G3D::GBuffer::m_timeOffset
protected

Referenced by setTimeOffsets(), and timeOffset().

◆ m_useImageStore

bool G3D::GBuffer::m_useImageStore
protected

Referenced by setImageStore().

◆ m_velocityStartTimeOffset

float G3D::GBuffer::m_velocityStartTimeOffset
protected

◆ m_writeDeclarationString

String G3D::GBuffer::m_writeDeclarationString
protected

Referenced by writeDeclarations().

◆ m_writeShaderStringCache

Table<String, String> G3D::GBuffer::m_writeShaderStringCache
protected

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