Open 3D Engine Atom Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
MaskedOcclusionCullingPrivate Class Reference

Inherits MaskedOcclusionCulling.

Classes

struct  ZTile
 

Public Member Functions

 MaskedOcclusionCullingPrivate (pfnAlignedAlloc alignedAlloc, pfnAlignedFree alignedFree)
 
void SetResolution (unsigned int width, unsigned int height) override
 Sets the resolution of the hierarchical depth buffer. This function will re-allocate the current depth buffer (if present). The contents of the buffer is undefined until ClearBuffer() is called.
 
void GetResolution (unsigned int &width, unsigned int &height) const override
 Gets the resolution of the hierarchical depth buffer.
 
void ComputeBinWidthHeight (unsigned int nBinsW, unsigned int nBinsH, unsigned int &outBinWidth, unsigned int &outBinHeight) override
 Returns the tile size for the current implementation.
 
void SetNearClipPlane (float nearDist) override
 Sets the distance for the near clipping plane. Default is nearDist = 0.
 
float GetNearClipPlane () const override
 Gets the distance for the near clipping plane.
 
void ClearBuffer () override
 Clears the hierarchical depth buffer.
 
void MergeBuffer (MaskedOcclusionCulling *BufferB) override
 Merge a second hierarchical depth buffer into the main buffer.
 
FORCE_INLINE int ClipPolygon (__m128 *outVtx, __m128 *inVtx, const __m128 &plane, int n) const
 
template<ClipPlanes CLIP_PLANE>
void TestClipPlane (__mw *vtxX, __mw *vtxY, __mw *vtxW, unsigned int &straddleMask, unsigned int &triMask, ClipPlanes clipPlaneMask)
 
FORCE_INLINE void ClipTriangleAndAddToBuffer (__mw *vtxX, __mw *vtxY, __mw *vtxW, __m128 *clippedTrisBuffer, int &clipWriteIdx, unsigned int &triMask, unsigned int triClipMask, ClipPlanes clipPlaneMask)
 
FORCE_INLINE void TransformVerts (__mw *vtxX, __mw *vtxY, __mw *vtxW, const float *modelToClipMatrix)
 
FORCE_INLINE void ProjectVertices (__mw *pVtxX, __mw *pVtxY, __mw *pVtxZ, const __mw *vtxX, const __mw *vtxY, const __mw *vtxW)
 
FORCE_INLINE void GatherVerticesFast (__mw *vtxX, __mw *vtxY, __mw *vtxW, const float *inVtx, const unsigned int *inTrisPtr, int numLanes)
 
FORCE_INLINE void ComputeBoundingBox (__mwi &bbminX, __mwi &bbminY, __mwi &bbmaxX, __mwi &bbmaxY, const __mw *vX, const __mw *vY, const ScissorRect *scissor)
 
FORCE_INLINE void SortVertices (__mw *vX, __mw *vY)
 
FORCE_INLINE int CullBackfaces (__mw *pVtxX, __mw *pVtxY, __mw *pVtxZ, const __mw &ccwMask, BackfaceWinding bfWinding)
 
FORCE_INLINE void ComputeDepthPlane (const __mw *pVtxX, const __mw *pVtxY, const __mw *pVtxZ, __mw &zPixelDx, __mw &zPixelDy) const
 
FORCE_INLINE void UpdateTileQuick (int tileIdx, const __mwi &coverage, const __mw &zTriv)
 
FORCE_INLINE void UpdateTileAccurate (int tileIdx, const __mwi &coverage, const __mw &zTriv)
 
template<int TEST_Z, int NRIGHT, int NLEFT>
FORCE_INLINE int TraverseScanline (int leftOffset, int rightOffset, int tileIdx, int rightEvent, int leftEvent, const __mwi *events, const __mw &zTriMin, const __mw &zTriMax, const __mw &iz0, float zx)
 
template<int TEST_Z, int TIGHT_TRAVERSAL, int MID_VTX_RIGHT>
FORCE_INLINE int RasterizeTriangle (unsigned int triIdx, int bbWidth, int tileRowIdx, int tileMidRowIdx, int tileEndRowIdx, const __mwi *eventStart, const __mwi *slope, const __mwi *slopeTileDelta, const __mw &zTriMin, const __mw &zTriMax, __mw &z0, float zx, float zy)
 
template<bool TEST_Z>
FORCE_INLINE int RasterizeTriangleBatch (__mw pVtxX[3], __mw pVtxY[3], __mw pVtxZ[3], unsigned int triMask, const ScissorRect *scissor)
 
