OpenGl_RT_uWinSizeY,
// sampled frame params
- OpenGl_RT_uSampleWeight,
+ OpenGl_RT_uAccumSamples,
OpenGl_RT_uFrameRndSeed,
// adaptive FSAA params
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");
// 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);
}
}
// 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,
#ifdef PATH_TRACING
+//! Number of previously rendered frames.
+uniform int uAccumSamples;
+
///////////////////////////////////////////////////////////////////////////////////////
// Specific data types
// 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
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
}
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
#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
"\n"
"#ifdef PATH_TRACING\n"
"\n"
+ "//! Number of previously rendered frames.\n"
+ "uniform int uAccumSamples;\n"
+ "\n"
"///////////////////////////////////////////////////////////////////////////////////////\n"
"// Specific data types\n"
"\n"
"// 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"
" 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"
"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"
"\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"