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


Sparse Voxel Octree: (compressed) 3D Analog of a GBuffer. More...

Inherits G3D::ReferenceCountedObject.

Public Types

typedef GBuffer::Field Field
 
typedef GBuffer::Specification Specification
 CS_POSITION is used for octree-space position, so. More...
 

Public Member Functions

void bindReadUniformsFragmentBuffer (Args &args) const
 
void bindWriteUniformsFragmentBuffer (Args &args) const
 
const Boxbounds () const
 Bounds on the elements that were voxelized, not on the octtree itself. More...
 
void build (RenderDevice *, bool multiPass=false, bool dummyPass=false, int curPass=0)
 Build octree from fragment data. More...
 
const shared_ptr< Cameracamera () const
 If null, there is no clipping frustum. More...
 
void clearFragmentCounter ()
 
void complete (RenderDevice *, const G3D::String &downSampleShader=G3D::String("SVO_downsampleValues.glc"))
 Build the actual oct-tree. More...
 
void connectToShader (Args &args, Access access, int maxTreeDepth, int level) const
 
void debugPrintIndexBuffer ()
 
void debugPrintRootIndexBuffer ()
 
void filter (RenderDevice *, const G3D::String &downSampleShader=G3D::String("SVO_downsampleValues.glc"))
 Filter octree data. More...
 
int fineVoxelResolution () const
 Number of voxels along each edge at the finest resolution. More...
 
shared_ptr< Framebufferframebuffer () const
 The framebuffer bound during rendering by Surface::renderIntoSVO. More...
 
shared_ptr< BufferTexturegetChildIndexBuffer ()
 
shared_ptr< GBuffergetGBuffer ()
 
shared_ptr< BufferTexturegetNeighborsIndexBuffer ()
 
int getNumSurfaceLayers ()
 
size_t getTopDenseTreeNumNodes (int depth=(6 - 1))
 
shared_ptr< GBuffergetTopMipMapGBuffer ()
 
void init (RenderDevice *rd, size_t svoPoolSize, int maxTreeDepth, size_t fragmentPoolSize)
 
void loadFromDisk (const std::string &fileName)
 
int maxDepth ()
 
const Stringname () const
 
void postBuild (RenderDevice *)
 
void preBuild (RenderDevice *, bool multiPass=false, bool dummyPass=false)
 
void prepare (RenderDevice *rd, const shared_ptr< Camera > &camera, const Box &wsBounds, float timeOffset, float velocityStartTimeOffset, size_t svoPoolSize, int maxTreeDepth, size_t fragmentPoolSize)
 Bind and clear the data structure. More...
 
void prepare (RenderDevice *rd, const shared_ptr< Camera > &camera, const Box &wsBounds, float timeOffset, float velocityStartTimeOffset)
 
void printDebugBuild ()
 
void renderRaycasting (RenderDevice *rd, shared_ptr< Texture > m_colorBuffer0, int level, float raycastingConeFactor)
 
void saveToDisk (const std::string &fileName)
 
void setCurSvoId (int id)
 
void setOrthogonalProjection (RenderDevice *rd) const
 Bind the camera and projection matrices for generating the SVO. More...
 
const Specificationspecification () const
 
CFrame svoToWorldMatrix () const
 
void visualizeFragments (RenderDevice *rd) const
 Draw the raw fragments as points for debugging purposes. More...
 
void visualizeNodes (RenderDevice *rd, int level) const
 
float voxelSideLength () const
 Length of each side of a voxel. More...
 
CFrame worldToSVOMatrix () const
 
const StringwriteDeclarationsFragmentBuffer () const
 

Static Public Member Functions

static shared_ptr< SVOcreate (const Specification &spec=Specification(), const String &name="SVO", bool usebricks=false)
 Requires a floating point WS_POSITION field. More...
 

Public Attributes

size_t m_levelsNumNodes [16+1]
 
Vector2 projectionOffset
 
float projectionScale
 

