Open CASCADE Technology  7.4.1.dev
Public Member Functions | Protected Member Functions | Protected Attributes
OpenGl_TileSampler Class Reference

Tool object used for sampling screen tiles according to estimated pixel variance (used in path tracing engine). To improve GPU thread coherency, rendering window is split into pixel blocks or tiles. The important feature of this approach is that it is possible to keep the same number of tiles for any screen resolution (e.g. 256 tiles can be used for both 512 x 512 window and 1920 x 1080 window). So, a smaller number of tiles allows to increase interactivity (FPS), but at the cost of higher per-frame variance ('noise'). On the contrary a larger number of tiles decrease interactivity, but leads to lower per-frame variance. Note that the total time needed to produce final final image is the same for both cases. More...

#include <OpenGl_TileSampler.hxx>

Public Member Functions

 OpenGl_TileSampler ()
 Creates new tile sampler. More...
 
Graphic3d_Vec2i TileSize () const
 Size of individual tile in pixels. More...
 
float VarianceScaleFactor () const
 Scale factor for quantization of visual error (float) into signed integer. More...
 
int NbTilesX () const
 Returns number of tiles in X dimension. More...
 
int NbTilesY () const
 Returns number of tiles in Y dimension. More...
 
int NbTiles () const
 Returns total number of tiles in viewport. More...
 
const Graphic3d_Vec2iViewSize () const
 Returns ray-tracing viewport. More...
 
Graphic3d_Vec2i NbOffsetTiles (bool theAdaptive) const
 Number of tiles within offsets texture. More...
 
Graphic3d_Vec2i NbOffsetTilesMax () const
 Maximum number of tiles within offsets texture. More...
 
Graphic3d_Vec2i OffsetTilesViewport (bool theAdaptive) const
 Viewport for rendering using offsets texture. More...
 
Graphic3d_Vec2i OffsetTilesViewportMax () const
 Maximum viewport for rendering using offsets texture. More...
 
int MaxTileSamples () const
 Return maximum number of samples per tile. More...
 
void SetSize (const Graphic3d_RenderingParams &theParams, const Graphic3d_Vec2i &theSize)
 Specifies size of ray-tracing viewport and recomputes tile size. More...
 
void GrabVarianceMap (const Handle< OpenGl_Context > &theContext, const Handle< OpenGl_Texture > &theTexture)
 Fetches current error estimation from the GPU and builds 2D discrete distribution for tile sampling. More...
 
void Reset ()
 Resets (restart) tile sampler to initial state. More...
 
bool UploadSamples (const Handle< OpenGl_Context > &theContext, const Handle< OpenGl_Texture > &theSamplesTexture, const bool theAdaptive)
 Uploads tile samples to the given OpenGL texture. More...
 
bool UploadOffsets (const Handle< OpenGl_Context > &theContext, const Handle< OpenGl_Texture > &theOffsetsTexture, const bool theAdaptive)
 Uploads offsets of sampled tiles to the given OpenGL texture. More...
 

Protected Member Functions

int tileArea (int theX, int theY) const
 Returns number of pixels in the given tile. More...
 
Graphic3d_Vec2i nextTileToSample ()
 Samples tile location according to estimated error. More...
 
bool upload (const Handle< OpenGl_Context > &theContext, const Handle< OpenGl_Texture > &theSamplesTexture, const Handle< OpenGl_Texture > &theOffsetsTexture, const bool theAdaptive)
 Uploads offsets of sampled tiles to the given OpenGL texture. More...
 
void dumpMap (std::ostream &theStream, const Image_PixMapTypedData< int > &theMap, const char *theTitle) const
 Auxiliary method for dumping 2D image map into stream (e.g. for debugging). More...
 

Protected Attributes

Image_PixMapTypedData< unsigned int > myTiles
 number of samples per tile (initially all 1) More...
 
Image_PixMapTypedData< unsigned int > myTileSamples
 number of samples for all pixels within the tile (initially equals to Tile area) More...
 
Image_PixMapTypedData< float > myVarianceMap
 Estimation of visual error per tile. More...
 
Image_PixMapTypedData< int > myVarianceRaw
 Estimation of visual error per tile (raw data) More...
 
Image_PixMapTypedData< Graphic3d_Vec2imyOffsets
 2D array of tiles redirecting to another tile More...
 
Image_PixMapTypedData< Graphic3d_Vec2imyOffsetsShrunk
 2D array of tiles redirecting to another tile (shrunk) More...
 
std::vector< float > myMarginalMap
 Marginal distribution of 2D error map. More...
 
OpenGl_HaltonSampler mySampler
 Halton sequence generator. More...
 
unsigned int myLastSample
 Index of generated sample. More...
 
float myScaleFactor
 scale factor for quantization of visual error (float) into signed integer More...
 
int myTileSize
 tile size More...
 
Graphic3d_Vec2i myViewSize
 ray-tracing viewport More...
 

Detailed Description

Tool object used for sampling screen tiles according to estimated pixel variance (used in path tracing engine). To improve GPU thread coherency, rendering window is split into pixel blocks or tiles. The important feature of this approach is that it is possible to keep the same number of tiles for any screen resolution (e.g. 256 tiles can be used for both 512 x 512 window and 1920 x 1080 window). So, a smaller number of tiles allows to increase interactivity (FPS), but at the cost of higher per-frame variance ('noise'). On the contrary a larger number of tiles decrease interactivity, but leads to lower per-frame variance. Note that the total time needed to produce final final image is the same for both cases.

Constructor & Destructor Documentation

◆ OpenGl_TileSampler()

OpenGl_TileSampler::OpenGl_TileSampler ( )

Creates new tile sampler.

Member Function Documentation

◆ dumpMap()

