]> OCCT Git - occt-copy.git/commitdiff
Update path tracing.
authorisk <ilya.sevrikov@opencascade.com>
Wed, 24 Feb 2016 14:47:50 +0000 (17:47 +0300)
committerisk <isk@opencascade.com>
Fri, 18 Mar 2016 09:46:15 +0000 (12:46 +0300)
samples/tcl/video.tcl
src/Graphic3d/Graphic3d_RenderingParams.hxx
src/OpenGl/OpenGl_View.hxx
src/OpenGl/OpenGl_View_Raytrace.cxx
src/OpenGl/OpenGl_View_Redraw.cxx
src/Shaders/Display.fs
src/Shaders/RaytraceRender.fs
src/ViewerTest/ViewerTest_ViewerCommands.cxx

index 23056c81b2402862ec2128745e3222419e5ea04d..99507b0dd09563db578af80ec600e17ffc77f91b 100644 (file)
@@ -3,13 +3,6 @@ pload ALL
 vclear
 vclose all
 
-vinit name=View1 w=512 h=512 t=256 l=1024
-vsetdispmode 1
-vcamera -persp -fovy 60
-
-vtrihedron tr0
-vzbufftrihedron
-
 # Declaration global variables
 global startTimeTyre
 global currentTimeTyre
@@ -29,17 +22,19 @@ set folderTyre  "D:/TmpFiles/for_video/Tyre"
 set folderEnv   "D:/TmpFiles/for_video/Environment"
 set folderVideo "D:/TmpFiles/for_video/Result"
 
+set width 512
+set height 512
+
 # Settings
 set isEditLight 1
 set isGI 1
-set isAnim 1
+set isAnim 0
+
+vinit name=View1 w=${width} h=${height} t=256 l=1024
+vsetdispmode 1
+vcamera -persp -fovy 60
 
-#road
-puts "Loading road..."
-#vdisplayobj   road "${folderEnv}/roadV2.obj"
-#vlocrotate    road 0 0 0 1 0 0 90
-#vlocscale     road 1 1 0 102400
-#vloctranslate road 0 1.0008 3.5
+vzbufftrihedron
 
 #building0
 puts "Loading the first building..."
@@ -49,25 +44,25 @@ puts "Loading the first building..."
 #vlocrotate    building0 0 0 0 0 1 0 45
 #vloctranslate building0 -6 3 3
 
-
 #House N090614
 puts "Loading the second building..."
+#height 7000
 #vdisplayobj   building1 "${folderEnv}/Scene BuildingN090614.obj"
-#vlocscale     building1 1 1 1 21845
+#vlocscale     building1 1 1 1 15555
 #vloctranslate building1 -1 1 1
 #vlocrotate    building1 0 0 0 0 0 1 180
 
 #Building1
 puts "Loading the third building..."
 #vdisplayobj   building2 "${folderEnv}/Scene BuildingN101213.obj"
-#vlocscale     building2 1 1 1 21845
+#vlocscale     building2 1 1 1 15555
 #vloctranslate building2 -1 1 1
 #vlocrotate    building2 0 0 0 0 0 1 180
 
 #lawn
 puts "Loading lawn..."
 #vdisplayobj   lawn "${folderEnv}/Scene Lawn.obj"
-#vlocscale     lawn 1 1 1 21485
+#vlocscale     lawn 1 1 1 15555
 #vloctranslate lawn -1 1 1
 #vlocrotate    lawn 0 0 0 0 0 1 180
 #vsetmaterial  lawn plastic
@@ -76,27 +71,48 @@ puts "Loading lawn..."
 #bench0
 puts "Loading the first bench..."
 #vdisplayobj   bench0 "${folderEnv}/Scene BenchN210815.obj"
-#vlocscale     bench0 1 1 1 21485
+#vlocscale     bench0 1 1 1 15555
 #vloctranslate bench0 -1 1 1
 #vlocrotate    bench0 0 0 0 0 0 1 180
 
 #urn0
 puts "Loading the first urn..."