Protected Member Functions

 SVO (const Specification &spec, const String &name, bool usebricks)
 
void connectOctreeToShader (Args &args, Access access, int maxTreeDepth, int level=-1) const
 
void copyScaleVal (RenderDevice *rd, shared_ptr< BufferTexture > &srcBuffer, shared_ptr< BufferTexture > &dstBuffer, int srcIndex, int dstIndex, int mulFactor, int divFactor)
 
void fillBuffer (shared_ptr< GLPixelTransferBuffer > buffer, uint numVal, uint val)
 
uint64 getBufferGPUAddress (const shared_ptr< BufferTexture > &buff) const
 
void updateDispatchIndirectBuffer (RenderDevice *rd, shared_ptr< BufferTexture > &dispatchIndirectBuffer, shared_ptr< BufferTexture > &startIndexBuffer, shared_ptr< BufferTexture > &endIndexBuffer, int startLevel, int endLevel, Vector2int32 workGroupSize)
 

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

int BUFFER_WIDTH
 We pack all of the material data into 2D textures, which are really just 1D wrapped at this width. More...
 
Box m_bounds
 
int m_brickBorderSize
 
int m_brickNumLevels
 
Vector3int16 m_brickRes
 
Vector3int16 m_brickResWithBorder
 
shared_ptr< Cameram_camera
 
shared_ptr< BufferTexturem_childIndex
 
int m_curSvoId
 
shared_ptr< BufferTexturem_dispatchIndirectBuffer
 The arguments for an indirect compute call to process the m_fragmentBuffer. More...
 
shared_ptr< BufferTexturem_dispatchIndirectLevelBuffer
 The arguments for an indirect compute call to process the next level of a tree. More...
 
shared_ptr< BufferTexturem_drawIndirectBuffer
 The arguments for an indirect draw call to visualize the octree. More...
 
shared_ptr< Framebufferm_dummyFramebuffer
 Used to force the fragment rasterization resolution. More...
 
shared_ptr< GBufferm_fragmentBuffer
 Storage for voxel fragments produced by Surface::renderIntoSVO before the tree is built. More...
 
shared_ptr< BufferTexturem_fragmentCount
 Number of allocated elements in m_fragmentBuffer. More...
 
shared_ptr< BufferTexturem_fragmentsDrawIndirectBuffer
 The arguments for an indirect draw call to visualize the m_fragmentBuffer. More...
 
size_t m_fragVoxelMemSize
 
shared_ptr< GBufferm_gbuffer
 The underlying output is stored in a gbuffer. More...
 
bool m_initOK
 
shared_ptr< BufferTexturem_levelIndexBuffer
 m_levelIndexBuffer[0] is the number of allocated nodes. More...
 
shared_ptr< BufferTexturem_levelSizeBuffer
 NEW: Allocated size for each mip level. More...
 
shared_ptr< BufferTexturem_levelStartIndexBuffer
 NEW: Offset for the allocation of each level. More...
 
int m_max2DTextureSize
 
int m_max3DTextureSize
 
Vector3int32 m_maxComputeGridDims
 
int m_maxTreeDepth
 
const String m_name
 
shared_ptr< BufferTexturem_neighborsIndex
 
shared_ptr< BufferTexturem_numberOfAllocatedNodes
 The number of nodes already allocated in m_childIndex (NOT the index of the next node, which is this * 8) More...
 
int m_numSurfaceLayers
 
int m_octreeBias
 
uint m_octreePoolNumNodes
 
shared_ptr< BufferTexturem_parentIndex
 
shared_ptr< BufferTexturem_prevNodeCountBuffer
 NEW. More...
 
shared_ptr< Profilerm_profiler
 Performance profiler. More...
 
shared_ptr< BufferTexturem_rootIndex
 
R32I pointers to children of nodes. More...
 
const Specification m_specification
 
size_t m_svoVoxelMemSize
 
Sampler m_textureSampler
 
float m_timeOffset
 