template<int TEST_Z, int FAST_GATHER>
FORCE_INLINE CullingResult RenderTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout)
 Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.
 
CullingResult RenderTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) override
 Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.
 
CullingResult TestTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) override
 This function is similar to RenderTriangles(), but performs an occlusion query instead and does not update the hierarchical z buffer. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.
 
CullingResult TestRect (float xmin, float ymin, float xmax, float ymax, float wmin) const override
 Occlusion query for a rectangle with a given depth. The rectangle is given in normalized device coordinates where (x,y) coordinates between [-1,1] map to the visible screen area. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.
 
template<bool FAST_GATHER>
FORCE_INLINE void BinTriangles (const float *inVtx, const unsigned int *inTris, int nTris, TriList *triLists, unsigned int nBinsW, unsigned int nBinsH, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout)
 Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)
 
void BinTriangles (const float *inVtx, const unsigned int *inTris, int nTris, TriList *triLists, unsigned int nBinsW, unsigned int nBinsH, const float *modelToClipMatrix, BackfaceWinding bfWinding, ClipPlanes clipPlaneMask, const VertexLayout &vtxLayout) override
 Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)
 
template<int FAST_GATHER>
void GatherTransformClip (int &clipHead, int &clipTail, int &numLanes, int nTris, int &triIndex, __mw *vtxX, __mw *vtxY, __mw *vtxW, const float *inVtx, const unsigned int *&inTrisPtr, const VertexLayout &vtxLayout, const float *modelToClipMatrix, __m128 *clipTriBuffer, unsigned int &triMask, ClipPlanes clipPlaneMask)
 
void RenderTrilist (const TriList &triList, const ScissorRect *scissor) override
 Renders all occluder triangles in a trilist. This function can be used in combination with BinTriangles() to create a threded (binning) rasterizer. The bins can be processed independently by different threads without risking writing to overlapping memory regions.
 
MaskedOcclusionCulling::Implementation GetImplementation () override
 Returns the implementation (CPU instruction set) version of this object.
 
void ComputePixelDepthBuffer (float *depthData, bool flipY) override
 Creates a per-pixel depth buffer from the hierarchical z buffer representation. Intended for visualizing the hierarchical depth buffer for debugging. The buffer is written in scanline order, from the top to bottom (D3D) or bottom to top (OGL) of the surface. See the USE_D3D define.
 
OcclusionCullingStatistics GetStatistics () override
 Fetch occlusion culling statistics, returns zeroes if ENABLE_STATS define is not defined. The statistics can be used for profiling or debugging.
 
- Public Member Functions inherited from MaskedOcclusionCulling
virtual void SetResolution (unsigned int width, unsigned int height)=0
 Sets the resolution of the hierarchical depth buffer. This function will re-allocate the current depth buffer (if present). The contents of the buffer is undefined until ClearBuffer() is called.
 
virtual void GetResolution (unsigned int &width, unsigned int &height) const =0
 Gets the resolution of the hierarchical depth buffer.
 
virtual void ComputeBinWidthHeight (unsigned int nBinsW, unsigned int nBinsH, unsigned int &outBinWidth, unsigned int &outBinHeight)=0
 Returns the tile size for the current implementation.
 
virtual void SetNearClipPlane (float nearDist)=0
 Sets the distance for the near clipping plane. Default is nearDist = 0.
 
virtual float GetNearClipPlane () const =0
 Gets the distance for the near clipping plane.
 
virtual void ClearBuffer ()=0
 Clears the hierarchical depth buffer.
 
virtual void MergeBuffer (MaskedOcclusionCulling *BufferB)=0
 Merge a second hierarchical depth buffer into the main buffer.
 
virtual CullingResult RenderTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix=nullptr, BackfaceWinding bfWinding=BACKFACE_CW, ClipPlanes clipPlaneMask=CLIP_PLANE_ALL, const VertexLayout &vtxLayout=VertexLayout(16, 4, 12))=0
 Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.
 
virtual CullingResult TestRect (float xmin, float ymin, float xmax, float ymax, float wmin) const =0
 Occlusion query for a rectangle with a given depth. The rectangle is given in normalized device coordinates where (x,y) coordinates between [-1,1] map to the visible screen area. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.
 
virtual CullingResult TestTriangles (const float *inVtx, const unsigned int *inTris, int nTris, const float *modelToClipMatrix=nullptr, BackfaceWinding bfWinding=BACKFACE_CW, ClipPlanes clipPlaneMask=CLIP_PLANE_ALL, const VertexLayout &vtxLayout=VertexLayout(16, 4, 12))=0
 This function is similar to RenderTriangles(), but performs an occlusion query instead and does not update the hierarchical z buffer. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.
 