void OpenGl_TileSampler::dumpMap ( std::ostream &  theStream,
const Image_PixMapTypedData< int > &  theMap,
const char *  theTitle 
) const
protected

Auxiliary method for dumping 2D image map into stream (e.g. for debugging).

◆ GrabVarianceMap()

void OpenGl_TileSampler::GrabVarianceMap ( const Handle< OpenGl_Context > &  theContext,
const Handle< OpenGl_Texture > &  theTexture 
)

Fetches current error estimation from the GPU and builds 2D discrete distribution for tile sampling.

◆ MaxTileSamples()

int OpenGl_TileSampler::MaxTileSamples ( ) const
inline

Return maximum number of samples per tile.

◆ NbOffsetTiles()

Graphic3d_Vec2i OpenGl_TileSampler::NbOffsetTiles ( bool  theAdaptive) const
inline

Number of tiles within offsets texture.

◆ NbOffsetTilesMax()

Graphic3d_Vec2i OpenGl_TileSampler::NbOffsetTilesMax ( ) const
inline

Maximum number of tiles within offsets texture.

◆ NbTiles()

int OpenGl_TileSampler::NbTiles ( ) const
inline

Returns total number of tiles in viewport.

◆ NbTilesX()

int OpenGl_TileSampler::NbTilesX ( ) const
inline

Returns number of tiles in X dimension.

◆ NbTilesY()

int OpenGl_TileSampler::NbTilesY ( ) const
inline

Returns number of tiles in Y dimension.

◆ nextTileToSample()

Graphic3d_Vec2i OpenGl_TileSampler::nextTileToSample ( )
protected

Samples tile location according to estimated error.

◆ OffsetTilesViewport()

Graphic3d_Vec2i OpenGl_TileSampler::OffsetTilesViewport ( bool  theAdaptive) const
inline

Viewport for rendering using offsets texture.

◆ OffsetTilesViewportMax()

Graphic3d_Vec2i OpenGl_TileSampler::OffsetTilesViewportMax ( ) const
inline

Maximum viewport for rendering using offsets texture.

◆ Reset()

void OpenGl_TileSampler::Reset ( void  )
inline

Resets (restart) tile sampler to initial state.

◆ SetSize()

void OpenGl_TileSampler::SetSize ( const Graphic3d_RenderingParams theParams,
const Graphic3d_Vec2i theSize 
)

Specifies size of ray-tracing viewport and recomputes tile size.

◆ tileArea()

int OpenGl_TileSampler::tileArea ( int  theX,
int  theY 
) const
inlineprotected

Returns number of pixels in the given tile.

◆ TileSize()

Graphic3d_Vec2i OpenGl_TileSampler::TileSize ( ) const
inline

Size of individual tile in pixels.

◆ upload()

bool OpenGl_TileSampler::upload ( const Handle< OpenGl_Context > &  theContext,
const Handle< OpenGl_Texture > &  theSamplesTexture,
const Handle< OpenGl_Texture > &  theOffsetsTexture,
const bool  theAdaptive 
)
protected

Uploads offsets of sampled tiles to the given OpenGL texture.

◆ UploadOffsets()

bool OpenGl_TileSampler::UploadOffsets ( const Handle< OpenGl_Context > &  theContext,
const Handle< OpenGl_Texture > &  theOffsetsTexture,
const bool  theAdaptive 
)
inline

Uploads offsets of sampled tiles to the given OpenGL texture.

◆ UploadSamples()

bool OpenGl_TileSampler::UploadSamples ( const Handle< OpenGl_Context > &  theContext,
const Handle< OpenGl_Texture > &  theSamplesTexture,
const bool  theAdaptive 
)
inline

Uploads tile samples to the given OpenGL texture.

◆ VarianceScaleFactor()

float OpenGl_TileSampler::VarianceScaleFactor ( ) const
inline

Scale factor for quantization of visual error (float) into signed integer.

◆ ViewSize()

const Graphic3d_Vec2i& OpenGl_TileSampler::ViewSize ( ) const
inline

Returns ray-tracing viewport.

Field Documentation

◆ myLastSample

unsigned int OpenGl_TileSampler::myLastSample
protected

Index of generated sample.

◆ myMarginalMap

std::vector<float> OpenGl_TileSampler::myMarginalMap
protected

Marginal distribution of 2D error map.

◆ myOffsets

Image_PixMapTypedData<Graphic3d_Vec2i> OpenGl_TileSampler::myOffsets
protected

2D array of tiles redirecting to another tile

◆ myOffsetsShrunk

Image_PixMapTypedData<Graphic3d_Vec2i> OpenGl_TileSampler::myOffsetsShrunk
protected

2D array of tiles redirecting to another tile (shrunk)

◆ mySampler

OpenGl_HaltonSampler OpenGl_TileSampler::mySampler
protected

Halton sequence generator.

◆ myScaleFactor

float OpenGl_TileSampler::myScaleFactor
protected

scale factor for quantization of visual error (float) into signed integer

◆ myTiles

Image_PixMapTypedData<unsigned int> OpenGl_TileSampler::myTiles
protected

number of samples per tile (initially all 1)

◆ myTileSamples

Image_PixMapTypedData<unsigned int> OpenGl_TileSampler::myTileSamples
protected

number of samples for all pixels within the tile (initially equals to Tile area)

◆ myTileSize

int OpenGl_TileSampler::myTileSize
protected

tile size

◆ myVarianceMap

Image_PixMapTypedData<float> OpenGl_TileSampler::myVarianceMap
protected

Estimation of visual error per tile.

◆ myVarianceRaw

Image_PixMapTypedData<int> OpenGl_TileSampler::myVarianceRaw
protected

Estimation of visual error per tile (raw data)

◆ myViewSize

Graphic3d_Vec2i OpenGl_TileSampler::myViewSize
protected

ray-tracing viewport


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