shared_ptr< GBufferm_topMipMapGBuffer
 GBuffer containing octree top mipMAp. More...
 
int m_topMipMapMaxLevel
 
int m_topMipMapNumLevels
 
int m_topMipMapRes
 
bool m_useBricks
 
bool m_useNeighborPointers
 
bool m_useTopMipMap
 
shared_ptr< Shaderm_visualizeNodes
 
String m_writeDeclarationsFragmentBuffer
 

Detailed Description


Sparse Voxel Octree: (compressed) 3D Analog of a GBuffer.

The algorithm operates in three passes:

  1. prepare (initialize data structures)
  2. render voxel fragments (Surface::renderIntoSVO)
  3. complete (build the tree)

The octree always fills a cube (it is sparse, so very little space is lost if the aspect ratio is more extreme)

Member Typedef Documentation

◆ Field

◆ Specification

CS_POSITION is used for octree-space position, so.

Constructor & Destructor Documentation

◆ SVO()

G3D::SVO::SVO ( const Specification spec,
const String name,
bool  usebricks 
)
protected

Member Function Documentation

◆ bindReadUniformsFragmentBuffer()

void G3D::SVO::bindReadUniformsFragmentBuffer ( Args args) const

◆ bindWriteUniformsFragmentBuffer()

void G3D::SVO::bindWriteUniformsFragmentBuffer ( Args args) const

◆ bounds()

const Box& G3D::SVO::bounds ( ) const
inline

Bounds on the elements that were voxelized, not on the octtree itself.

◆ build()

void G3D::SVO::build ( RenderDevice ,
bool  multiPass = false,
bool  dummyPass = false,
int  curPass = 0 
)

Build octree from fragment data.

Multipass mode require a dummy pre-pass in order to allocate per-level memory.

◆ camera()

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

If null, there is no clipping frustum.

◆ clearFragmentCounter()

void G3D::SVO::clearFragmentCounter ( )

◆ complete()

void G3D::SVO::complete ( RenderDevice ,
const G3D::String downSampleShader = G3D::String("SVO_downsampleValues.glc") 
)

Build the actual oct-tree.

Call after Surface::renderIntoSVO().

◆ connectOctreeToShader()

void G3D::SVO::connectOctreeToShader ( Args args,
Access  access,
int  maxTreeDepth,
int  level = -1 
) const
protected

◆ connectToShader()

void G3D::SVO::connectToShader ( Args args,
Access  access,
int  maxTreeDepth,
int  level 
) const

◆ copyScaleVal()

void G3D::SVO::copyScaleVal ( RenderDevice rd,
shared_ptr< BufferTexture > &  srcBuffer,
shared_ptr< BufferTexture > &  dstBuffer,
int  srcIndex,
int  dstIndex,
int  mulFactor,
int  divFactor 
)
protected

◆ create()

static shared_ptr<SVO> G3D::SVO::create ( const Specification spec = Specification(),
const String name = "SVO",
bool  usebricks = false 
)
static

Requires a floating point WS_POSITION field.

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

◆ debugPrintIndexBuffer()

void G3D::SVO::debugPrintIndexBuffer ( )

◆ debugPrintRootIndexBuffer()

void G3D::SVO::debugPrintRootIndexBuffer ( )

◆ fillBuffer()

void G3D::SVO::fillBuffer ( shared_ptr< GLPixelTransferBuffer buffer,
uint  numVal,
uint  val 
)
protected

◆ filter()

void G3D::SVO::filter ( RenderDevice ,
const G3D::String downSampleShader = G3D::String("SVO_downsampleValues.glc") 
)

Filter octree data.

◆ fineVoxelResolution()

int G3D::SVO::fineVoxelResolution ( ) const
inline

Number of voxels along each edge at the finest resolution.

Referenced by voxelSideLength().

◆ framebuffer()

shared_ptr<Framebuffer> G3D::SVO::framebuffer ( ) const
inline

