mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-13 14:27:08 +03:00
0030483: Visualization, Path Tracing - make Tile Size configurable
OpenGl_TileSampler has been refactored to better describe its logic: - Offset image now defines tile index instead of offset to tile origin. - Added 2D array defining the number of times to sample tile for straight-forward debugging. Graphic3d_RenderingParams has been extended with property RayTracingTileSize for testing various tile configurations. Default behavior is the following: - Target number of tiles (e.g. upper limit per frame): 256 - Tile size: 32x32. OpenGl_View::runPathtrace() has been split into two methods per rendering stage. OpenGl_Texture::Init() now returns FALSE immediately on 0 input dimensions. Added Image_PixMapTypedData template class allowing to work with image data of known pixel format.
This commit is contained in:
@@ -10,6 +10,12 @@
|
||||
//! OpenGL image storing variance of sampled pixels blocks.
|
||||
volatile restrict layout(size1x32) uniform iimage2D uVarianceImage;
|
||||
|
||||
//! Scale factor used to quantize visual error (float) into signed integer.
|
||||
uniform float uVarianceScaleFactor;
|
||||
|
||||
//! Screen space tile size.
|
||||
uniform ivec2 uTileSize;
|
||||
|
||||
#else // ADAPTIVE_SAMPLING
|
||||
|
||||
//! Input image.
|
||||
@@ -42,9 +48,6 @@ out vec4 OutColor;
|
||||
//! RGB weight factors to calculate luminance.
|
||||
#define LUMA vec3 (0.2126f, 0.7152f, 0.0722f)
|
||||
|
||||
//! Scale factor used to quantize visual error.
|
||||
#define SCALE_FACTOR 1.0e6f
|
||||
|
||||
// =======================================================================
|
||||
// function : ToneMappingFilmic
|
||||
// purpose :
|
||||
@@ -113,7 +116,8 @@ void main (void)
|
||||
|
||||
// accumulate visual error to current block; estimated error is written only
|
||||
// after the first 40 samples and path length has reached 10 bounces or more
|
||||
imageAtomicAdd (uVarianceImage, ivec2 (aPixel / vec2 (BLOCK_SIZE)), int (mix (SCALE_FACTOR, anError * SCALE_FACTOR, aColor.w > 40.f)));
|
||||
imageAtomicAdd (uVarianceImage, aPixel / uTileSize,
|
||||
int (mix (uVarianceScaleFactor, anError * uVarianceScaleFactor, aColor.w > 40.f)));
|
||||
|
||||
if (uDebugAdaptive == 0) // normal rendering
|
||||
{
|
||||
|
@@ -101,6 +101,9 @@ uniform float uSceneEpsilon;
|
||||
|
||||
//! OpenGL image storing offsets of sampled pixels blocks.
|
||||
coherent restrict layout(size2x32) uniform iimage2D uOffsetImage;
|
||||
|
||||
//! Screen space tile size.
|
||||
uniform ivec2 uTileSize;
|
||||
#endif
|
||||
|
||||
//! Top color of gradient background.
|
||||
@@ -275,10 +278,9 @@ vec4 BackgroundColor()
|
||||
|
||||
ivec2 aFragCoord = ivec2 (gl_FragCoord.xy);
|
||||
|
||||
ivec2 aTileXY = imageLoad (uOffsetImage, ivec2 (aFragCoord.x / BLOCK_SIZE,
|
||||
aFragCoord.y / BLOCK_SIZE)).xy;
|
||||
ivec2 aTileXY = imageLoad (uOffsetImage, aFragCoord / uTileSize).xy * uTileSize;
|
||||
|
||||
aTileXY.y += aFragCoord.y % min (uWinSizeY - aTileXY.y, BLOCK_SIZE);
|
||||
aTileXY.y += aFragCoord.y % min (uWinSizeY - aTileXY.y, uTileSize.y);
|
||||
|
||||
return mix (uBackColorBot, uBackColorTop, float (aTileXY.y) / uWinSizeY);
|
||||
|
||||
|
@@ -38,11 +38,11 @@ void main (void)
|
||||
|
||||
#ifdef ADAPTIVE_SAMPLING
|
||||
|
||||
ivec2 aTileXY = imageLoad (uOffsetImage, ivec2 (aFragCoord.x / BLOCK_SIZE,
|
||||
aFragCoord.y / BLOCK_SIZE)).xy;
|
||||
ivec2 aTileXY = imageLoad (uOffsetImage, aFragCoord / uTileSize).xy * uTileSize;
|
||||
if (aTileXY.x < 0) { discard; }
|
||||
|
||||
ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, BLOCK_SIZE),
|
||||
min (uWinSizeY - aTileXY.y, BLOCK_SIZE));
|
||||
ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, uTileSize.x),
|
||||
min (uWinSizeY - aTileXY.y, uTileSize.y));
|
||||
|
||||
aFragCoord.x = aTileXY.x + (aFragCoord.x % aRealBlockSize.x);
|
||||
aFragCoord.y = aTileXY.y + (aFragCoord.y % aRealBlockSize.y);
|
||||
|
@@ -13,6 +13,12 @@ static const char Shaders_Display_fs[] =
|
||||
" //! OpenGL image storing variance of sampled pixels blocks.\n"
|
||||
" volatile restrict layout(size1x32) uniform iimage2D uVarianceImage;\n"
|
||||
"\n"
|
||||
" //! Scale factor used to quantize visual error (float) into signed integer.\n"
|
||||
" uniform float uVarianceScaleFactor;\n"
|
||||
"\n"
|
||||
" //! Screen space tile size.\n"
|
||||
" uniform ivec2 uTileSize;\n"
|
||||
"\n"
|
||||
"#else // ADAPTIVE_SAMPLING\n"
|
||||
"\n"
|
||||
" //! Input image.\n"
|
||||
@@ -45,9 +51,6 @@ static const char Shaders_Display_fs[] =
|
||||
"//! RGB weight factors to calculate luminance.\n"
|
||||
"#define LUMA vec3 (0.2126f, 0.7152f, 0.0722f)\n"
|
||||
"\n"
|
||||
"//! Scale factor used to quantize visual error.\n"
|
||||
"#define SCALE_FACTOR 1.0e6f\n"
|
||||
"\n"
|
||||
"// =======================================================================\n"
|
||||
"// function : ToneMappingFilmic\n"
|
||||
"// purpose :\n"
|
||||
@@ -116,7 +119,8 @@ static const char Shaders_Display_fs[] =
|
||||
"\n"
|
||||
" // accumulate visual error to current block; estimated error is written only\n"
|
||||
" // after the first 40 samples and path length has reached 10 bounces or more\n"
|
||||
" imageAtomicAdd (uVarianceImage, ivec2 (aPixel / vec2 (BLOCK_SIZE)), int (mix (SCALE_FACTOR, anError * SCALE_FACTOR, aColor.w > 40.f)));\n"
|
||||
" imageAtomicAdd (uVarianceImage, aPixel / uTileSize,\n"
|
||||
" int (mix (uVarianceScaleFactor, anError * uVarianceScaleFactor, aColor.w > 40.f)));\n"
|
||||
"\n"
|
||||
" if (uDebugAdaptive == 0) // normal rendering\n"
|
||||
" {\n"
|
||||
|
@@ -104,6 +104,9 @@ static const char Shaders_RaytraceBase_fs[] =
|
||||
"\n"
|
||||
" //! OpenGL image storing offsets of sampled pixels blocks.\n"
|
||||
" coherent restrict layout(size2x32) uniform iimage2D uOffsetImage;\n"
|
||||
"\n"
|
||||
" //! Screen space tile size.\n"
|
||||
" uniform ivec2 uTileSize;\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"//! Top color of gradient background.\n"
|
||||
@@ -278,10 +281,9 @@ static const char Shaders_RaytraceBase_fs[] =
|
||||
"\n"
|
||||
" ivec2 aFragCoord = ivec2 (gl_FragCoord.xy);\n"
|
||||
"\n"
|
||||
" ivec2 aTileXY = imageLoad (uOffsetImage, ivec2 (aFragCoord.x / BLOCK_SIZE,\n"
|
||||
" aFragCoord.y / BLOCK_SIZE)).xy;\n"
|
||||
" ivec2 aTileXY = imageLoad (uOffsetImage, aFragCoord / uTileSize).xy * uTileSize;\n"
|
||||
"\n"
|
||||
" aTileXY.y += aFragCoord.y % min (uWinSizeY - aTileXY.y, BLOCK_SIZE);\n"
|
||||
" aTileXY.y += aFragCoord.y % min (uWinSizeY - aTileXY.y, uTileSize.y);\n"
|
||||
"\n"
|
||||
" return mix (uBackColorBot, uBackColorTop, float (aTileXY.y) / uWinSizeY);\n"
|
||||
"\n"
|
||||
|
@@ -41,11 +41,11 @@ static const char Shaders_RaytraceRender_fs[] =
|
||||
"\n"
|
||||
"#ifdef ADAPTIVE_SAMPLING\n"
|
||||
"\n"
|
||||
" ivec2 aTileXY = imageLoad (uOffsetImage, ivec2 (aFragCoord.x / BLOCK_SIZE,\n"
|
||||
" aFragCoord.y / BLOCK_SIZE)).xy;\n"
|
||||
" ivec2 aTileXY = imageLoad (uOffsetImage, aFragCoord / uTileSize).xy * uTileSize;\n"
|
||||
" if (aTileXY.x < 0) { discard; }\n"
|
||||
"\n"
|
||||
" ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, BLOCK_SIZE),\n"
|
||||
" min (uWinSizeY - aTileXY.y, BLOCK_SIZE));\n"
|
||||
" ivec2 aRealBlockSize = ivec2 (min (uWinSizeX - aTileXY.x, uTileSize.x),\n"
|
||||
" min (uWinSizeY - aTileXY.y, uTileSize.y));\n"
|
||||
"\n"
|
||||
" aFragCoord.x = aTileXY.x + (aFragCoord.x % aRealBlockSize.x);\n"
|
||||
" aFragCoord.y = aTileXY.y + (aFragCoord.y % aRealBlockSize.y);\n"
|
||||
|
Reference in New Issue
Block a user