mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0028129: Visualization, Path Tracing - Improve interactivity in "steady" rendering mode
Re-basing the patch on current master.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#extension GL_ARB_shader_image_load_store : require
|
||||
|
||||
#extension GL_ARB_shader_image_size : enable
|
||||
|
||||
//! OpenGL image used for accumulating rendering result.
|
||||
volatile restrict layout(size1x32) uniform image2D uRenderImage;
|
||||
|
||||
@@ -87,8 +89,9 @@ void main (void)
|
||||
// calculate visual error
|
||||
float anError = (aAverRad - aHalfRad) * (aAverRad - aHalfRad);
|
||||
|
||||
// accumulate visual error to current block
|
||||
imageAtomicAdd (uVarianceImage, ivec2 (aPixel / vec2 (BLOCK_SIZE)), int (anError * SCALE_FACTOR));
|
||||
// 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)));
|
||||
|
||||
if (uDebugAdaptive == 0) // normal rendering
|
||||
{
|
||||
@@ -96,7 +99,13 @@ void main (void)
|
||||
}
|
||||
else // showing number of samples
|
||||
{
|
||||
aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);
|
||||
vec2 aRatio = vec2 (1.f, 1.f);
|
||||
|
||||
#ifdef GL_ARB_shader_image_size
|
||||
aRatio = vec2 (imageSize (uRenderImage)) / vec2 (3.f * 512.f, 2.f * 512.f);
|
||||
#endif
|
||||
|
||||
aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, sqrt (aRatio.x * aRatio.y) * aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);
|
||||
}
|
||||
|
||||
#endif // ADAPTIVE_SAMPLING
|
||||
|
@@ -12,9 +12,6 @@
|
||||
|
||||
#ifdef PATH_TRACING
|
||||
|
||||
//! Number of previously rendered frames.
|
||||
uniform int uAccumSamples;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// Specific data types
|
||||
|
||||
@@ -700,17 +697,26 @@ vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, o
|
||||
#define MATERIAL_FRESNEL(index) (18 * index + 16)
|
||||
#define MATERIAL_ABSORPT(index) (18 * index + 17)
|
||||
|
||||
// Enables expiremental russian roulette sampling
|
||||
//! Enables experimental russian roulette sampling path termination.
|
||||
//! In most cases, it provides faster image convergence with minimal
|
||||
//! bias, so it is enabled by default.
|
||||
#define RUSSIAN_ROULETTE
|
||||
|
||||
//! Frame step to increase number of bounces
|
||||
#define FRAME_STEP 5
|
||||
//! Frame step to increase number of bounces. This mode is used
|
||||
//! for interaction with the model, when path length is limited
|
||||
//! for the first samples, and gradually increasing when camera
|
||||
//! is stabilizing.
|
||||
#ifdef ADAPTIVE_SAMPLING
|
||||
#define FRAME_STEP 4
|
||||
#else
|
||||
#define FRAME_STEP 5
|
||||
#endif
|
||||
|
||||
//=======================================================================
|
||||
// function : PathTrace
|
||||
// purpose : Calculates radiance along the given ray
|
||||
//=======================================================================
|
||||
vec4 PathTrace (in SRay theRay, in vec3 theInverse)
|
||||
vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)
|
||||
{
|
||||
float aRaytraceDepth = MAXFLOAT;
|
||||
|
||||
@@ -867,7 +873,8 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse)
|
||||
aSurvive = aDepth < 3 ? 1.f : min (dot (LUMA, aThroughput), 0.95f);
|
||||
#endif
|
||||
|
||||
if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= uAccumSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))
|
||||
// here, we additionally increase path length for non-diffuse bounces
|
||||
if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= theNbSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))
|
||||
{
|
||||
aDepth = INVALID_BOUNCES; // terminate path
|
||||
}
|
||||
|
@@ -8,6 +8,9 @@ uniform int uFrameRndSeed;
|
||||
//! become structured. Can be used fo final rendering.
|
||||
uniform int uBlockedRngEnabled;
|
||||
|
||||
//! Number of previously rendered frames (used in non-ISS mode).
|
||||
uniform int uAccumSamples;
|
||||
|
||||
#ifndef ADAPTIVE_SAMPLING
|
||||
//! Input image with previously accumulated samples.
|
||||
uniform sampler2D uAccumTexture;
|
||||
@@ -57,7 +60,18 @@ void main (void)
|
||||
|
||||
#ifdef PATH_TRACING
|
||||
|
||||
vec4 aColor = PathTrace (aRay, aInvDirect);
|
||||
#ifndef ADAPTIVE_SAMPLING
|
||||
|
||||
vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);
|
||||
|
||||
#else
|
||||
|
||||
float aNbSamples = imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,
|
||||
2 * aFragCoord.y + 1), 1.0);
|
||||
|
||||
vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));
|
||||
|
||||
#endif
|
||||
|
||||
if (any (isnan (aColor.rgb)))
|
||||
{
|
||||
@@ -78,18 +92,12 @@ void main (void)
|
||||
imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,
|
||||
2 * aFragCoord.y + 1), aColor.w);
|
||||
|
||||
// accumulate number of samples
|
||||
float aNbSamples = imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,
|
||||
2 * aFragCoord.y + 1), 1.0);
|
||||
|
||||
if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only
|
||||
{
|
||||
imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,
|
||||
2 * aFragCoord.y + 0), dot (LUMA, aColor.rgb));
|
||||
}
|
||||
|
||||
discard; // fragment should not be written to frame buffer
|
||||
|
||||
#else
|
||||
|
||||
if (uAccumSamples == 0)
|
||||
|
@@ -5,6 +5,8 @@ static const char Shaders_Display_fs[] =
|
||||
"\n"
|
||||
" #extension GL_ARB_shader_image_load_store : require\n"
|
||||
"\n"
|
||||
" #extension GL_ARB_shader_image_size : enable\n"
|
||||
"\n"
|
||||
" //! OpenGL image used for accumulating rendering result.\n"
|
||||
" volatile restrict layout(size1x32) uniform image2D uRenderImage;\n"
|
||||
"\n"
|
||||
@@ -90,8 +92,9 @@ static const char Shaders_Display_fs[] =
|
||||
" // calculate visual error\n"
|
||||
" float anError = (aAverRad - aHalfRad) * (aAverRad - aHalfRad);\n"
|
||||
"\n"
|
||||
" // accumulate visual error to current block\n"
|
||||
" imageAtomicAdd (uVarianceImage, ivec2 (aPixel / vec2 (BLOCK_SIZE)), int (anError * SCALE_FACTOR));\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"
|
||||
"\n"
|
||||
" if (uDebugAdaptive == 0) // normal rendering\n"
|
||||
" {\n"
|
||||
@@ -99,7 +102,13 @@ static const char Shaders_Display_fs[] =
|
||||
" }\n"
|
||||
" else // showing number of samples\n"
|
||||
" {\n"
|
||||
" aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);\n"
|
||||
" vec2 aRatio = vec2 (1.f, 1.f);\n"
|
||||
"\n"
|
||||
"#ifdef GL_ARB_shader_image_size\n"
|
||||
" aRatio = vec2 (imageSize (uRenderImage)) / vec2 (3.f * 512.f, 2.f * 512.f);\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" aColor = vec4 (0.5f * aColor.rgb * aSampleWeight + vec3 (0.f, sqrt (aRatio.x * aRatio.y) * aColor.w / uAccumFrames * 0.35f, 0.f), 1.0);\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"#endif // ADAPTIVE_SAMPLING\n"
|
||||
|
@@ -15,9 +15,6 @@ static const char Shaders_PathtraceBase_fs[] =
|
||||
"\n"
|
||||
"#ifdef PATH_TRACING\n"
|
||||
"\n"
|
||||
"//! Number of previously rendered frames.\n"
|
||||
"uniform int uAccumSamples;\n"
|
||||
"\n"
|
||||
"///////////////////////////////////////////////////////////////////////////////////////\n"
|
||||
"// Specific data types\n"
|
||||
"\n"
|
||||
@@ -703,17 +700,26 @@ static const char Shaders_PathtraceBase_fs[] =
|
||||
"#define MATERIAL_FRESNEL(index) (18 * index + 16)\n"
|
||||
"#define MATERIAL_ABSORPT(index) (18 * index + 17)\n"
|
||||
"\n"
|
||||
"// Enables expiremental russian roulette sampling\n"
|
||||
"//! Enables experimental russian roulette sampling path termination.\n"
|
||||
"//! In most cases, it provides faster image convergence with minimal\n"
|
||||
"//! bias, so it is enabled by default.\n"
|
||||
"#define RUSSIAN_ROULETTE\n"
|
||||
"\n"
|
||||
"//! Frame step to increase number of bounces\n"
|
||||
"#define FRAME_STEP 5\n"
|
||||
"//! Frame step to increase number of bounces. This mode is used\n"
|
||||
"//! for interaction with the model, when path length is limited\n"
|
||||
"//! for the first samples, and gradually increasing when camera\n"
|
||||
"//! is stabilizing.\n"
|
||||
"#ifdef ADAPTIVE_SAMPLING\n"
|
||||
" #define FRAME_STEP 4\n"
|
||||
"#else\n"
|
||||
" #define FRAME_STEP 5\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
"//=======================================================================\n"
|
||||
"// function : PathTrace\n"
|
||||
"// purpose : Calculates radiance along the given ray\n"
|
||||
"//=======================================================================\n"
|
||||
"vec4 PathTrace (in SRay theRay, in vec3 theInverse)\n"
|
||||
"vec4 PathTrace (in SRay theRay, in vec3 theInverse, in int theNbSamples)\n"
|
||||
"{\n"
|
||||
" float aRaytraceDepth = MAXFLOAT;\n"
|
||||
"\n"
|
||||
@@ -870,7 +876,8 @@ static const char Shaders_PathtraceBase_fs[] =
|
||||
" aSurvive = aDepth < 3 ? 1.f : min (dot (LUMA, aThroughput), 0.95f);\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= uAccumSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))\n"
|
||||
" // here, we additionally increase path length for non-diffuse bounces\n"
|
||||
" if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= theNbSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))\n"
|
||||
" {\n"
|
||||
" aDepth = INVALID_BOUNCES; // terminate path\n"
|
||||
" }\n"
|
||||
|
@@ -11,6 +11,9 @@ static const char Shaders_RaytraceRender_fs[] =
|
||||
"//! become structured. Can be used fo final rendering.\n"
|
||||
"uniform int uBlockedRngEnabled;\n"
|
||||
"\n"
|
||||
"//! Number of previously rendered frames (used in non-ISS mode).\n"
|
||||
"uniform int uAccumSamples;\n"
|
||||
"\n"
|
||||
"#ifndef ADAPTIVE_SAMPLING\n"
|
||||
" //! Input image with previously accumulated samples.\n"
|
||||
" uniform sampler2D uAccumTexture;\n"
|
||||
@@ -60,7 +63,18 @@ static const char Shaders_RaytraceRender_fs[] =
|
||||
"\n"
|
||||
"#ifdef PATH_TRACING\n"
|
||||
"\n"
|
||||
" vec4 aColor = PathTrace (aRay, aInvDirect);\n"
|
||||
"#ifndef ADAPTIVE_SAMPLING\n"
|
||||
"\n"
|
||||
" vec4 aColor = PathTrace (aRay, aInvDirect, uAccumSamples);\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
" float aNbSamples = imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,\n"
|
||||
" 2 * aFragCoord.y + 1), 1.0);\n"
|
||||
"\n"
|
||||
" vec4 aColor = PathTrace (aRay, aInvDirect, int (aNbSamples));\n"
|
||||
"\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
" if (any (isnan (aColor.rgb)))\n"
|
||||
" {\n"
|
||||
@@ -81,18 +95,12 @@ static const char Shaders_RaytraceRender_fs[] =
|
||||
" imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,\n"
|
||||
" 2 * aFragCoord.y + 1), aColor.w);\n"
|
||||
"\n"
|
||||
" // accumulate number of samples\n"
|
||||
" float aNbSamples = imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 0,\n"
|
||||
" 2 * aFragCoord.y + 1), 1.0);\n"
|
||||
"\n"
|
||||
" if (int (aNbSamples) % 2 == 0) // accumulate luminance for even samples only\n"
|
||||
" {\n"
|
||||
" imageAtomicAdd (uRenderImage, ivec2 (3 * aFragCoord.x + 2,\n"
|
||||
" 2 * aFragCoord.y + 0), dot (LUMA, aColor.rgb));\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
" discard; // fragment should not be written to frame buffer\n"
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
" if (uAccumSamples == 0)\n"
|
||||
|
Reference in New Issue
Block a user