1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-07-30 13:05:50 +03:00

0028114: Visualization, Path tracing - Make path tracing mode interactive in high resolutions

This commit is contained in:
dbp 2016-11-16 15:44:56 +03:00 committed by apn
parent 8511408796
commit 383c6c9fb2
6 changed files with 26 additions and 20 deletions

View File

@ -573,7 +573,7 @@ protected: //! @name data types related to ray-tracing
OpenGl_RT_uWinSizeY, OpenGl_RT_uWinSizeY,
// sampled frame params // sampled frame params
OpenGl_RT_uSampleWeight, OpenGl_RT_uAccumSamples,
OpenGl_RT_uFrameRndSeed, OpenGl_RT_uFrameRndSeed,
// adaptive FSAA params // adaptive FSAA params

View File

@ -1721,8 +1721,8 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
myUniformLocations[anIndex][OpenGl_RT_uWinSizeY] = myUniformLocations[anIndex][OpenGl_RT_uWinSizeY] =
aShaderProgram->GetUniformLocation (theGlContext, "uWinSizeY"); aShaderProgram->GetUniformLocation (theGlContext, "uWinSizeY");
myUniformLocations[anIndex][OpenGl_RT_uSampleWeight] = myUniformLocations[anIndex][OpenGl_RT_uAccumSamples] =
aShaderProgram->GetUniformLocation (theGlContext, "uSampleWeight"); aShaderProgram->GetUniformLocation (theGlContext, "uAccumSamples");
myUniformLocations[anIndex][OpenGl_RT_uFrameRndSeed] = myUniformLocations[anIndex][OpenGl_RT_uFrameRndSeed] =
aShaderProgram->GetUniformLocation (theGlContext, "uFrameRndSeed"); aShaderProgram->GetUniformLocation (theGlContext, "uFrameRndSeed");
@ -2778,10 +2778,10 @@ Standard_Boolean OpenGl_View::runPathtrace (const Graphic3d_Camera::Projection
// We upload tile offset texture each 4 frames in order // We upload tile offset texture each 4 frames in order
// to minimize overhead of additional memory bandwidth. // to minimize overhead of additional memory bandwidth.
// Adaptive sampling is starting after first 10 frames. // Adaptive sampling is starting after first 30 frames.
if (myAccumFrames % 4 == 0) if (myAccumFrames % 4 == 0)
{ {
myTileSampler.Upload (theGlContext, myRaytraceTileOffsetsTexture, myAccumFrames > 10); myTileSampler.Upload (theGlContext, myRaytraceTileOffsetsTexture, myAccumFrames > 30);
} }
} }
@ -2828,7 +2828,7 @@ Standard_Boolean OpenGl_View::runPathtrace (const Graphic3d_Camera::Projection
// Set frame accumulation weight // Set frame accumulation weight
myRaytraceProgram->SetUniform (theGlContext, myRaytraceProgram->SetUniform (theGlContext,
myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + 1)); myUniformLocations[0][OpenGl_RT_uAccumSamples], myAccumFrames);
// Set random number generator seed // Set random number generator seed
myRaytraceProgram->SetUniform (theGlContext, myRaytraceProgram->SetUniform (theGlContext,

View File

@ -12,6 +12,9 @@
#ifdef PATH_TRACING #ifdef PATH_TRACING
//! Number of previously rendered frames.
uniform int uAccumSamples;
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
// Specific data types // Specific data types
@ -677,6 +680,9 @@ vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, o
// Enables expiremental russian roulette sampling // Enables expiremental russian roulette sampling
#define RUSSIAN_ROULETTE #define RUSSIAN_ROULETTE
//! Frame step to increase number of bounces
#define FRAME_STEP 5
//======================================================================= //=======================================================================
// function : PathTrace // function : PathTrace
// purpose : Calculates radiance along the given ray // purpose : Calculates radiance along the given ray
@ -832,7 +838,7 @@ vec4 PathTrace (in SRay theRay, in vec3 theInverse)
aSurvive = aDepth < 3 ? 1.f : min (dot (LUMA, aThroughput), 0.95f); aSurvive = aDepth < 3 ? 1.f : min (dot (LUMA, aThroughput), 0.95f);
#endif #endif
if (RandFloat() > aSurvive || all (lessThanEqual (aThroughput, MIN_THROUGHPUT))) if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= uAccumSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))
{ {
aDepth = INVALID_BOUNCES; // terminate path aDepth = INVALID_BOUNCES; // terminate path
} }

