From 1bd2fee41401eee1edbd8c739fc353ccb80e1ae0 Mon Sep 17 00:00:00 2001 From: kgv Date: Tue, 25 Aug 2015 15:43:31 +0300 Subject: [PATCH] 0026601: Visualization, Ray Tracing - make Path Tracing results reproducible for the same camera position OpenGl_View - reset Random Number Generator seed on progressive render restart to produce the same visual results. --- src/OpenGl/OpenGl_View_Raytrace.cxx | 5 +++++ src/math/math_BullardGenerator.hxx | 15 +++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/OpenGl/OpenGl_View_Raytrace.cxx b/src/OpenGl/OpenGl_View_Raytrace.cxx index f7bd08ba15..27c76a7878 100644 --- a/src/OpenGl/OpenGl_View_Raytrace.cxx +++ b/src/OpenGl/OpenGl_View_Raytrace.cxx @@ -2396,6 +2396,11 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Graphic3d_CView& if (myRaytraceParameters.GlobalIllumination) { + if (myAccumFrames == 0) + { + myRNG.SetSeed(); + } + // Set frame accumulation weight myRaytraceProgram->SetUniform (theGlContext, myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + 1)); diff --git a/src/math/math_BullardGenerator.hxx b/src/math/math_BullardGenerator.hxx index ff604ec720..4b682d2440 100644 --- a/src/math/math_BullardGenerator.hxx +++ b/src/math/math_BullardGenerator.hxx @@ -24,14 +24,21 @@ class math_BullardGenerator public: //! Creates new Xorshift 64-bit RNG. - Standard_EXPORT math_BullardGenerator(unsigned int theSeed = 1) - : myStateHi (theSeed) + math_BullardGenerator (unsigned int theSeed = 1) + : myStateHi (theSeed) { + SetSeed (theSeed); + } + + //! Setup new seed / reset defaults. + void SetSeed (unsigned int theSeed = 1) + { + myStateHi = theSeed; myStateLo = theSeed ^ 0x49616E42; } //! Generates new 64-bit integer value. - Standard_EXPORT unsigned int NextInt() + unsigned int NextInt() { myStateHi = (myStateHi >> 2) + (myStateHi << 2); @@ -42,7 +49,7 @@ public: } //! Generates new floating-point value. - Standard_EXPORT Standard_Real NextReal() + Standard_Real NextReal() { return NextInt() / static_cast (0xFFFFFFFFu); }