-vdisplayobj   urn0 "${folderEnv}/Scene Urn.obj"
-vlocscale     urn0 1 1 1 21485
-vloctranslate urn0 -1 1 1
-vlocrotate    urn0 0 0 0 0 0 1 180
+#vdisplayobj   urn0 "${folderEnv}/Scene Urn.obj"
+#vlocscale     urn0 1 1 1 15555
+#vloctranslate urn0 -1 1 1
+#vlocrotate    urn0 0 0 0 0 0 1 180
+
+#The ground
+puts "Loading the ground..."
+#vdisplayobj   ground "${folderEnv}/Scene Ground.obj"
+#vlocscale     ground 1 1 1 25000
+#vloctranslate ground -1 1 1
+#vlocrotate    ground 0 0 0 0 0 1 180
+
+vdisplayobj   building0 "${folderEnv}/Scene Building0.obj"
+#vloctranslate building0 21494 886 0
+
+vdisplayobj   building1 "${folderEnv}/Scene Building1.obj"
+#vloctranslate building1 21494 886 0
 
-vviewparams -eye 24631.990743707178 -5440.5284854311521 10802.013424258917
-vviewparams -at 5913.1650096036392 5334.3047672616967 5730.8013468954196
-vviewparams -proj 0.84373094111182723 -0.48566402239936912 0.22857943117746968
-vviewparams -up -0.41631981347694685 -0.32330155298659913 0.84979639840550847
+vdisplayobj   pave0 "${folderEnv}/Scene Pave0.obj"
+#vloctranslate pave0 21494 886 0
+
+vdisplayobj   pave1 "${folderEnv}/Scene Pave1.obj"
+#vloctranslate pave1 21494 886 0
+
+vdisplayobj   ground "${folderEnv}/Scene Ground 1.obj"
+#vloctranslate ground 21494 886 0
+vviewparams -eye 2791.5312733012979 -725.23102548487986 116.8841126550864
+vviewparams -at 1725.2371931049909 335.97379619693942 -283.97309576949539
+vviewparams -proj 0.68489870691961574 -0.68162979017282999 0.257477359021686
+vviewparams -up -0.077576623573434436 0.2831440641922589 0.95593478145092925
 
 if { ${isEditLight} == 1 } {
   vlight change 0 head 0
   vlight change 0 sm 0.1
   vlight change 0 int 300
-  vlight change 0 direction 1 1 -1
+  vlight change 0 direction -1 0.2 -1
 }
 
 vtextureenv on 4
@@ -105,8 +121,15 @@ vrenderparams -ray -env on
 if { ${isGI} == 1 } {
   vrenderparams -gi
   vrenderparams -brng
+  #vrenderparams -filter on
 }
 