virtual void BinTriangles (const float *inVtx, const unsigned int *inTris, int nTris, TriList *triLists, unsigned int nBinsW, unsigned int nBinsH, const float *modelToClipMatrix=nullptr, BackfaceWinding bfWinding=BACKFACE_CW, ClipPlanes clipPlaneMask=CLIP_PLANE_ALL, const VertexLayout &vtxLayout=VertexLayout(16, 4, 12))=0
 Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)
 
virtual void RenderTrilist (const TriList &triList, const ScissorRect *scissor)=0
 Renders all occluder triangles in a trilist. This function can be used in combination with BinTriangles() to create a threded (binning) rasterizer. The bins can be processed independently by different threads without risking writing to overlapping memory regions.
 
virtual void ComputePixelDepthBuffer (float *depthData, bool flipY)=0
 Creates a per-pixel depth buffer from the hierarchical z buffer representation. Intended for visualizing the hierarchical depth buffer for debugging. The buffer is written in scanline order, from the top to bottom (D3D) or bottom to top (OGL) of the surface. See the USE_D3D define.
 
virtual OcclusionCullingStatistics GetStatistics ()=0
 Fetch occlusion culling statistics, returns zeroes if ENABLE_STATS define is not defined. The statistics can be used for profiling or debugging.
 
virtual Implementation GetImplementation ()=0
 Returns the implementation (CPU instruction set) version of this object.
 
void GetAllocFreeCallback (pfnAlignedAlloc &allocCallback, pfnAlignedFree &freeCallback)
 Get used memory alloc/free callbacks.
 

Public Attributes

__mw mHalfWidth
 
__mw mHalfHeight
 
__mw mCenterX
 
__mw mCenterY
 
__m128 mCSFrustumPlanes [5]
 
__m128 mIHalfSize
 
__m128 mICenter
 
__m128i mIScreenSize
 
float mNearDist
 
int mWidth
 
int mHeight
 
int mTilesWidth
 
int mTilesHeight
 
ZTilemMaskedHiZBuffer
 
ScissorRect mFullscreenScissor
 

Additional Inherited Members

- Public Types inherited from MaskedOcclusionCulling
enum  Implementation { SSE2 = 0 , SSE41 = 1 , AVX2 = 2 , AVX512 = 3 }
 
enum  BackfaceWinding { BACKFACE_NONE = 0 , BACKFACE_CW = 1 , BACKFACE_CCW = 2 }
 
enum  CullingResult { VISIBLE = 0x0 , OCCLUDED = 0x1 , VIEW_CULLED = 0x3 }
 
enum  ClipPlanes {
  CLIP_PLANE_NONE = 0x00 , CLIP_PLANE_NEAR = 0x01 , CLIP_PLANE_LEFT = 0x02 , CLIP_PLANE_RIGHT = 0x04 ,
  CLIP_PLANE_BOTTOM = 0x08 , CLIP_PLANE_TOP = 0x10 , CLIP_PLANE_SIDES = (CLIP_PLANE_LEFT | CLIP_PLANE_RIGHT | CLIP_PLANE_BOTTOM | CLIP_PLANE_TOP) , CLIP_PLANE_ALL = (CLIP_PLANE_LEFT | CLIP_PLANE_RIGHT | CLIP_PLANE_BOTTOM | CLIP_PLANE_TOP | CLIP_PLANE_NEAR)
}
 
typedef void *(* pfnAlignedAlloc) (size_t alignment, size_t size)
 
typedef void(* pfnAlignedFree) (void *ptr)
 
- Static Public Member Functions inherited from MaskedOcclusionCulling
static MaskedOcclusionCullingCreate (Implementation RequestedSIMD=AVX512)
 Creates a new object with default state, no z buffer attached/allocated.
 
static MaskedOcclusionCullingCreate (Implementation RequestedSIMD, pfnAlignedAlloc alignedAlloc, pfnAlignedFree alignedFree)
 Creates a new object with default state, no z buffer attached/allocated.
 
static void Destroy (MaskedOcclusionCulling *moc)
 Destroys an object and frees the z buffer memory. Note that you cannot use the delete operator, and should rather use this function to free up memory.
 
static void TransformVertices (const float *mtx, const float *inVtx, float *xfVtx, unsigned int nVtx, const VertexLayout &vtxLayout=VertexLayout(12, 4, 8))
 Utility function for transforming vertices and outputting them to an (x,y,z,w) format suitable for the occluder rasterization and occludee testing functions.
 