View File

@ -9,10 +9,7 @@ uniform int uFrameRndSeed;
uniform int uBlockedRngEnabled; uniform int uBlockedRngEnabled;
#ifndef ADAPTIVE_SAMPLING #ifndef ADAPTIVE_SAMPLING
//! Weight of current frame related to accumulated samples. //! Input image with previously accumulated samples.
uniform float uSampleWeight;
//! Input accumulated image.
uniform sampler2D uAccumTexture; uniform sampler2D uAccumTexture;
#endif #endif
@ -95,13 +92,13 @@ void main (void)
#else #else
if (uSampleWeight >= 1.f) if (uAccumSamples == 0)
{ {
OutColor = aColor; OutColor = aColor;
} }
else else
{ {
OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight); OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1));
} }
#endif // ADAPTIVE_SAMPLING #endif // ADAPTIVE_SAMPLING

View File

@ -15,6 +15,9 @@ static const char Shaders_PathtraceBase_fs[] =
"\n" "\n"
"#ifdef PATH_TRACING\n" "#ifdef PATH_TRACING\n"
"\n" "\n"
"//! Number of previously rendered frames.\n"
"uniform int uAccumSamples;\n"
"\n"
"///////////////////////////////////////////////////////////////////////////////////////\n" "///////////////////////////////////////////////////////////////////////////////////////\n"
"// Specific data types\n" "// Specific data types\n"
"\n" "\n"
@ -680,6 +683,9 @@ static const char Shaders_PathtraceBase_fs[] =
"// Enables expiremental russian roulette sampling\n" "// Enables expiremental russian roulette sampling\n"
"#define RUSSIAN_ROULETTE\n" "#define RUSSIAN_ROULETTE\n"
"\n" "\n"
"//! Frame step to increase number of bounces\n"
"#define FRAME_STEP 5\n"
"\n"
"//=======================================================================\n" "//=======================================================================\n"
"// function : PathTrace\n" "// function : PathTrace\n"
"// purpose : Calculates radiance along the given ray\n" "// purpose : Calculates radiance along the given ray\n"
@ -835,7 +841,7 @@ static const char Shaders_PathtraceBase_fs[] =
" aSurvive = aDepth < 3 ? 1.f : min (dot (LUMA, aThroughput), 0.95f);\n" " aSurvive = aDepth < 3 ? 1.f : min (dot (LUMA, aThroughput), 0.95f);\n"
"#endif\n" "#endif\n"
"\n" "\n"
" if (RandFloat() > aSurvive || all (lessThanEqual (aThroughput, MIN_THROUGHPUT)))\n" " if (RandFloat() > aSurvive || all (lessThan (aThroughput, MIN_THROUGHPUT)) || aDepth >= uAccumSamples / FRAME_STEP + step (1.f / M_PI, aImpPDF))\n"
" {\n" " {\n"
" aDepth = INVALID_BOUNCES; // terminate path\n" " aDepth = INVALID_BOUNCES; // terminate path\n"
" }\n" " }\n"

View File

@ -12,10 +12,7 @@ static const char Shaders_RaytraceRender_fs[] =
"uniform int uBlockedRngEnabled;\n" "uniform int uBlockedRngEnabled;\n"
"\n" "\n"
"#ifndef ADAPTIVE_SAMPLING\n" "#ifndef ADAPTIVE_SAMPLING\n"
" //! Weight of current frame related to accumulated samples.\n" " //! Input image with previously accumulated samples.\n"
" uniform float uSampleWeight;\n"
"\n"
" //! Input accumulated image.\n"
" uniform sampler2D uAccumTexture;\n" " uniform sampler2D uAccumTexture;\n"
"#endif\n" "#endif\n"
"\n" "\n"
@ -98,13 +95,13 @@ static const char Shaders_RaytraceRender_fs[] =
"\n" "\n"
"#else\n" "#else\n"
"\n" "\n"
" if (uSampleWeight >= 1.f)\n" " if (uAccumSamples == 0)\n"
" {\n" " {\n"
" OutColor = aColor;\n" " OutColor = aColor;\n"
" }\n" " }\n"
" else\n" " else\n"
" {\n" " {\n"
" OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);\n" " OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1));\n"
" }\n" " }\n"
"\n" "\n"
"#endif // ADAPTIVE_SAMPLING\n" "#endif // ADAPTIVE_SAMPLING\n"