The framebuffer bound during rendering by Surface::renderIntoSVO.

It is not actually rendered into, however

◆ getBufferGPUAddress()

uint64 G3D::SVO::getBufferGPUAddress ( const shared_ptr< BufferTexture > &  buff) const
protected

◆ getChildIndexBuffer()

shared_ptr<BufferTexture> G3D::SVO::getChildIndexBuffer ( )
inline

◆ getGBuffer()

shared_ptr<GBuffer> G3D::SVO::getGBuffer ( )
inline

◆ getNeighborsIndexBuffer()

shared_ptr<BufferTexture> G3D::SVO::getNeighborsIndexBuffer ( )
inline

◆ getNumSurfaceLayers()

int G3D::SVO::getNumSurfaceLayers ( )
inline

◆ getTopDenseTreeNumNodes()

size_t G3D::SVO::getTopDenseTreeNumNodes ( int  depth = ( 6  - 1))
inline

◆ getTopMipMapGBuffer()

shared_ptr<GBuffer> G3D::SVO::getTopMipMapGBuffer ( )
inline

◆ init()

void G3D::SVO::init ( RenderDevice rd,
size_t  svoPoolSize,
int  maxTreeDepth,
size_t  fragmentPoolSize 
)

◆ loadFromDisk()

void G3D::SVO::loadFromDisk ( const std::string &  fileName)

◆ maxDepth()

int G3D::SVO::maxDepth ( )
inline

◆ name()

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

◆ postBuild()

void G3D::SVO::postBuild ( RenderDevice )

◆ preBuild()

void G3D::SVO::preBuild ( RenderDevice ,
bool  multiPass = false,
bool  dummyPass = false 
)

◆ prepare() [1/2]

void G3D::SVO::prepare ( RenderDevice rd,
const shared_ptr< Camera > &  camera,
const Box wsBounds,
float  timeOffset,
float  velocityStartTimeOffset,
size_t  svoPoolSize,
int  maxTreeDepth,
size_t  fragmentPoolSize 
)

Bind and clear the data structure.

Call before Surface::renderIntoSVO()

Parameters
cameraThe voxelization is clipped to the camera's frustum if the camera is non-null
wsBoundsThe world-space bounds of the voxelization. For example,
camera->frustum(viewport)->boundingBox(1000)
maxTreeDepth
fragmentPoolSizeMaximum number of fragments expected from Surface::renderIntoSVO. Proportional to the area of the scene. There can be many fragments within a single voxel that will later be collapsed.

◆ prepare() [2/2]

void G3D::SVO::prepare ( RenderDevice rd,
const shared_ptr< Camera > &  camera,
const Box wsBounds,
float  timeOffset,
float  velocityStartTimeOffset 
)

◆ printDebugBuild()

void G3D::SVO::printDebugBuild ( )

◆ renderRaycasting()

void G3D::SVO::renderRaycasting ( RenderDevice rd,
shared_ptr< Texture m_colorBuffer0,
int  level,
float  raycastingConeFactor 
)

◆ saveToDisk()

void G3D::SVO::saveToDisk ( const std::string &  fileName)

◆ setCurSvoId()

void G3D::SVO::setCurSvoId ( int  id)
inline

◆ setOrthogonalProjection()

void G3D::SVO::setOrthogonalProjection ( RenderDevice rd) const

Bind the camera and projection matrices for generating the SVO.

Used by Surface::renderIntoSVO

◆ specification()

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

◆ svoToWorldMatrix()

CFrame G3D::SVO::svoToWorldMatrix ( ) const

◆ updateDispatchIndirectBuffer()

void G3D::SVO::updateDispatchIndirectBuffer ( RenderDevice rd,
shared_ptr< BufferTexture > &  dispatchIndirectBuffer,
shared_ptr< BufferTexture > &  startIndexBuffer,
shared_ptr< BufferTexture > &  endIndexBuffer,
int  startLevel,
int  endLevel,
Vector2int32  workGroupSize 
)
protected

