Support Forum G3D Web Page |
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< Camera > | camera () 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< Framebuffer > | framebuffer () |
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 String & | name () 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 Specification & | specification () const |
shared_ptr< Texture > | texture (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< GBuffer > | create (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 &) | |
String & | getShaderString (const String &gbufferName, Args &args, Access access, bool &needCreation) |
GBuffer & | operator= (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< Camera > | m_camera |
Vector2int16 | m_colorGuardBandThickness |
Vector2int16 | m_depthGuardBandThickness |
bool | m_depthOnly |
Framebuffer::AttachmentPoint | m_fieldToAttachmentPoint [Field::COUNT] |
shared_ptr< Framebuffer > | m_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, String > | m_readShaderStringCache |
Table< String, String > | m_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, String > | m_writeShaderStringCache |
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:
|
protected |
|
protected |
|
inline |
Returns the attachment point on framebuffer() for field.
Referenced by getClearValue(), and setColorClearValue().
|
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.
texture | If nullptr, no binding is made. Use Texture::blackIfNull and Texture::whiteIfNull to avoid this behavior. |
encoding | Used for non-nullptr, non- Field::DEPTH_AND_STENCIL input |
|
static |
Note that the framebuffer() automatically binds all write uniform arguments.
|
inline |
The camera from which these buffers were rendered.
Referenced by setCamera().
|
inline |
|
inline |
The region within the color guard band.
void G3D::GBuffer::connectToShader | ( | String | gbufferName, |
Args & | args, | ||
Access | access, | ||
const Sampler & | textureSettings, | ||
int | mipLevel = 0 |
||
) |
|
static |
|
inlinestaticprotectedinherited |
Like std::make_shared, but works for protected constructors.
Call as createShared<myclass>.
int G3D::GBuffer::depth | ( | ) | const |
Referenced by resize().
|
inline |
|
inline |
The region that will affect the final image, i.e., with the depth and color band stripped off.
|
inline |
The other buffers are permanently bound to this framebuffer.
Referenced by colorRect(), finalRect(), getClearValue(), and setColorClearValue().
|
inline |
The other buffers are permanently bound to this framebuffer.
get the clear value of the given field
String G3D::GBuffer::getImageString | ( | const Specification & | spec, |
const ImageFormat * | format | ||
) |
String G3D::GBuffer::getSamplerStringFromTexDimension | ( | const Specification & | spec | ) |
|
protected |
String G3D::GBuffer::getSwizzleComponents | ( | int | numComponents | ) |
int G3D::GBuffer::getTexDimensionInt | ( | Texture::Dimension | dim | ) |
|
inline |
True if this contains non-nullptr Field::CS_FACE_NORMAL or Field::WS_FACE_NORMAL in the specificationl.
int G3D::GBuffer::height | ( | ) | const |
|
inline |
True iff this G-buffer renders only depth and stencil.
|
inline |
For debugging in programs with many GBuffers.
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.
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.
|
inline |
Example:
This helper is not always desirable–you may wish to manually bind the scaleBias values
|
inline |
Rect2D G3D::GBuffer::rect2DBounds | ( | ) | const |
The full bounds, including the depth guard band.
Referenced by rect().
|
virtual |
Reallocate all buffers to this size if they are not already.
Referenced by resize().
|
inlinevirtual |
|
inline |
Explicitly override the camera stored in the GBuffer.
sets the clear value of the given field
|
inline |
Enable/disable the image store api.
|
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:
|
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.
|
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.
|
protected |
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.
|
inline |
|
inline |
|
static |
Returns true if GBuffer is supported on this GPU.
Returns the Texture bound to f, or nullptr if there is not one.
|
inline |
Referenced by setTimeOffsets().
|
inline |
|
inline |
Referenced by setTimeOffsets().
int G3D::GBuffer::width | ( | ) | 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:
|
protected |
True when the textures have been allocated.
|
protected |
Referenced by camera(), and setCamera().
|
protected |
Referenced by colorGuardBandThickness(), colorRect(), and trimBandThickness().
|
protected |
Referenced by colorRect(), depthGuardBandThickness(), finalRect(), and trimBandThickness().
|
protected |
Referenced by isDepthAndStencilOnly().
|
protected |
Referenced by attachmentPoint().
|
protected |
The other buffers are permanently bound to this framebuffer.
Referenced by framebuffer().
|
protected |
Referenced by hasFaceNormals().
|
protected |
Referenced by readDeclarations().
|
protected |
|
protected |
Referenced by specification().
|
protected |
Referenced by setTimeOffsets(), and timeOffset().
|
protected |
Referenced by setImageStore().
|
protected |
Referenced by setTimeOffsets(), and velocityStartTimeOffset().
|
protected |
Referenced by writeDeclarations().