0026437: Visualization - Improve path tracing rendering engine
[occt.git] / src / Shaders / RaytraceRender.fs
index a15ddd2..25c9bbe 100644 (file)
@@ -9,6 +9,12 @@ uniform float uSampleWeight;
 //! Input accumulated image.
 uniform sampler2D uAccumTexture;
 
+//! Enabled/disbales using of single RNG seed for image 16x16 blocks.
+//! Increases performance up to 4 times, but noise becomes structured.
+uniform int uBlockedRngEnabled;
+
+#define MAX_RADIANCE vec3 (10.f)
+
 // =======================================================================
 // function : main
 // purpose  :
@@ -20,7 +26,7 @@ void main (void)
 #else
   ivec2 aWinSize = textureSize (uAccumTexture, 0);
 
-  SeedRand (uFrameRndSeed, aWinSize.x);
+  SeedRand (uFrameRndSeed, aWinSize.x, uBlockedRngEnabled == 0 ? 1 : 16);
 
   SRay aRay = GenerateRay (vPixel +
     vec2 (RandFloat() + 1.f, RandFloat() + 1.f) / vec2 (aWinSize));
@@ -33,19 +39,17 @@ void main (void)
                      aRay.Direct.z < 0.f ? -aInvDirect.z : aInvDirect.z);
 
 #ifdef PATH_TRACING
-
   vec4 aColor = PathTrace (aRay, aInvDirect);
 
   if (any (isnan (aColor.xyz)))
   {
-    aColor.xyz = ZERO;
+    aColor.rgb = ZERO;
   }
 
-  OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);
+  aColor.rgb = min (aColor.rgb, MAX_RADIANCE);
 
+  OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);
 #else
-
   OutColor = clamp (Radiance (aRay, aInvDirect), 0.f, 1.f);
-
 #endif
 }
\ No newline at end of file