+vdisplayobj   tyre_3 "${folderTyre}/tyre_3.5600.obj"
+#vloctranslate tyre_3 0 0 500
+
+#vdisplayobj   pave "${folderEnv}/pave.obj"
+#vloctranslate pave 0 0 500
+
 proc Anim0 {thePts theLocalPts theName} {
   global startTimeTyre
   global currentTimeTyre
@@ -122,6 +145,9 @@ proc Anim0 {thePts theLocalPts theName} {
   if { ${currentTimeTyre} <= ${endTimeTyre} } {
     puts "Loading tyre_${currentTimeTyre}..."
     vdisplayobj tyre_${currentTimeTyre} "${folderTyre}/tyre_3.${currentTimeTyre}.obj"
+    #vrender -spp 10
+    vloctranslate tyre_${currentTimeTyre} 0 0 500
+    #vrender -spp 1
   }
 
   set currentTimeTyre [expr ${currentTimeTyre} + ${stepTimeTyre}]
@@ -129,6 +155,6 @@ proc Anim0 {thePts theLocalPts theName} {
 
 if { ${isAnim} == 1 } {
   vanim anim0 -reset -onRedraw Anim0
-  vanim anim -reset -addSlice 0.0 0.5 anim0
-  vanim -play anim -playFps 60 -record "${folderVideo}/video.mkv" -recWidth 1920 -recHeight 1080
+  vanim anim -reset -addSlice 0.0 3.0 anim0
+  vanim -play anim -playFps 20 -record "${folderVideo}/video.mkv" -recWidth 1920 -recHeight 1080
 }
index 8e0f2313325da91c2932bf79348c03e1f0f9941b..adca4eeed9e86dad9361dd714c2e801f85a7f11f 100644 (file)
@@ -61,6 +61,8 @@ public:
     IsTransparentShadowEnabled  (Standard_False),
     UseEnvironmentMapBackground (Standard_False),
     CoherentPathTracingMode     (Standard_False),
+    IsGIFilteringEnabled        (Standard_False),
+    RadianceClampValue          (10.0),
     // stereoscopic parameters
     StereoMode (Graphic3d_StereoMode_QuadBuffer),
     AnaglyphFilter (Anaglyph_RedCyan_Optimized),
@@ -99,6 +101,8 @@ public:
   Standard_Boolean        IsTransparentShadowEnabled;  //!< enables/disables light propagation through transparent media, False by default
   Standard_Boolean        UseEnvironmentMapBackground; //!< enables/disables environment map background
   Standard_Boolean        CoherentPathTracingMode;     //!< enables/disables 'coherent' tracing mode (single RNG seed within 16x16 image blocks)
+  Standard_Boolean        IsGIFilteringEnabled;        //!< enables/disables post-processing of GI rendering results
+  Standard_Real           RadianceClampValue;          //!< maximum radiance value which will not be clamped.
 
   Graphic3d_StereoMode    StereoMode;                  //!< stereoscopic output mode, Graphic3d_StereoMode_QuadBuffer by default
   Anaglyph                AnaglyphFilter;              //!< filter for anaglyph output, Anaglyph_RedCyan_Optimized by default
index d75586e5d02454297849f1c8defdbf1c4efef3fe..5fa7024d4480341f0a0668335d317763b2d60122 100644 (file)
@@ -661,10 +661,12 @@ protected: //! @name data types related to ray-tracing
     OpenGl_RT_uSphereMapForBack,
     OpenGl_RT_uTexSamplersArray,
     OpenGl_RT_uBlockedRngEnabled,
+    OpenGl_RT_uMaxRadiance,
 
     // sampled frame params
     OpenGl_RT_uSampleWeight,
     OpenGl_RT_uFrameRndSeed,
+    OpenGl_RT_uBilateralEnabled,
 
     // adaptive FSAA params
     OpenGl_RT_uOffsetX,
index dd8b024c7be6503b90f8fb178556b83ff0ecc9c6..3bf6bad73a0d608400200fb8082b41c89bf4e134 100644 (file)
@@ -1598,6 +1598,8 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
         aShaderProgram->GetUniformLocation (theGlContext, "uSphereMapForBack");
       myUniformLocations[anIndex][OpenGl_RT_uBlockedRngEnabled] =
         aShaderProgram->GetUniformLocation (theGlContext, "uBlockedRngEnabled");
+      myUniformLocations[anIndex][OpenGl_RT_uMaxRadiance] =
+        aShaderProgram->GetUniformLocation (theGlContext, "uMaxRadiance");
 
       myUniformLocations[anIndex][OpenGl_RT_uSampleWeight] =
         aShaderProgram->GetUniformLocation (theGlContext, "uSampleWeight");
@@ -1612,6 +1614,9 @@ Standard_Boolean OpenGl_View::initRaytraceResources (const Handle(OpenGl_Context
 
     theGlContext->BindProgram (myOutImageProgram);
 
+    myUniformLocations[0][OpenGl_RT_uBilateralEnabled] =
+      myOutImageProgram->GetUniformLocation (theGlContext, "uBilateralEnabled");
+
     myOutImageProgram->SetSampler (theGlContext,
       "uInputTexture", OpenGl_RT_PrevAccumTexture);
 
@@ -2489,16 +2494,54 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
       myRNG.SetSeed();
     }
 
-    // Set frame accumulation weight
     myRaytraceProgram->SetUniform (theGlContext,
-      myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + 1));
+      myUniformLocations[0][OpenGl_RT_uMaxRadiance], static_cast<Standard_ShortReal> (myRenderParams.RadianceClampValue));
 
     // Set random number generator seed
     myRaytraceProgram->SetUniform (theGlContext,
       myUniformLocations[0][OpenGl_RT_uFrameRndSeed], static_cast<Standard_Integer> (myRNG.NextInt() >> 2));
-  }
 
-  theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
+    Standard_Integer aSamplesPerPixel = myRenderParams.SamplesPerPixel;
+
+    if (aSamplesPerPixel == 0)
+    {
+      // Set frame accumulation weight
+      myRaytraceProgram->SetUniform (theGlContext,
+        myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + 1));
+
+      theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
+    }
+    else
+    {
+      for (int aPassIndex = 0; aPassIndex < aSamplesPerPixel; ++aPassIndex)
+      {
+        aRenderFramebuffer = (myAccumFrames + aPassIndex) % 2 ? myRaytraceFBO1[aFBOIdx] : myRaytraceFBO2[aFBOIdx];
+        anAccumFramebuffer = (myAccumFrames + aPassIndex) % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
+
+        aRenderFramebuffer->BindBuffer (theGlContext);
+
+        anAccumFramebuffer->ColorTexture()->Bind (
+          theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
+
+        // Set frame accumulation weight
+        myRaytraceProgram->SetUniform (theGlContext,
+          myUniformLocations[0][OpenGl_RT_uSampleWeight], 1.f / (myAccumFrames + aPassIndex + 1));
+
+        // Set random number generator seed
+        myRaytraceProgram->SetUniform (theGlContext,
+          myUniformLocations[0][OpenGl_RT_uFrameRndSeed], static_cast<Standard_Integer> (myRNG.NextInt() >> 2));
+
+        theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
+        //++myAccumFrames;
+        glFinish();
+      }
+    }
+  }
+  else
+  {
+    theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
+    ++myAccumFrames;
+  }
 
   if (myRaytraceParameters.GlobalIllumination)
   {
@@ -2520,6 +2563,9 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
     aRenderFramebuffer->DepthStencilTexture()->Bind (
       theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
 
+    myOutImageProgram->SetUniform (theGlContext,
+      myUniformLocations[0][OpenGl_RT_uBilateralEnabled], myRenderParams.IsGIFilteringEnabled ? 1 : 0);
+
     theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
 
     aRenderFramebuffer->DepthStencilTexture()->Unbind (
index 28f354b5dd461a4b8be2426e434722bffa05fc6d..32c1e665572a35b71e6581dd1b6fea39477141df 100644 (file)
@@ -475,7 +475,7 @@ void OpenGl_View::Redraw()
   if (myRenderParams.Method == Graphic3d_RM_RAYTRACING
    && myRenderParams.IsGlobalIlluminationEnabled)
   {
-    myAccumFrames++;
+    myAccumFrames += myRenderParams.SamplesPerPixel;
   }
 
   // bind default FBO
index 85ebec20e0e4672f65aa66370b1276777fbb47f2..66b71181da83a06bb0d909725eb456cf6e113470 100644 (file)
@@ -4,16 +4,59 @@ uniform sampler2D uInputTexture;
 //! Ray tracing depth image.
 uniform sampler2D uDepthTexture;
 
+uniform int uBilateralEnabled;
+
 //! Output pixel color.
 out vec4 OutColor;
 
+const float rI = 0.270 * 1.0f;  // The intensity radius (in pixels).
+const float rL = 1.71 * 0.5f;   // The geometric radius (in pixels).
+const int WindowSize = 8;       // The window size (in pixels).
+
+float gaussian (float theL, float theR)
+{
+  return exp (-theL * theL / (2.0f * theR * theR));
+}
+
+vec4 bilateral()
+{
+  // Get the sizes
+  int aWindow   = WindowSize / 2;
+  vec4 anOutCol = vec4 (0.f, 0.f, 0.f, 0.f);
+  vec4 aRefCol  = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy), 0);
+  float aNorm   = 0.f;
+
+  // Compute the kernel
+  for (int i = -aWindow; i <= aWindow; i++)
+  {
+    for (int j = -aWindow; j <= aWindow; j++)
+    {
+      vec4 aCol = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy) + ivec2 (j, i), 0);
+      float A = gaussian (distance (aCol, aRefCol), rI);
+      float B = gaussian (length (vec2(j, i)), rL);
+      anOutCol += aCol * A * B;
+      aNorm += A * B;
+    }
+  }
+  return anOutCol * (1.f / aNorm);
+}
+
 void main (void)
 {
-  vec4 aColor = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy), 0);
+  vec4 aColor;
+
+  if (bool (uBilateralEnabled))
+  {
+    aColor = bilateral();
+  }
+  else
+  {
+    aColor = texelFetch (uInputTexture, ivec2 (gl_FragCoord.xy), 0);
+  }
 
   float aDepth = texelFetch (uDepthTexture, ivec2 (gl_FragCoord.xy), 0).r;
   gl_FragDepth = aDepth;
 
   // apply gamma correction (we use gamma = 2)
   OutColor = vec4 (sqrt (aColor.rgb), aColor.a);
