X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=blobdiff_plain;f=src%2FShaders%2FRaytraceBase.fs;h=cff32f88e0e91a774abbf1fcf65229358b3ca30c;hb=312a4043c287e51ae01c677672e14dc5865ccba8;hpb=51023771f99f25311b7d5fd27f436cd95e9f6104 diff --git a/src/Shaders/RaytraceBase.fs b/src/Shaders/RaytraceBase.fs index 10bf8af757..cff32f88e0 100644 --- a/src/Shaders/RaytraceBase.fs +++ b/src/Shaders/RaytraceBase.fs @@ -19,6 +19,11 @@ uniform vec3 uOriginRT; //! Origin of viewing ray in right-bottom corner. uniform vec3 uOriginRB; +//! Width of the rendering window. +uniform int uWinSizeX; +//! Height of the rendering window. +uniform int uWinSizeY; + //! Direction of viewing ray in left-top corner. uniform vec3 uDirectLT; //! Direction of viewing ray in left-bottom corner. @@ -141,6 +146,47 @@ vec3 MatrixRowMultiplyDir (in vec3 v, dot (m2.xyz, v)); } +//! 32-bit state of random number generator. +uint RandState; + +// ======================================================================= +// function : SeedRand +// purpose : Applies hash function by Thomas Wang to randomize seeds +// (see http://www.burtleburtle.net/bob/hash/integer.html) +// ======================================================================= +void SeedRand (in int theSeed) +{ + RandState = uint (int (gl_FragCoord.y) * uWinSizeX + int (gl_FragCoord.x) + theSeed); + + RandState = (RandState + 0x479ab41du) + (RandState << 8); + RandState = (RandState ^ 0xe4aa10ceu) ^ (RandState >> 5); + RandState = (RandState + 0x9942f0a6u) - (RandState << 14); + RandState = (RandState ^ 0x5aedd67du) ^ (RandState >> 3); + RandState = (RandState + 0x17bea992u) + (RandState << 7); +} + +// ======================================================================= +// function : RandInt +// purpose : Generates integer using Xorshift algorithm by G. Marsaglia +// ======================================================================= +uint RandInt() +{ + RandState ^= (RandState << 13); + RandState ^= (RandState >> 17); + RandState ^= (RandState << 5); + + return RandState; +} + +// ======================================================================= +// function : RandFloat +// purpose : Generates a random float in [0, 1) range +// ======================================================================= +float RandFloat() +{ + return float (RandInt()) * (1.f / 4294967296.f); +} + // ======================================================================= // function : MatrixColMultiplyPnt // purpose : Multiplies a vector by matrix