◆ visualizeFragments()

void G3D::SVO::visualizeFragments ( RenderDevice rd) const

Draw the raw fragments as points for debugging purposes.

◆ visualizeNodes()

void G3D::SVO::visualizeNodes ( RenderDevice rd,
int  level 
) const

◆ voxelSideLength()

float G3D::SVO::voxelSideLength ( ) const
inline

Length of each side of a voxel.

◆ worldToSVOMatrix()

CFrame G3D::SVO::worldToSVOMatrix ( ) const

◆ writeDeclarationsFragmentBuffer()

const String& G3D::SVO::writeDeclarationsFragmentBuffer ( ) const
inline

Member Data Documentation

◆ BUFFER_WIDTH

int G3D::SVO::BUFFER_WIDTH
protected

We pack all of the material data into 2D textures, which are really just 1D wrapped at this width.

◆ m_bounds

Box G3D::SVO::m_bounds
protected

Referenced by bounds(), and voxelSideLength().

◆ m_brickBorderSize

int G3D::SVO::m_brickBorderSize
protected

◆ m_brickNumLevels

int G3D::SVO::m_brickNumLevels
protected

◆ m_brickRes

Vector3int16 G3D::SVO::m_brickRes
protected

◆ m_brickResWithBorder

Vector3int16 G3D::SVO::m_brickResWithBorder
protected

◆ m_camera

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

Referenced by camera().

◆ m_childIndex

shared_ptr<BufferTexture> G3D::SVO::m_childIndex
protected

Referenced by getChildIndexBuffer().

◆ m_curSvoId

int G3D::SVO::m_curSvoId
protected

Referenced by setCurSvoId().

◆ m_dispatchIndirectBuffer

shared_ptr<BufferTexture> G3D::SVO::m_dispatchIndirectBuffer
protected

The arguments for an indirect compute call to process the m_fragmentBuffer.

◆ m_dispatchIndirectLevelBuffer

shared_ptr<BufferTexture> G3D::SVO::m_dispatchIndirectLevelBuffer
protected

The arguments for an indirect compute call to process the next level of a tree.

The fourth element is the number of threads desired.

◆ m_drawIndirectBuffer

shared_ptr<BufferTexture> G3D::SVO::m_drawIndirectBuffer
protected

The arguments for an indirect draw call to visualize the octree.

◆ m_dummyFramebuffer

shared_ptr<Framebuffer> G3D::SVO::m_dummyFramebuffer
protected

Used to force the fragment rasterization resolution.

Not actually written to.

Referenced by framebuffer().

◆ m_fragmentBuffer

shared_ptr<GBuffer> G3D::SVO::m_fragmentBuffer
protected

Storage for voxel fragments produced by Surface::renderIntoSVO before the tree is built.

The size of this buffer is proportional to the surface area of the scene.

◆ m_fragmentCount

shared_ptr<BufferTexture> G3D::SVO::m_fragmentCount
protected

Number of allocated elements in m_fragmentBuffer.

◆ m_fragmentsDrawIndirectBuffer

shared_ptr<BufferTexture> G3D::SVO::m_fragmentsDrawIndirectBuffer
protected

The arguments for an indirect draw call to visualize the m_fragmentBuffer.

◆ m_fragVoxelMemSize

size_t G3D::SVO::m_fragVoxelMemSize
protected

◆ m_gbuffer

shared_ptr<GBuffer> G3D::SVO::m_gbuffer
protected

The underlying output is stored in a gbuffer.

Referenced by getGBuffer().

◆ m_initOK

bool G3D::SVO::m_initOK
protected

◆ m_levelIndexBuffer

shared_ptr<BufferTexture> G3D::SVO::m_levelIndexBuffer
protected

m_levelIndexBuffer[0] is the number of allocated nodes.

m_levelIndexBuffer[i] is the offset into m_childIndex of the first node for level (i - 1) of the tree.