-}
+}
\ No newline at end of file
index 25c9bbec19950100f02f22b97bcd3f5364dd9108..a8ce317863d224781c8bf318c832543f0ff52ddc 100644 (file)
@@ -13,7 +13,8 @@ uniform sampler2D uAccumTexture;
 //! Increases performance up to 4 times, but noise becomes structured.
 uniform int uBlockedRngEnabled;
 
-#define MAX_RADIANCE vec3 (10.f)
+//! Maximum value for radiance clamping.
+uniform float uMaxRadiance;
 
 // =======================================================================
 // function : main
@@ -46,7 +47,7 @@ void main (void)
     aColor.rgb = ZERO;
   }
 
-  aColor.rgb = min (aColor.rgb, MAX_RADIANCE);
+  aColor.rgb = min (aColor.rgb, vec3 (uMaxRadiance));
 
   OutColor = mix (texture2D (uAccumTexture, vPixel), aColor, uSampleWeight);
 #else
index 9e63f23627fcf4f84566e2d7ded55471283c4382..1f001121cfb449be4718896d774365419394c48f 100644 (file)
@@ -8259,6 +8259,8 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
     theDI << "reflections:  " << (aParams.IsReflectionEnabled         ? "on" : "off") << "\n";
     theDI << "gleam:        " << (aParams.IsTransparentShadowEnabled  ? "on" : "off") << "\n";
     theDI << "GI:           " << (aParams.IsGlobalIlluminationEnabled ? "on" : "off") << "\n";