- Protected Attributes inherited from MaskedOcclusionCulling
pfnAlignedAlloc mAlignedAllocCallback
 
pfnAlignedFree mAlignedFreeCallback
 
OcclusionCullingStatistics mStats
 

Member Function Documentation

◆ BinTriangles() [1/2]

template<bool FAST_GATHER>
FORCE_INLINE void MaskedOcclusionCullingPrivate::BinTriangles ( const float *  inVtx,
const unsigned int *  inTris,
int  nTris,
TriList triLists,
unsigned int  nBinsW,
unsigned int  nBinsH,
const float *  modelToClipMatrix,
BackfaceWinding  bfWinding,
ClipPlanes  clipPlaneMask,
const VertexLayout vtxLayout 
)
inlinevirtual

Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)

Parameters
inVtxPointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout.
inTrisPointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array.
nTrisThe number of triangles to render (inTris must contain atleast 3*nTris entries)
triListsPointer to an array of TriList objects with one TriList object per bin. If a triangle overlaps a bin, it will be written to the corresponding trilist. Note that this method appends the triangles to the current list, to start writing from the beginning of the list, set triList.mTriIdx = 0
nBinsWNumber of vertical bins, the screen is divided into nBinsW x nBinsH rectangular bins.
nBinsHNumber of horizontal bins, the screen is divided into nBinsW x nBinsH rectangular bins.
modelToClipMatrixall vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped
clipPlaneMaskA mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses.
vtxLayoutA struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible.
bfWindingSets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be binned / rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry

Implements MaskedOcclusionCulling.

◆ BinTriangles() [2/2]

void MaskedOcclusionCullingPrivate::BinTriangles ( const float *  inVtx,
const unsigned int *  inTris,
int  nTris,
TriList triLists,
unsigned int  nBinsW,
unsigned int  nBinsH,
const float *  modelToClipMatrix,
BackfaceWinding  bfWinding,
ClipPlanes  clipPlaneMask,
const VertexLayout vtxLayout 
)
inlineoverridevirtual

Perform input assembly, clipping , projection, triangle setup, and write triangles to the screen space bins they overlap. This function can be used to distribute work for threading (See the CullingThreadpool class for an example)

Parameters
inVtxPointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout.
inTrisPointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array.
nTrisThe number of triangles to render (inTris must contain atleast 3*nTris entries)
triListsPointer to an array of TriList objects with one TriList object per bin. If a triangle overlaps a bin, it will be written to the corresponding trilist. Note that this method appends the triangles to the current list, to start writing from the beginning of the list, set triList.mTriIdx = 0
nBinsWNumber of vertical bins, the screen is divided into nBinsW x nBinsH rectangular bins.
nBinsHNumber of horizontal bins, the screen is divided into nBinsW x nBinsH rectangular bins.
modelToClipMatrixall vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped
clipPlaneMaskA mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses.
vtxLayoutA struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible.
bfWindingSets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be binned / rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry

Implements MaskedOcclusionCulling.

◆ ClearBuffer()

void MaskedOcclusionCullingPrivate::ClearBuffer ( )
inlineoverridevirtual

Clears the hierarchical depth buffer.

Implements MaskedOcclusionCulling.

◆ ComputeBinWidthHeight()

void MaskedOcclusionCullingPrivate::ComputeBinWidthHeight ( unsigned int  nBinsW,
unsigned int  nBinsH,
unsigned int &  outBinWidth,
unsigned int &  outBinHeight 
)
inlineoverridevirtual

Returns the tile size for the current implementation.

Parameters
nBinsWNumber of vertical bins, the screen is divided into nBinsW x nBinsH rectangular bins.
nBinsHNumber of horizontal bins, the screen is divided into nBinsW x nBinsH rectangular bins.
outBinWidthOutput: The width of the single bin in pixels (except for the rightmost bin width, which is extended to resolution width)
outBinHeightOutput: The height of the single bin in pixels (except for the bottommost bin height, which is extended to resolution height)

Implements MaskedOcclusionCulling.

◆ ComputePixelDepthBuffer()

void MaskedOcclusionCullingPrivate::ComputePixelDepthBuffer ( float *  depthData,
bool  flipY 
)
inlineoverridevirtual