◆ m_levelSizeBuffer

shared_ptr<BufferTexture> G3D::SVO::m_levelSizeBuffer
protected

NEW: Allocated size for each mip level.

◆ m_levelsNumNodes

size_t G3D::SVO::m_levelsNumNodes[16+1]

◆ m_levelStartIndexBuffer

shared_ptr<BufferTexture> G3D::SVO::m_levelStartIndexBuffer
protected

NEW: Offset for the allocation of each level.

◆ m_max2DTextureSize

int G3D::SVO::m_max2DTextureSize
protected

◆ m_max3DTextureSize

int G3D::SVO::m_max3DTextureSize
protected

◆ m_maxComputeGridDims

Vector3int32 G3D::SVO::m_maxComputeGridDims
protected

◆ m_maxTreeDepth

int G3D::SVO::m_maxTreeDepth
protected

Referenced by fineVoxelResolution(), and maxDepth().

◆ m_name

const String G3D::SVO::m_name
protected

Referenced by name().

◆ m_neighborsIndex

shared_ptr<BufferTexture> G3D::SVO::m_neighborsIndex
protected

Referenced by getNeighborsIndexBuffer().

◆ m_numberOfAllocatedNodes

shared_ptr<BufferTexture> G3D::SVO::m_numberOfAllocatedNodes
protected

The number of nodes already allocated in m_childIndex (NOT the index of the next node, which is this * 8)

◆ m_numSurfaceLayers

int G3D::SVO::m_numSurfaceLayers
protected

Referenced by getNumSurfaceLayers().

◆ m_octreeBias

int G3D::SVO::m_octreeBias
protected

Referenced by fineVoxelResolution().

◆ m_octreePoolNumNodes

uint G3D::SVO::m_octreePoolNumNodes
protected

◆ m_parentIndex

shared_ptr<BufferTexture> G3D::SVO::m_parentIndex
protected

◆ m_prevNodeCountBuffer

shared_ptr<BufferTexture> G3D::SVO::m_prevNodeCountBuffer
protected

NEW.

◆ m_profiler

shared_ptr<Profiler> G3D::SVO::m_profiler
protected

Performance profiler.

◆ m_rootIndex

shared_ptr<BufferTexture> G3D::SVO::m_rootIndex
protected


R32I pointers to children of nodes.

Each node is a 2^3 block.

◆ m_specification

const Specification G3D::SVO::m_specification
protected

Referenced by specification().

◆ m_svoVoxelMemSize

size_t G3D::SVO::m_svoVoxelMemSize
protected

◆ m_textureSampler

Sampler G3D::SVO::m_textureSampler
protected

◆ m_timeOffset

float G3D::SVO::m_timeOffset
protected

◆ m_topMipMapGBuffer

shared_ptr<GBuffer> G3D::SVO::m_topMipMapGBuffer
protected

GBuffer containing octree top mipMAp.

Referenced by getTopMipMapGBuffer().

◆ m_topMipMapMaxLevel

int G3D::SVO::m_topMipMapMaxLevel
protected

Referenced by getTopDenseTreeNumNodes().

◆ m_topMipMapNumLevels

int G3D::SVO::m_topMipMapNumLevels
protected

◆ m_topMipMapRes

int G3D::SVO::m_topMipMapRes
protected

◆ m_useBricks

bool G3D::SVO::m_useBricks
protected

◆ m_useNeighborPointers

bool G3D::SVO::m_useNeighborPointers
protected

◆ m_useTopMipMap

bool G3D::SVO::m_useTopMipMap
protected

◆ m_visualizeNodes

shared_ptr<Shader> G3D::SVO::m_visualizeNodes
protected

◆ m_writeDeclarationsFragmentBuffer

String G3D::SVO::m_writeDeclarationsFragmentBuffer
protected

◆ projectionOffset

Vector2 G3D::SVO::projectionOffset

◆ projectionScale

float G3D::SVO::projectionScale

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