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

Supports both traditional forward shading and full-screen deferred shading. More...

Inherits G3D::Renderer.

Public Member Functions

void addVolumeInitializationFrames (int numInitializationFrames)
 
virtual const StringclassName () const override
 
void convergeUninitializedProbes (RenderDevice *rd, const Array< shared_ptr< Surface >> &surfaceArray, const shared_ptr< TriTree > &tritree, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &lightingEnv)
 If there are any probes in the uninitialized state, converge them. More...
 
virtual void createProbeVolumes (const AABox &sceneBounds, LightingEnvironment &environment, const shared_ptr< Camera > &camera)
 For creating the diffuse irradiance probe volume(s). More...
 
bool deferredShading () const
 
int diffuseMipLevel () const
 
float diffuseRayFraction () const
 Fraction of rays cast that were for diffuse shading. More...
 
bool diskFramebuffer () const
 
bool enableDiffuseGI ()
 
bool enableGlossyGI ()
 
bool enableProbeRayRandomRotation ()
 
void getDynamicObjectBounds (const Array< shared_ptr< Entity >> &sceneEntities, Array< AABox > &dynamicBounds)
 Compute bounds on dynamic objects to wake up sleeping probes. More...
 
int glossyMipLevel () const
 
int glossyYScale () const
 
float gRaysPerFrame () const
 When everything is enabled, assuming looking at a fully glossy frame. More...
 
int initializationFrames ()
 
const shared_ptr< GBuffer > & irradianceGBuffer ()
 
bool orderIndependentTransparency () const
 
const shared_ptr< GBuffer > & reflectionGBuffer ()
 
const shared_ptr< Texture > & reflectionTexture ()
 
virtual void render (RenderDevice *rd, const shared_ptr< Camera > &camera, const shared_ptr< Framebuffer > &framebuffer, const shared_ptr< Framebuffer > &depthPeelFramebuffer, LightingEnvironment &lightingEnvironment, const shared_ptr< GBuffer > &gbuffer, const Array< shared_ptr< Surface >> &allSurfaces, const std::function< const shared_ptr< TriTree > &()> &tritreeFunction=nullptr) override
 
The active camera and time interval are taken from the GBuffer. More...
 
void setDeferredShading (bool b)
 If true, use deferred shading on all surfaces that can be represented by the GBuffer. More...
 
void setDiffuseMipLevel (int i)
 
void setDiskFramebuffer (bool b)
 
void setEnableDiffuseGI (bool b)
 
void setEnableGlossyGI (bool b)
 
void setEnableProbeRayRandomRotation (bool b)
 
void setGlossyMipLevel (int i)
 
void setGlossyYScale (int i)
 
void setOrderIndependentTransparency (bool b)
 If true, uses OIT. More...
 
void setReflectionTexture (const shared_ptr< GLPixelTransferBuffer > &pbo)
 
void setTraceGlossyReflections (bool b)
 
void traceAndUpdateProbes (RenderDevice *rd, const Array< shared_ptr< Surface >> &surfaceArray, const shared_ptr< TriTree > &tritree, const shared_ptr< GBuffer > &primaryGBuffer, const LightingEnvironment &environment, const int raysPerProbe, const unsigned int visibilityMask)
 Update the probe data structure. More...
 
void traceGlossyIndirectIllumination (RenderDevice *rd, const Array< shared_ptr< Surface > > &sortedVisibleSurfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment, const shared_ptr< TriTree > &tritree=nullptr)
 Trace half-res rays to resolve glossy ilumination. More...
 
bool traceGlossyReflections ()
 
virtual void updateDiffuseGI (RenderDevice *rd, const shared_ptr< Scene > &scene, const shared_ptr< GBuffer > &primaryGBuffer, const shared_ptr< Camera > &camera)
 Resolve probe states and update the irradiance probe volume. More...
 

Static Public Member Functions

static shared_ptr< Renderercreate ()
 

Public Attributes

AABox m_bounds
 
Array< shared_ptr< DDGIVolume > > m_ddgiVolumeArray
 
float m_energyPreservation = 0.95f
 How much should the probes count when shading themselves? 1.0 preserves energy perfectly. More...
 
shared_ptr< Framebufferm_glossyGIFramebuffer
 
int m_raysThisFrame = 0
 
Array< bool > m_showProbeLocations
 

Static Public Attributes

static const int CAMERA_TRACK = 2
 
static const int SCENE_INIT = 5
 

Protected Types

enum  Order {
  FRONT_TO_BACK,
  BACK_TO_FRONT,
  ARBITRARY
}
 
using PBOGBuffer = shared_ptr< GLPixelTransferBuffer >[5]
 

Protected Member Functions

 DefaultRenderer (const String &className="DefaultRenderer", const String &namespacePrefix="G3D::")
 
virtual void allocateAllOITBuffers (RenderDevice *rd, bool highPrecision=false)
 