Creates a per-pixel depth buffer from the hierarchical z buffer representation. Intended for visualizing the hierarchical depth buffer for debugging. The buffer is written in scanline order, from the top to bottom (D3D) or bottom to top (OGL) of the surface. See the USE_D3D define.

Parameters
depthDataPointer to memory where the per-pixel depth data is written. Must hold storage for atleast width*height elements as set by setResolution.

Implements MaskedOcclusionCulling.

◆ GetImplementation()

MaskedOcclusionCulling::Implementation MaskedOcclusionCullingPrivate::GetImplementation ( )
inlineoverridevirtual

Returns the implementation (CPU instruction set) version of this object.

Implements MaskedOcclusionCulling.

◆ GetNearClipPlane()

float MaskedOcclusionCullingPrivate::GetNearClipPlane ( ) const
inlineoverridevirtual

Gets the distance for the near clipping plane.

Implements MaskedOcclusionCulling.

◆ GetResolution()

void MaskedOcclusionCullingPrivate::GetResolution ( unsigned int &  width,
unsigned int &  height 
) const
inlineoverridevirtual

Gets the resolution of the hierarchical depth buffer.

Parameters
witdhOutput: The width of the buffer in pixels
heightOutput: The height of the buffer in pixels

Implements MaskedOcclusionCulling.

◆ GetStatistics()

OcclusionCullingStatistics MaskedOcclusionCullingPrivate::GetStatistics ( )
inlineoverridevirtual

Fetch occlusion culling statistics, returns zeroes if ENABLE_STATS define is not defined. The statistics can be used for profiling or debugging.

Implements MaskedOcclusionCulling.

◆ MergeBuffer()

void MaskedOcclusionCullingPrivate::MergeBuffer ( MaskedOcclusionCulling BufferB)
inlineoverridevirtual

Merge a second hierarchical depth buffer into the main buffer.

Implements MaskedOcclusionCulling.

◆ RenderTriangles() [1/2]

template<int TEST_Z, int FAST_GATHER>
FORCE_INLINE CullingResult MaskedOcclusionCullingPrivate::RenderTriangles ( const float *  inVtx,
const unsigned int *  inTris,
int  nTris,
const float *  modelToClipMatrix,
BackfaceWinding  bfWinding,
ClipPlanes  clipPlaneMask,
const VertexLayout vtxLayout 
)
inlinevirtual

Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.

This function is optimized for vertex layouts with stride 16 and y and w offsets of 4 and 12 bytes, respectively.

Parameters
inVtxPointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout.
inTrisPointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array.
nTrisThe number of triangles to render (inTris must contain atleast 3*nTris entries)
modelToClipMatrixall vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped
bfWindingSets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry
clipPlaneMaskA mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses.
vtxLayoutA struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible.
Returns
Will return VIEW_CULLED if all triangles are either outside the frustum or backface culled, returns VISIBLE otherwise.

Implements MaskedOcclusionCulling.

◆ RenderTriangles() [2/2]

CullingResult MaskedOcclusionCullingPrivate::RenderTriangles ( const float *  inVtx,
const unsigned int *  inTris,
int  nTris,
const float *  modelToClipMatrix,
BackfaceWinding  bfWinding,
ClipPlanes  clipPlaneMask,
const VertexLayout vtxLayout 
)
inlineoverridevirtual

Renders a mesh of occluder triangles and updates the hierarchical z buffer with conservative depth values.

This function is optimized for vertex layouts with stride 16 and y and w offsets of 4 and 12 bytes, respectively.

Parameters
inVtxPointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout.
inTrisPointer to an array of vertex indices. Each triangle is created from three indices consecutively fetched from the array.
nTrisThe number of triangles to render (inTris must contain atleast 3*nTris entries)
modelToClipMatrixall vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped
bfWindingSets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be rasterized. You may use BACKFACE_NONE to disable culling for double sided geometry
clipPlaneMaskA mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses.
vtxLayoutA struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible.
Returns
Will return VIEW_CULLED if all triangles are either outside the frustum or backface culled, returns VISIBLE otherwise.

Implements MaskedOcclusionCulling.

◆ RenderTrilist()

void MaskedOcclusionCullingPrivate::RenderTrilist ( const TriList triList,
const ScissorRect scissor 
)
inlineoverridevirtual

Renders all occluder triangles in a trilist. This function can be used in combination with BinTriangles() to create a threded (binning) rasterizer. The bins can be processed independently by different threads without risking writing to overlapping memory regions.

