33
44#include < osg/Uniform>
55
6+ #include < cover/coVRMSController.h>
7+
68#include " SplotchTerroirTexture.h"
79
810SplotchTerroirTexture::SplotchTerroirTexture (float distanceThreshold)
911 : TerroirTexture(" TerroirTextureSplotches" , distanceThreshold)
1012{
13+ /*
14+ Since in the CAVE multiple OpenCover instances are running (which would each
15+ generate their own seeds, resulting in mismatching splotches) we need the master
16+ to create a seed and send it to the slaves.
17+ */
18+ masterGeneratesAndSharesSeed ();
1119}
1220
1321void SplotchTerroirTexture::onEnoughDistanceCovered ()
@@ -23,20 +31,30 @@ void SplotchTerroirTexture::updateShader()
2331 updateShaderUniforms ();
2432}
2533
26- float generateRandomFloat ( float start, float end )
34+ void SplotchTerroirTexture::masterGeneratesAndSharesSeed ( )
2735{
28- /*
29- Since in the CAVE multiple OpenCovers seem to be running (which would each generate their own
30- random numbers, resulting in mismatching splotches) we have to set a seed.
31- */
32- static thread_local std::mt19937 engine { 3847u };
36+ if (opencover::coVRMSController::instance ()->isMaster ())
37+ {
38+ std::mt19937 engine { std::random_device { }() };
39+ m_seed = std::uniform_int_distribution<unsigned int > { 0 , 1000 }(engine);
40+ opencover::coVRMSController::instance ()->syncData (&m_seed, sizeof (m_seed));
41+ }
42+ else
43+ {
44+ opencover::coVRMSController::instance ()->syncData (&m_seed, sizeof (m_seed));
45+ }
46+ }
47+
48+ float generateRandomFloat (unsigned int seed, float start, float end)
49+ {
50+ static std::mt19937 engine { seed };
3351 return std::uniform_real_distribution<float > { start, end }(engine);
3452}
3553
3654osg::Vec3 SplotchTerroirTexture::generateRandomSplotch (int textureSlot)
3755{
38- float texCoordX = generateRandomFloat (0 .1f , 0 .9f );
39- float texCoordY = generateRandomFloat (0 .1f , 0 .9f );
56+ float texCoordX = generateRandomFloat (m_seed, 0 .1f , 0 .9f );
57+ float texCoordY = generateRandomFloat (m_seed, 0 .1f , 0 .9f );
4058
4159 return { texCoordX, texCoordY, 1 .0f * textureSlot };
4260}
0 commit comments