+    theDI << "samples:      " <<  aParams.SamplesPerPixel                             << "\n";
+    theDI << "filtering:    " << (aParams.IsGIFilteringEnabled        ? "on" : "off") << "\n";
     theDI << "blocked RNG:  " << (aParams.CoherentPathTracingMode     ? "on" : "off") << "\n";
     theDI << "shadingModel: ";
     switch (aView->ShadingModel())
@@ -8382,6 +8384,48 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
         aParams.RaytracingDepth = aDepth;
       }
     }
+    else if (aFlag == "-maxrad"
+          || aFlag == "-rclamp")
+    {
+      if (toPrint)
+      {
+        theDI << aParams.RadianceClampValue << " ";
+        continue;
+      }
+      else if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+        return 1;
+      }
+
+      aParams.RadianceClampValue = Draw::Atoi (theArgVec[anArgIter]);
+    }
+    else if (aFlag == "-samples"
+          || aFlag == "-spp")
+    {
+      if (toPrint)
+      {
+        theDI << aParams.SamplesPerPixel << " ";
+        continue;
+      }
+      else if (++anArgIter >= theArgNb)
+      {
+        std::cerr << "Error: wrong syntax at argument '" << anArg << "'\n";
+        return 1;
+      }
+
+      const Standard_Integer aSamples = Draw::Atoi (theArgVec[anArgIter]);
+
+      if (aSamples < 0)
+      {
+        std::cerr << "Error: invalid ray-tracing samples per pixel " << aSamples << ". SPP should be a positive number.\n";
+        return 1;
+      }
+      else
+      {
+        aParams.SamplesPerPixel = aSamples;
+      }
+    }
     else if (aFlag == "-shad"
           || aFlag == "-shadows")
     {
@@ -8468,6 +8512,22 @@ static Standard_Integer VRenderParams (Draw_Interpretor& theDI,
         aParams.RaytracingDepth = Min (aParams.RaytracingDepth, 10);
       }
     }
+    else if (aFlag == "-filter" || aFlag == "-pp" )
+    {
+      if (toPrint)
+      {
+        theDI << (aParams.IsGIFilteringEnabled ? "on" : "off") << " ";
+        continue;
+      }
+
+      Standard_Boolean toEnable = Standard_True;
+      if (++anArgIter < theArgNb
+      && !ViewerTest::ParseOnOff (theArgVec[anArgIter], toEnable))
+      {
+        --anArgIter;
+      }
+      aParams.IsGIFilteringEnabled = toEnable;
+    }
     else if (aFlag == "-blockedrng"
           || aFlag == "-brng")
     {