Parameters
triListsA triangle list, filled using the BinTriangles() function that is to be rendered.
scissorA scissor box limiting the rendering region to the bin. The size of each bin must be a multiple of 32x8 pixels due to implementation constraints. For a render target with (width, height) resolution and (nBinsW, nBinsH) bins, the size of a bin is: binWidth = (width / nBinsW) - (width / nBinsW) % 32; binHeight = (height / nBinsH) - (height / nBinsH) % 8; The last row and column of tiles have a different size: lastColBinWidth = width - (nBinsW-1)*binWidth; lastRowBinHeight = height - (nBinsH-1)*binHeight;

Implements MaskedOcclusionCulling.

◆ SetNearClipPlane()

void MaskedOcclusionCullingPrivate::SetNearClipPlane ( float  nearDist)
inlineoverridevirtual

Sets the distance for the near clipping plane. Default is nearDist = 0.

Parameters
nearDistThe distance to the near clipping plane, given as clip space w

Implements MaskedOcclusionCulling.

◆ SetResolution()

void MaskedOcclusionCullingPrivate::SetResolution ( unsigned int  width,
unsigned int  height 
)
inlineoverridevirtual

Sets the resolution of the hierarchical depth buffer. This function will re-allocate the current depth buffer (if present). The contents of the buffer is undefined until ClearBuffer() is called.

Parameters
witdhThe width of the buffer in pixels, must be a multiple of 8
heightThe height of the buffer in pixels, must be a multiple of 4

Implements MaskedOcclusionCulling.

◆ TestRect()

CullingResult MaskedOcclusionCullingPrivate::TestRect ( float  xmin,
float  ymin,
float  xmax,
float  ymax,
float  wmin 
) const
inlineoverridevirtual

Occlusion query for a rectangle with a given depth. The rectangle is given in normalized device coordinates where (x,y) coordinates between [-1,1] map to the visible screen area. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.

Parameters
xminNDC coordinate of the left side of the rectangle.
yminNDC coordinate of the bottom side of the rectangle.
xmaxNDC coordinate of the right side of the rectangle.
ymaxNDC coordinate of the top side of the rectangle.
ymaxNDC coordinate of the top side of the rectangle.
wminClip space W coordinate for the rectangle.
Returns
The query will return VISIBLE if the rectangle may be visible, OCCLUDED if the rectangle is occluded by a previously rendered object, or VIEW_CULLED if the rectangle is outside the view frustum.

Implements MaskedOcclusionCulling.

◆ TestTriangles()

CullingResult MaskedOcclusionCullingPrivate::TestTriangles ( const float *  inVtx,
const unsigned int *  inTris,
int  nTris,
const float *  modelToClipMatrix,
BackfaceWinding  bfWinding,
ClipPlanes  clipPlaneMask,
const VertexLayout vtxLayout 
)
inlineoverridevirtual

This function is similar to RenderTriangles(), but performs an occlusion query instead and does not update the hierarchical z buffer. The query uses a GREATER_EQUAL (reversed) depth test meaning that depth values equal to the contents of the depth buffer are counted as visible.

This function is optimized for vertex layouts with stride 16 and y and w offsets of 4 and 12 bytes, respectively.

Parameters
inVtxPointer to an array of input vertices, should point to the x component of the first vertex. The input vertices are given as (x,y,w) coordinates in clip space. The memory layout can be changed using vtxLayout.
inTrisPointer to an array of triangle indices. Each triangle is created from three indices consecutively fetched from the array.
nTrisThe number of triangles to render (inTris must contain atleast 3*nTris entries)
modelToClipMatrixall vertices will be transformed by this matrix before performing projection. If nullptr is passed the transform step will be skipped
bfWindingSets triangle winding order to consider backfacing, must be one one of (BACKFACE_NONE, BACKFACE_CW and BACKFACE_CCW). Back-facing triangles are culled and will not be occlusion tested. You may use BACKFACE_NONE to disable culling for double sided geometry
clipPlaneMaskA mask indicating which clip planes should be considered by the triangle clipper. Can be used as an optimization if your application can determine (for example during culling) that a group of triangles does not intersect a certain frustum plane. However, setting an incorrect mask may cause out of bounds memory accesses.
vtxLayoutA struct specifying the vertex layout (see struct for detailed description). For best performance, it is advisable to store position data as compactly in memory as possible.
Returns
The query will return VISIBLE if the triangle mesh may be visible, OCCLUDED if the mesh is occluded by a previously rendered object, or VIEW_CULLED if all triangles are entirely outside the view frustum or backface culled.

Implements MaskedOcclusionCulling.


The documentation for this class was generated from the following file: