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:
parent
8511408796
commit
383c6c9fb2
@ -573,7 +573,7 @@ protected: //! @name data types related to ray-tracing
|
||||
OpenGl_RT_uWinSizeY,
|
||||
|
||||
// sampled frame params
|
||||
OpenGl_RT_uSampleWeight,
|
||||
OpenGl_RT_uAccumSamples,
|
||||
OpenGl_RT_uFrameRndSeed,
|
||||
|
||||
// adaptive FSAA params
|
||||
|
@ -1721,8 +1721,8 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
|
||||
myUniformLocations[anIndex][OpenGl_RT_uWinSizeY] =
|
||||
aShaderProgram->GetUniformLocation (theGlContext, "uWinSizeY");
|
||||
|
||||
myUniformLocations[anIndex][OpenGl_RT_uSampleWeight] =
|
||||
aShaderProgram->GetUniformLocation (theGlContext, "uSampleWeight");
|
||||
myUniformLocations[anIndex][OpenGl_RT_uAccumSamples] =
|
||||
aShaderProgram->GetUniformLocation (theGlContext, "uAccumSamples");
|
||||
myUniformLocations[anIndex][OpenGl_RT_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
|
||||
// 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)
|
||||
{
|
||||
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
|
||||
myRaytraceProgram->SetUniform (theGlContext,
|
||||
myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + 1));
|
||||
myUniformLocations[0][OpenGl_RT_uAccumSamples], myAccumFrames);
|
||||
|
||||
// Set random number generator seed
|
||||
myRaytraceProgram->SetUniform (theGlContext,
|
||||
|
@ -12,6 +12,9 @@
|
||||
|
||||
#ifdef PATH_TRACING
|
||||
|
||||
//! Number of previously rendered frames.
|
||||
uniform int uAccumSamples;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// Specific data types
|
||||
|
||||
@ -677,6 +680,9 @@ vec3 IntersectLight (in SRay theRay, in int theDepth, in float theHitDistance, o
|
||||
// Enables expiremental russian roulette sampling
|
||||
#define RUSSIAN_ROULETTE
|
||||
|
||||
//! Frame step to increase number of bounces
|
||||
#define FRAME_STEP 5
|
||||
|
||||
//=======================================================================
|
||||
// function : PathTrace
|
||||
// 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);
|
||||
#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
|
||||
}
|
||||
|
@ -9,10 +9,7 @@ uniform int uFrameRndSeed;
|
||||
uniform int uBlockedRngEnabled;
|
||||
|
||||
#ifndef ADAPTIVE_SAMPLING
|
||||
//! Weight of current frame related to accumulated samples.
|
||||
uniform float uSampleWeight;
|
||||
|
||||
//! Input accumulated image.
|
||||
//! Input image with previously accumulated samples.
|
||||
uniform sampler2D uAccumTexture;
|
||||
#endif
|
||||
|
||||
@ -95,13 +92,13 @@ void main (void)
|
||||
|
||||
#else
|
||||
|
||||
if (uSampleWeight >= 1.f)
|
||||
if (uAccumSamples == 0)
|
||||
{
|
||||
OutColor = aColor;
|
||||
}
|
||||
else
|
||||
{
|
||||
OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);
|
||||
OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1));
|
||||
}
|
||||
|
||||
#endif // ADAPTIVE_SAMPLING
|
||||
|
@ -15,6 +15,9 @@ 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"
|
||||
@ -680,6 +683,9 @@ static const char Shaders_PathtraceBase_fs[] =
|
||||
"// Enables expiremental russian roulette sampling\n"
|
||||
"#define RUSSIAN_ROULETTE\n"
|
||||
"\n"
|
||||
"//! Frame step to increase number of bounces\n"
|
||||
"#define FRAME_STEP 5\n"
|
||||
"\n"
|
||||
"//=======================================================================\n"
|
||||
"// function : PathTrace\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"
|
||||
"#endif\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"
|
||||
" aDepth = INVALID_BOUNCES; // terminate path\n"
|
||||
" }\n"
|
||||
|
@ -12,10 +12,7 @@ static const char Shaders_RaytraceRender_fs[] =
|
||||
"uniform int uBlockedRngEnabled;\n"
|
||||
"\n"
|
||||
"#ifndef ADAPTIVE_SAMPLING\n"
|
||||
" //! Weight of current frame related to accumulated samples.\n"
|
||||
" uniform float uSampleWeight;\n"
|
||||
"\n"
|
||||
" //! Input accumulated image.\n"
|
||||
" //! Input image with previously accumulated samples.\n"
|
||||
" uniform sampler2D uAccumTexture;\n"
|
||||
"#endif\n"
|
||||
"\n"
|
||||
@ -98,13 +95,13 @@ static const char Shaders_RaytraceRender_fs[] =
|
||||
"\n"
|
||||
"#else\n"
|
||||
"\n"
|
||||
" if (uSampleWeight >= 1.f)\n"
|
||||
" if (uAccumSamples == 0)\n"
|
||||
" {\n"
|
||||
" OutColor = aColor;\n"
|
||||
" }\n"
|
||||
" else\n"
|
||||
" {\n"
|
||||
" OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);\n"
|
||||
" OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, 1.f / (uAccumSamples + 1));\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
"#endif // ADAPTIVE_SAMPLING\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user