virtual void allocateOITFramebufferAttachments (RenderDevice *rd, const shared_ptr< Framebuffer > &oitFramebuffer, int w, int h, bool highPrecision=false)
 Called once for the high res buffer and once for the low res one from allocateAllOITBuffers. More...
 
virtual void clearAndRenderToOITFramebuffer (RenderDevice *rd, const shared_ptr< Framebuffer > &oitFramebuffer, Array< shared_ptr< Surface >> &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 
virtual void computeGBuffer (RenderDevice *rd, const Array< shared_ptr< Surface >> &sortedVisibleSurfaces, const shared_ptr< GBuffer > &gbuffer, const shared_ptr< Framebuffer > &depthPeelFramebuffer, float depthPeelSeparationHint)
 Render z-prepass, depth peel, and G-buffer. More...
 
virtual void computeLowResDepthAndNormals (RenderDevice *rd, const shared_ptr< Texture > &csHighResNormalTexture)
 For OIT. More...
 
virtual void computeShadowing (RenderDevice *rd, const Array< shared_ptr< Surface >> &allSurfaces, const shared_ptr< GBuffer > &gbuffer, const shared_ptr< Framebuffer > &depthPeelFramebuffer, LightingEnvironment &lightingEnvironment)
 Compute ambient occlusion and direct illumination shadow maps. More...
 
virtual void cullAndSort (const shared_ptr< Camera > &camera, const shared_ptr< GBuffer > &gbuffer, const Rect2D &viewport, const Array< shared_ptr< Surface >> &allSurfaces, Array< shared_ptr< Surface >> &sortedVisibleSurfaces, Array< shared_ptr< Surface >> &forwardOpaqueSurfaces, Array< shared_ptr< Surface >> &forwardBlendedSurfaces)
 
Appends to sortedVisibleSurfaces and forwardSurfaces. More...
 
virtual void forwardShade (RenderDevice *rd, Array< shared_ptr< Surface > > &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment, const RenderPassType &renderPassType, Order order)
 Forward shade everything in surfaceArray. More...
 
void generateIrradianceRays (RenderDevice *rd, const int offset, const shared_ptr< DDGIVolume > &ddgiVolume, int &numGeneratedRays, const int raysPerProbe)
 Generate rays for diffuse irradiance. More...
 
void generateMirrorRays (RenderDevice *rd, const shared_ptr< GBuffer > &primaryGBuffer, int &numGlossyRays)
 
virtual void renderDeferredShading (RenderDevice *rd, const Array< shared_ptr< Surface > > &sortedVisibleSurfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 
virtual void renderIndirectIllumination (RenderDevice *rd, const Array< shared_ptr< Surface > > &sortedVisibleSurfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment, const shared_ptr< TriTree > &tritree=nullptr)
 Subclasses that can compute global illumination to deferred shading buffers should override this method, which is invoked before renderDeferredShading. More...
 
virtual void renderOpaqueSamples (RenderDevice *rd, Array< shared_ptr< Surface > > &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 
virtual void renderOpaqueScreenSpaceRefractingSamples (RenderDevice *rd, Array< shared_ptr< Surface > > &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 
virtual void renderOrderIndependentBlendedSamples (RenderDevice *rd, Array< shared_ptr< Surface > > &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 
virtual void renderSortedBlendedSamples (RenderDevice *rd, Array< shared_ptr< Surface > > &surfaceArray, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 
void resizeIrradianceRayTextures (const int raysPerProbe=-1)
 
virtual void resizeOITBuffersIfNeeded (const int width, const int height, const int lowResWidth, const int lowResHeight)
 For OIT. More...
 
void resizeReflectionRayTextures (const int screenWidth, const int screenHeight)
 
void sampleArbitraryRays (const shared_ptr< Texture > &rayOrigins, const shared_ptr< Texture > &rayDirections, const shared_ptr< TriTree > &tritree, const shared_ptr< GBuffer > &gbuffer, const int totalRays, const unsigned int visibilityMask, const int mipLevel=0)
 Trace an arbitrary buffer of rays to fill a GBuffer. More...
 
virtual void setDeferredShadingArgs (Args &args, const shared_ptr< GBuffer > &gbuffer, const LightingEnvironment &environment)
 Called by DefaultRenderer::renderDeferredShading to configure the inputs to deferred shading. More...
 
void shadeArbitraryRays (RenderDevice *rd, const Array< shared_ptr< Surface >> &surfaceArray, const shared_ptr< Framebuffer > &targetFramebuffer, const LightingEnvironment &environment, const shared_ptr< Texture > &rayOrigins, const shared_ptr< Texture > &rayDirections, const shared_ptr< GBuffer > &gbuffer, const bool useProbeIndirect, const bool glossyToMatte)
 Run the deferred shader on a gbuffer of arbitrary ray data. 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< Framebufferm_backgroundFramebuffer
 Captured image of the background used for blurs for OIT. More...
 
shared_ptr< Framebufferm_blurredMIPReflectionFramebuffer
 For computing blurred mirror reflections to approximate gathered glossy reflections. More...
 
shared_ptr< Shaderm_compositeOITShader
 
shared_ptr< Framebufferm_csOctLowResNormalFramebuffer
 Used for resampling normals during computeLowResDepthAndNormals for later upsampling under OIT. More...
 
shared_ptr< Shaderm_deferredShader
 Because subclasses can change the shader filename prefix, we must use member variables instead of the static variables created by LAUNCH_SHADER to store the shaders. More...
 
bool m_deferredShading
 
int m_diffuseMipLevel = 8
 Specifies the mip level at which to sample textures for irradiance and glossy rays. More...
 
bool m_diskFramebuffer = false
 For VR. More...
 
bool m_enableDiffuseGI = false
 Ray traced diffuse global illumination using DDGI. More...
 
bool m_enableGlossyGI = false
 Renders the glossy pass for primary rays each frame. More...
 
bool m_enableProbeRayRandomRotation = true
 
shared_ptr< GaussianMIPFilterm_gaussianMIPFilter
 
int m_glossyMipLevel = 3
 
int m_glossyYScale = 2
 
shared_ptr< Texturem_irradianceRayDirectionsTexture
 
shared_ptr< Texturem_irradianceRayOriginsTexture
 Textures storing ray origins and directions for irradiance probe sampling, regenerated every frame and then split between all probes according to a given heuristic. More...
 
shared_ptr< GBufferm_irradianceRaysGBuffer
 
shared_ptr< Framebufferm_irradianceRaysShadedFB
 
bool m_newlyXProbes = false
 
int m_numInitializationFrames = 0
 Number of frames to spend initializing probes if any volume has uninitialized probes. More...
 
shared_ptr< Framebufferm_oitFramebuffer
 For the transparent surface pass of the OIT algorithm. More...
 
bool m_oitHighPrecision
 If true, all OIT buffers will be in 32-bit floating point. More...
 
int m_oitLowResDownsampleFactor
 Hi-res pixels per low-res pixel, along one dimension. More...
 
shared_ptr< Framebufferm_oitLowResFramebuffer
 A low resolution version of m_oitFramebuffer. More...
 
int m_oitUpsampleFilterRadius
 Default is 1. More...
 
String m_oitWriteDeclarationGLSLFilename
 Loaded by the constructor, but subclasses may replace it in their own constructors. More...
 
bool m_orderIndependentTransparency
 
PBOGBuffer m_pboGBuffer
 
Table< shared_ptr< Texture >, shared_ptr< GLPixelTransferBuffer > > m_rayOriginsAndDirectionsTable
 
shared_ptr< GBufferm_reflectionGBuffer
 
shared_ptr< Texturem_reflectionRayDirectionsTexture
 
shared_ptr< Texturem_reflectionRayOriginsTexture
 Ray textures for reflection rays. More...
 
shared_ptr< Framebufferm_shadedMirrorRaysFramebuffer
 Only used when half-resolution glossy is in effect. More...
 
String m_shaderName
 e.g., "DefaultRenderer" used for switching the shaders loaded by subclasses. More...
 
bool m_shouldClearUninitializedProbes = false
 
String m_textureNamePrefix
 e.g., "G3D::DefaultRenderer::" used for switching the shaders loaded by subclasses. More...
 
bool m_traceGlossyReflections = true
 If true, ray trace glossy reflections. More...
 
shared_ptr< Shaderm_upsampleOITShader
 

Detailed Description

Supports both traditional forward shading and full-screen deferred shading.

The basic rendering algorithm is:

visible, requireForward, requireBlended = cullAndSort(all)
renderGBuffer(visible)
renderOpaqueSamples(deferredShading() ? requireForward : visible)
lighting.updateColorImage() // For the next frame
renderBlendedSamples(requireBlended, transparencyMode)
}
The DefaultRenderer::renderDeferredShading() pass uses whatever properties are available in the
GBuffer, which are controlled by the GBufferSpecification. For most applications,
it is necessary to enable the lambertian, glossy, camera-space normal,
and emissive fields to produce good results. If the current GBuffer specification
does not contain sufficient fields, most of the surfaces will take the fallback
forward shading pass at reduced performance.

\sa GApp::m_renderer, G3D::RenderDevice, G3D::Surface

Member Typedef Documentation

◆ PBOGBuffer

using G3D::DefaultRenderer::PBOGBuffer = shared_ptr<GLPixelTransferBuffer>[5]
protected

Member Enumeration Documentation

◆ Order

enum G3D::Renderer::Order
protectedinherited
Enumerator
FRONT_TO_BACK 

Good for early depth culling.

BACK_TO_FRONT 

Good for painter's algorithm sorted transparency.

ARBITRARY 

Allows minimizing state changes by batching primitives.

Constructor & Destructor Documentation

◆ DefaultRenderer()

G3D::DefaultRenderer::DefaultRenderer ( const String className = "DefaultRenderer",
const String namespacePrefix = "G3D::" 
)
protected

Member Function Documentation

◆ addVolumeInitializationFrames()

void G3D::DefaultRenderer::addVolumeInitializationFrames ( int  numInitializationFrames)
inline

◆ allocateAllOITBuffers()

virtual void G3D::DefaultRenderer::allocateAllOITBuffers ( RenderDevice rd,
bool  highPrecision = false 
)
protectedvirtual

◆ allocateOITFramebufferAttachments()

virtual void G3D::DefaultRenderer::allocateOITFramebufferAttachments ( RenderDevice rd,
const shared_ptr< Framebuffer > &  oitFramebuffer,
int  w,
int  h,
bool  highPrecision = false 
)
protectedvirtual

Called once for the high res buffer and once for the low res one from allocateAllOITBuffers.

Parameters
wDesired width of this framebuffer
hDesired height of this framebuffer

◆ className()

virtual const String& G3D::DefaultRenderer::className ( ) const
inlineoverridevirtual

Implements G3D::Renderer.

◆ clearAndRenderToOITFramebuffer()

virtual void G3D::DefaultRenderer::clearAndRenderToOITFramebuffer ( RenderDevice rd,
const shared_ptr< Framebuffer > &  oitFramebuffer,
Array< shared_ptr< Surface >> &  surfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

◆ computeGBuffer()

virtual void G3D::Renderer::computeGBuffer ( RenderDevice rd,
const Array< shared_ptr< Surface >> &  sortedVisibleSurfaces,
const shared_ptr< GBuffer > &  gbuffer,
const shared_ptr< Framebuffer > &  depthPeelFramebuffer,
float  depthPeelSeparationHint 
)
protectedvirtualinherited

Render z-prepass, depth peel, and G-buffer.

Called from render().

Parameters
gbufferMust already have had GBuffer::prepare() called
depthPeelFramebufferOnly rendered if notNull()

◆ computeLowResDepthAndNormals()

virtual void G3D::DefaultRenderer::computeLowResDepthAndNormals ( RenderDevice rd,
const shared_ptr< Texture > &  csHighResNormalTexture 
)
protectedvirtual

For OIT.

Parameters
csNormalTextureMay be nullptr

◆ computeShadowing()

virtual void G3D::Renderer::computeShadowing ( RenderDevice rd,
const Array< shared_ptr< Surface >> &  allSurfaces,
const shared_ptr< GBuffer > &  gbuffer,
const shared_ptr< Framebuffer > &  depthPeelFramebuffer,
LightingEnvironment lightingEnvironment 
)
protectedvirtualinherited

Compute ambient occlusion and direct illumination shadow maps.

◆ convergeUninitializedProbes()

void G3D::DefaultRenderer::convergeUninitializedProbes ( RenderDevice rd,
const Array< shared_ptr< Surface >> &  surfaceArray,
const shared_ptr< TriTree > &  tritree,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment lightingEnv 
)

If there are any probes in the uninitialized state, converge them.

◆ create()

static shared_ptr<Renderer> G3D::DefaultRenderer::create ( )
inlinestatic

◆ createProbeVolumes()

virtual void G3D::DefaultRenderer::createProbeVolumes ( const AABox sceneBounds,
LightingEnvironment environment,
const shared_ptr< Camera > &  camera 
)
virtual

For creating the diffuse irradiance probe volume(s).

Volumes at varying grid resolutions store irradiance (RGB10A2) and mean distance/squared-distance (RG16F). When enabled, these volumes are updated using raytracing and queried during shading (for both raytracing and rasterization) for duffise global illumination. Details in:

Majercik et al., Dynamic Diffuse Global Illumination with Ray-Traced Irradiance Fields, JCGT'19 http://jcgt.org/published/0008/02/01/

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

◆ cullAndSort()

virtual void G3D::Renderer::cullAndSort ( const shared_ptr< Camera > &  camera,
const shared_ptr< GBuffer > &  gbuffer,
const Rect2D viewport,
const Array< shared_ptr< Surface >> &  allSurfaces,
Array< shared_ptr< Surface >> &  sortedVisibleSurfaces,
Array< shared_ptr< Surface >> &  forwardOpaqueSurfaces,
Array< shared_ptr< Surface >> &  forwardBlendedSurfaces 
)
protectedvirtualinherited


Appends to sortedVisibleSurfaces and forwardSurfaces.

Parameters
sortedVisibleSurfacesAll surfaces visible to the GBuffer::camera(), sorted from back to front
forwardOpaqueSurfacesSurfaces for which Surface::canBeFullyRepresentedInGBuffer() returned false. These require a forward pass in a deferred shader. (They may be capable of deferred shading for some pixels covered, e.g., if the GBuffer did not contain a sufficient emissive channel.)
forwardBlendedSurfacesSurfaces that returned true Surface::hasBlendedTransparency() because they require per-pixel blending at some locations

◆ deferredShading()

bool G3D::DefaultRenderer::deferredShading ( ) const
inline

◆ diffuseMipLevel()

int G3D::DefaultRenderer::diffuseMipLevel ( ) const
inline

◆ diffuseRayFraction()

float G3D::DefaultRenderer::diffuseRayFraction ( ) const
inline

Fraction of rays cast that were for diffuse shading.

◆ diskFramebuffer()

bool G3D::Renderer::diskFramebuffer ( ) const
inlineinherited

◆ enableDiffuseGI()

bool G3D::DefaultRenderer::enableDiffuseGI ( )
inline

◆ enableGlossyGI()

bool G3D::DefaultRenderer::enableGlossyGI ( )
inline

◆ enableProbeRayRandomRotation()

bool G3D::DefaultRenderer::enableProbeRayRandomRotation ( )
inline

◆ forwardShade()

virtual void G3D::Renderer::forwardShade ( RenderDevice rd,
Array< shared_ptr< Surface > > &  surfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment,
const RenderPassType renderPassType,
Order  order 
)
protectedvirtualinherited

Forward shade everything in surfaceArray.

Called from render()

Parameters
surfaceArrayVisible surfaces sorted from front to back

◆ generateIrradianceRays()

void G3D::DefaultRenderer::generateIrradianceRays ( RenderDevice rd,
const int  offset,
const shared_ptr< DDGIVolume > &  ddgiVolume,
int &  numGeneratedRays,
const int  raysPerProbe 
)
protected

Generate rays for diffuse irradiance.

Uses DDGIVolume_generateRays.glc.

◆ generateMirrorRays()

void G3D::DefaultRenderer::generateMirrorRays ( RenderDevice rd,
const shared_ptr< GBuffer > &  primaryGBuffer,
int &  numGlossyRays 
)
protected
Parameters
numGlossyRaysReturns the number of rays generated; needed by generateIrradianceRays

◆ getDynamicObjectBounds()

void G3D::DefaultRenderer::getDynamicObjectBounds ( const Array< shared_ptr< Entity >> &  sceneEntities,
Array< AABox > &  dynamicBounds 
)

Compute bounds on dynamic objects to wake up sleeping probes.

◆ glossyMipLevel()

int G3D::DefaultRenderer::glossyMipLevel ( ) const
inline

◆ glossyYScale()

int G3D::DefaultRenderer::glossyYScale ( ) const
inline

◆ gRaysPerFrame()

float G3D::DefaultRenderer::gRaysPerFrame ( ) const
inline

When everything is enabled, assuming looking at a fully glossy frame.

◆ initializationFrames()

int G3D::DefaultRenderer::initializationFrames ( )
inline

◆ irradianceGBuffer()

const shared_ptr<GBuffer>& G3D::DefaultRenderer::irradianceGBuffer ( )
inline

◆ orderIndependentTransparency()

bool G3D::DefaultRenderer::orderIndependentTransparency ( ) const
inline

◆ reflectionGBuffer()

const shared_ptr<GBuffer>& G3D::DefaultRenderer::reflectionGBuffer ( )
inline

◆ reflectionTexture()

const shared_ptr<Texture>& G3D::DefaultRenderer::reflectionTexture ( )
inline

◆ render()

virtual void G3D::DefaultRenderer::render ( RenderDevice rd,
const shared_ptr< Camera > &  camera,
const shared_ptr< Framebuffer > &  framebuffer,
const shared_ptr< Framebuffer > &  depthPeelFramebuffer,
LightingEnvironment lightingEnvironment,
const shared_ptr< GBuffer > &  gbuffer,
const Array< shared_ptr< Surface >> &  allSurfaces,
const std::function< const shared_ptr< TriTree > &()> &  tritreeFunction = nullptr 
)
overridevirtual


The active camera and time interval are taken from the GBuffer.

Parameters
framebufferTarget color and depth framebuffer. Will be rendered in high dynamic range (HDR) linear radiance.
gbufferMust be allocated, sized, and prepared. Will be rendered according to its specification by this method.
allSurfacesSurfaces not visible to the camera will automatically be culled
depthPeelFramebufferMay be nullptr
lightingEnvironmentShadow maps will be updated for any lights that require them. AO will be updated if the ambientOcclusion field is non-nullptr. Screen-space color buffer will be updated with textures the next frame.
tritreeThe BVH for ray tracing queries.

Implements G3D::Renderer.

◆ renderDeferredShading()

virtual void G3D::DefaultRenderer::renderDeferredShading ( RenderDevice rd,
const Array< shared_ptr< Surface > > &  sortedVisibleSurfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

◆ renderIndirectIllumination()

virtual void G3D::DefaultRenderer::renderIndirectIllumination ( RenderDevice rd,
const Array< shared_ptr< Surface > > &  sortedVisibleSurfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment,
const shared_ptr< TriTree > &  tritree = nullptr 
)
protectedvirtual

Subclasses that can compute global illumination to deferred shading buffers should override this method, which is invoked before renderDeferredShading.

◆ renderOpaqueSamples()

virtual void G3D::DefaultRenderer::renderOpaqueSamples ( RenderDevice rd,
Array< shared_ptr< Surface > > &  surfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

◆ renderOpaqueScreenSpaceRefractingSamples()

virtual void G3D::DefaultRenderer::renderOpaqueScreenSpaceRefractingSamples ( RenderDevice rd,
Array< shared_ptr< Surface > > &  surfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

◆ renderOrderIndependentBlendedSamples()

virtual void G3D::DefaultRenderer::renderOrderIndependentBlendedSamples ( RenderDevice rd,
Array< shared_ptr< Surface > > &  surfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

◆ renderSortedBlendedSamples()

virtual void G3D::DefaultRenderer::renderSortedBlendedSamples ( RenderDevice rd,
Array< shared_ptr< Surface > > &  surfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

◆ resizeIrradianceRayTextures()

void G3D::DefaultRenderer::resizeIrradianceRayTextures ( const int  raysPerProbe = -1)
protected

◆ resizeOITBuffersIfNeeded()

virtual void G3D::DefaultRenderer::resizeOITBuffersIfNeeded ( const int  width,
const int  height,
const int  lowResWidth,
const int  lowResHeight 
)
protectedvirtual

For OIT.

◆ resizeReflectionRayTextures()

void G3D::DefaultRenderer::resizeReflectionRayTextures ( const int  screenWidth,
const int  screenHeight 
)
protected

◆ sampleArbitraryRays()

void G3D::DefaultRenderer::sampleArbitraryRays ( const shared_ptr< Texture > &  rayOrigins,
const shared_ptr< Texture > &  rayDirections,
const shared_ptr< TriTree > &  tritree,
const shared_ptr< GBuffer > &  gbuffer,
const int  totalRays,
const unsigned int  visibilityMask,
const int  mipLevel = 0 
)
protected

Trace an arbitrary buffer of rays to fill a GBuffer.

◆ setDeferredShading()

void G3D::DefaultRenderer::setDeferredShading ( bool  b)
inline

If true, use deferred shading on all surfaces that can be represented by the GBuffer.

Default is false.

◆ setDeferredShadingArgs()

virtual void G3D::DefaultRenderer::setDeferredShadingArgs ( Args args,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment 
)
protectedvirtual

Called by DefaultRenderer::renderDeferredShading to configure the inputs to deferred shading.

◆ setDiffuseMipLevel()

void G3D::DefaultRenderer::setDiffuseMipLevel ( int  i)
inline

◆ setDiskFramebuffer()

void G3D::Renderer::setDiskFramebuffer ( bool  b)
inlineinherited

◆ setEnableDiffuseGI()

void G3D::DefaultRenderer::setEnableDiffuseGI ( bool  b)
inline

◆ setEnableGlossyGI()

void G3D::DefaultRenderer::setEnableGlossyGI ( bool  b)
inline

◆ setEnableProbeRayRandomRotation()

void G3D::DefaultRenderer::setEnableProbeRayRandomRotation ( bool  b)
inline

◆ setGlossyMipLevel()

void G3D::DefaultRenderer::setGlossyMipLevel ( int  i)
inline

◆ setGlossyYScale()

void G3D::DefaultRenderer::setGlossyYScale ( int  i)
inline

◆ setOrderIndependentTransparency()

void G3D::DefaultRenderer::setOrderIndependentTransparency ( bool  b)
inline

If true, uses OIT.

Default is false.

The current implementation is based on:

McGuire and Bavoil, Weighted Blended Order-Independent Transparency, Journal of Computer Graphics Techniques (JCGT), vol. 2, no. 2, 122–141, 2013 Available online http://jcgt.org/published/0002/02/09/

This can be turned on in both forward and deferred shading modes.

This algorithm improves the quality of overlapping transparent surfaces for many scenes, eliminating popping and confusing appearance that can arise from imperfect sorting. It is especially helpful in scenes with lots of particles. This technique has relatively low overhead compared to alternative methods.

◆ setReflectionTexture()

void G3D::DefaultRenderer::setReflectionTexture ( const shared_ptr< GLPixelTransferBuffer > &  pbo)
inline

◆ setTraceGlossyReflections()

void G3D::DefaultRenderer::setTraceGlossyReflections ( bool  b)
inline

◆ shadeArbitraryRays()

void G3D::DefaultRenderer::shadeArbitraryRays ( RenderDevice rd,
const Array< shared_ptr< Surface >> &  surfaceArray,
const shared_ptr< Framebuffer > &  targetFramebuffer,
const LightingEnvironment environment,
const shared_ptr< Texture > &  rayOrigins,
const shared_ptr< Texture > &  rayDirections,
const shared_ptr< GBuffer > &  gbuffer,
const bool  useProbeIndirect,
const bool  glossyToMatte 
)
protected

Run the deferred shader on a gbuffer of arbitrary ray data.

◆ traceAndUpdateProbes()

void G3D::DefaultRenderer::traceAndUpdateProbes ( RenderDevice rd,
const Array< shared_ptr< Surface >> &  surfaceArray,
const shared_ptr< TriTree > &  tritree,
const shared_ptr< GBuffer > &  primaryGBuffer,
const LightingEnvironment environment,
const int  raysPerProbe,
const unsigned int  visibilityMask 
)

Update the probe data structure.

Called multiple times from updateDiffuseGI to intialize different sets of probes in different states.

◆ traceGlossyIndirectIllumination()

void G3D::DefaultRenderer::traceGlossyIndirectIllumination ( RenderDevice rd,
const Array< shared_ptr< Surface > > &  sortedVisibleSurfaceArray,
const shared_ptr< GBuffer > &  gbuffer,
const LightingEnvironment environment,
const shared_ptr< TriTree > &  tritree = nullptr 
)

Trace half-res rays to resolve glossy ilumination.

If diffuse GI is enabled, uses irradiance volume for second-order glossy reflections.

◆ traceGlossyReflections()

bool G3D::DefaultRenderer::traceGlossyReflections ( )
inline

◆ updateDiffuseGI()

virtual void G3D::DefaultRenderer::updateDiffuseGI ( RenderDevice rd,
const shared_ptr< Scene > &  scene,
const shared_ptr< GBuffer > &  primaryGBuffer,
const shared_ptr< Camera > &  camera 
)
virtual

Resolve probe states and update the irradiance probe volume.

Member Data Documentation

◆ CAMERA_TRACK

const int G3D::DefaultRenderer::CAMERA_TRACK = 2
static

◆ m_backgroundFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_backgroundFramebuffer
protected

Captured image of the background used for blurs for OIT.

◆ m_blurredMIPReflectionFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_blurredMIPReflectionFramebuffer
protected

For computing blurred mirror reflections to approximate gathered glossy reflections.

The mip levels are progressively blurred versions.

Referenced by reflectionTexture(), and setReflectionTexture().

◆ m_bounds

AABox G3D::DefaultRenderer::m_bounds

◆ m_compositeOITShader

shared_ptr<Shader> G3D::DefaultRenderer::m_compositeOITShader
protected

◆ m_csOctLowResNormalFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_csOctLowResNormalFramebuffer
protected

Used for resampling normals during computeLowResDepthAndNormals for later upsampling under OIT.

Has a single RG8_SNORM texture that is camera-space octahedrally encoded normals.

◆ m_ddgiVolumeArray

Array<shared_ptr<DDGIVolume> > G3D::DefaultRenderer::m_ddgiVolumeArray

◆ m_deferredShader

shared_ptr<Shader> G3D::DefaultRenderer::m_deferredShader
protected

Because subclasses can change the shader filename prefix, we must use member variables instead of the static variables created by LAUNCH_SHADER to store the shaders.

These are loaded just before use.

◆ m_deferredShading

bool G3D::DefaultRenderer::m_deferredShading
protected

◆ m_diffuseMipLevel

int G3D::DefaultRenderer::m_diffuseMipLevel = 8
protected

Specifies the mip level at which to sample textures for irradiance and glossy rays.

Referenced by diffuseMipLevel(), and setDiffuseMipLevel().

◆ m_diskFramebuffer

bool G3D::Renderer::m_diskFramebuffer = false
protectedinherited

For VR.

Default is false.

Referenced by G3D::Renderer::diskFramebuffer(), and G3D::Renderer::setDiskFramebuffer().

◆ m_enableDiffuseGI

bool G3D::DefaultRenderer::m_enableDiffuseGI = false
protected

Ray traced diffuse global illumination using DDGI.

Referenced by enableDiffuseGI(), and setEnableDiffuseGI().

◆ m_enableGlossyGI

bool G3D::DefaultRenderer::m_enableGlossyGI = false
protected

Renders the glossy pass for primary rays each frame.

Referenced by enableGlossyGI(), and setEnableGlossyGI().

◆ m_enableProbeRayRandomRotation

bool G3D::DefaultRenderer::m_enableProbeRayRandomRotation = true
protected

◆ m_energyPreservation

float G3D::DefaultRenderer::m_energyPreservation = 0.95f

How much should the probes count when shading themselves? 1.0 preserves energy perfectly.

Lower numbers compensate for small leaks/precision by avoiding recursive energy explosion.

◆ m_gaussianMIPFilter

shared_ptr<GaussianMIPFilter> G3D::DefaultRenderer::m_gaussianMIPFilter
protected

◆ m_glossyGIFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_glossyGIFramebuffer

◆ m_glossyMipLevel

int G3D::DefaultRenderer::m_glossyMipLevel = 3
protected

◆ m_glossyYScale

int G3D::DefaultRenderer::m_glossyYScale = 2
protected

Referenced by glossyYScale(), and setGlossyYScale().

◆ m_irradianceRayDirectionsTexture

shared_ptr<Texture> G3D::DefaultRenderer::m_irradianceRayDirectionsTexture
protected

◆ m_irradianceRayOriginsTexture

shared_ptr<Texture> G3D::DefaultRenderer::m_irradianceRayOriginsTexture
protected

Textures storing ray origins and directions for irradiance probe sampling, regenerated every frame and then split between all probes according to a given heuristic.

Referenced by diffuseRayFraction().

◆ m_irradianceRaysGBuffer

shared_ptr<GBuffer> G3D::DefaultRenderer::m_irradianceRaysGBuffer
protected

Referenced by irradianceGBuffer().

◆ m_irradianceRaysShadedFB

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_irradianceRaysShadedFB
protected

◆ m_newlyXProbes

bool G3D::DefaultRenderer::m_newlyXProbes = false
protected

◆ m_numInitializationFrames

int G3D::DefaultRenderer::m_numInitializationFrames = 0
protected

Number of frames to spend initializing probes if any volume has uninitialized probes.

Triggered on scene load, volume creation, and leap-frogging on a camera-locked volume.

Referenced by addVolumeInitializationFrames(), and initializationFrames().

◆ m_oitFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_oitFramebuffer
protected

For the transparent surface pass of the OIT algorithm.

Shares the depth buffer with the main framebuffer. The subsequent compositing pass uses the regular framebuffer in 2D mode.

This framebuffer has several color render targets bound. For details, see:

McGuire and Mara, A Phenomenological Scattering Model for Order-Independent Transparency, I3D'16 http://graphics.cs.williams.edu/papers/TransparencyI3D16/

It shares the depth with the original framebuffer but does not write to it.

◆ m_oitHighPrecision

bool G3D::DefaultRenderer::m_oitHighPrecision
protected

If true, all OIT buffers will be in 32-bit floating point.

Default is false.

◆ m_oitLowResDownsampleFactor

int G3D::DefaultRenderer::m_oitLowResDownsampleFactor
protected

Hi-res pixels per low-res pixel, along one dimension.

(1 is identical resolution, 4 would be quarter-res, which is 1/16 the number of pixels).

Default is 4.

Set to 1 to disable low resolution OIT.

◆ m_oitLowResFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_oitLowResFramebuffer
protected

A low resolution version of m_oitFramebuffer.

◆ m_oitUpsampleFilterRadius

int G3D::DefaultRenderer::m_oitUpsampleFilterRadius
protected

Default is 1.

◆ m_oitWriteDeclarationGLSLFilename

String G3D::DefaultRenderer::m_oitWriteDeclarationGLSLFilename
protected

Loaded by the constructor, but subclasses may replace it in their own constructors.

The default implementation is Weighted-Blended Order Independent Transparency by McGuire and Bavoil. This string can be overwritten to implement alternative algorithms, such as Adaptive Transparency. However, new buffers may need to be set by overriding renderOrderIndependentBlendedSamples() for certain algorithms.

◆ m_orderIndependentTransparency

bool G3D::DefaultRenderer::m_orderIndependentTransparency
protected

◆ m_pboGBuffer

PBOGBuffer G3D::DefaultRenderer::m_pboGBuffer
protected

◆ m_rayOriginsAndDirectionsTable

Table<shared_ptr<Texture>, shared_ptr<GLPixelTransferBuffer> > G3D::DefaultRenderer::m_rayOriginsAndDirectionsTable
protected

◆ m_raysThisFrame

int G3D::DefaultRenderer::m_raysThisFrame = 0

Referenced by gRaysPerFrame().

◆ m_reflectionGBuffer

shared_ptr<GBuffer> G3D::DefaultRenderer::m_reflectionGBuffer
protected

Referenced by reflectionGBuffer().

◆ m_reflectionRayDirectionsTexture

shared_ptr<Texture> G3D::DefaultRenderer::m_reflectionRayDirectionsTexture
protected

◆ m_reflectionRayOriginsTexture

shared_ptr<Texture> G3D::DefaultRenderer::m_reflectionRayOriginsTexture
protected

Ray textures for reflection rays.

Referenced by diffuseRayFraction().

◆ m_shadedMirrorRaysFramebuffer

shared_ptr<Framebuffer> G3D::DefaultRenderer::m_shadedMirrorRaysFramebuffer
protected

Only used when half-resolution glossy is in effect.

Otherwise, we render straight into m_blurredMIPReflectionFramebuffer

◆ m_shaderName

String G3D::DefaultRenderer::m_shaderName
protected

e.g., "DefaultRenderer" used for switching the shaders loaded by subclasses.

◆ m_shouldClearUninitializedProbes

bool G3D::DefaultRenderer::m_shouldClearUninitializedProbes = false
protected

◆ m_showProbeLocations

Array<bool> G3D::DefaultRenderer::m_showProbeLocations

◆ m_textureNamePrefix

String G3D::DefaultRenderer::m_textureNamePrefix
protected

e.g., "G3D::DefaultRenderer::" used for switching the shaders loaded by subclasses.

◆ m_traceGlossyReflections

bool G3D::DefaultRenderer::m_traceGlossyReflections = true
protected

If true, ray trace glossy reflections.

Referenced by setTraceGlossyReflections(), and traceGlossyReflections().

◆ m_upsampleOITShader

shared_ptr<Shader> G3D::DefaultRenderer::m_upsampleOITShader
protected

◆ SCENE_INIT

const int G3D::DefaultRenderer::SCENE_INIT = 5
static

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