0027337: [Regression vs. 6.9.1] Selection highlight is poor in ray traced mode with...
authorduv <duv@opencascade.com>
Mon, 4 Apr 2016 09:16:49 +0000 (12:16 +0300)
committerabv <abv@opencascade.com>
Mon, 4 Apr 2016 13:47:09 +0000 (16:47 +0300)
For FSAA mode we now store the depth values from first sample in myRaytraceFBO1 and do not modify it while collecting the rest of samples.
When all samples are gathered we fetch color from myRaytraceFBO2 and depth from myRaytraceFBO1 and display it to the current FBO.

Test bugs vis bug27337 added.

src/OpenGl/OpenGl_View_Raytrace.cxx
src/Shaders/Display.fs
tests/bugs/vis/bug27337 [new file with mode: 0644]

index ecc26ac..0c7dc00 100644 (file)
@@ -2358,6 +2358,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
   bindRaytraceTextures (theGlContext);
 
   Handle(OpenGl_FrameBuffer) aRenderFramebuffer;
+  Handle(OpenGl_FrameBuffer) aDepthSourceFramebuffer;
   Handle(OpenGl_FrameBuffer) anAccumFramebuffer;
 
   // Choose proper set of framebuffers for stereo rendering
@@ -2369,6 +2370,7 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
   {
     aRenderFramebuffer = myAccumFrames % 2 ? myRaytraceFBO1[aFBOIdx] : myRaytraceFBO2[aFBOIdx];
     anAccumFramebuffer = myAccumFrames % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
+    aDepthSourceFramebuffer = aRenderFramebuffer;
 
     anAccumFramebuffer->ColorTexture()->Bind (
       theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
@@ -2407,36 +2409,10 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
 
   theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
 
-  if (myRaytraceParameters.GlobalIllumination)
+  if (myRenderParams.IsAntialiasingEnabled)
   {
-    // Output accumulated image
-    theGlContext->BindProgram (myOutImageProgram);
-
-    if (theReadDrawFbo != NULL)
-    {
-      theReadDrawFbo->BindBuffer (theGlContext);
-    }
-    else
-    {
-      aRenderFramebuffer->UnbindBuffer (theGlContext);
-    }
-
-    aRenderFramebuffer->ColorTexture()->Bind (
-      theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
-
-    aRenderFramebuffer->DepthStencilTexture()->Bind (
-      theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
+    glDepthMask (GL_FALSE);
 
-    theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
-
-    aRenderFramebuffer->DepthStencilTexture()->Unbind (
-      theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
-
-    aRenderFramebuffer->ColorTexture()->Unbind (
-      theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
-  }
-  else if (myRenderParams.IsAntialiasingEnabled)
-  {
     myRaytraceFBO1[aFBOIdx]->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture);
 
     aResult &= theGlContext->BindProgram (myPostFSAAProgram);
@@ -2482,29 +2458,48 @@ Standard_Boolean OpenGl_View::runRaytraceShaders (const Standard_Integer
 
       Handle(OpenGl_FrameBuffer)& aFramebuffer = anIt % 2 ? myRaytraceFBO2[aFBOIdx] : myRaytraceFBO1[aFBOIdx];
 
-      if (anIt == 3) // disable FBO on last iteration
-      {
-        if (theReadDrawFbo != NULL)
-        {
-          theReadDrawFbo->BindBuffer (theGlContext);
-        }
-        else
-        {
-          aFramebuffer->UnbindBuffer (theGlContext);
-        }
-      }
-      else
-      {
-        aFramebuffer->BindBuffer (theGlContext);
-      }
+      aFramebuffer->BindBuffer (theGlContext);
 
       theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
 
-      if (anIt != 3) // set input for the next pass
-      {
-        aFramebuffer->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture);
-      }
+      aFramebuffer->ColorTexture()->Bind (theGlContext, GL_TEXTURE0 + OpenGl_RT_FsaaInputTexture);
     }
+
+    aRenderFramebuffer = myRaytraceFBO2[aFBOIdx];
+    aDepthSourceFramebuffer = myRaytraceFBO1[aFBOIdx];
+  }
+
+  if (myRaytraceParameters.GlobalIllumination || myRenderParams.IsAntialiasingEnabled)
+  {
+    // Output accumulated image
+    glDepthMask (GL_TRUE);
+
+    theGlContext->BindProgram (myOutImageProgram);
+
+    myOutImageProgram->SetUniform (theGlContext, "uApplyGamma", static_cast<Standard_Integer> (myRaytraceParameters.GlobalIllumination));
+
+    if (theReadDrawFbo != NULL)
+    {
+      theReadDrawFbo->BindBuffer (theGlContext);
+    }
+    else
+    {
+      aRenderFramebuffer->UnbindBuffer (theGlContext);
+    }
+
+    aRenderFramebuffer->ColorTexture()->Bind (
+      theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
+
+    aDepthSourceFramebuffer->DepthStencilTexture()->Bind (
+      theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
+
+    theGlContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
+
+    aDepthSourceFramebuffer->DepthStencilTexture()->Unbind (
+      theGlContext, GL_TEXTURE0 + OpenGl_RT_DepthTexture);
+
+    aRenderFramebuffer->ColorTexture()->Unbind (
+      theGlContext, GL_TEXTURE0 + OpenGl_RT_PrevAccumTexture);
   }
 
   unbindRaytraceTextures (theGlContext);
@@ -2578,10 +2573,13 @@ Standard_Boolean OpenGl_View::raytrace (const Standard_Integer        theSizeX,
         0, GL_DEBUG_SEVERITY_MEDIUM, "Error: Failed to acquire OpenGL image textures");
     }
 
-    // Remember the old depth function
+    // Remember the old depth function and mask
     GLint aDepthFunc;
     theGlContext->core11fwd->glGetIntegerv (GL_DEPTH_FUNC, &aDepthFunc);
 
+    GLboolean aDepthMask;
+    theGlContext->core11fwd->glGetBooleanv (GL_DEPTH_WRITEMASK, &aDepthMask);
+
     glDisable (GL_BLEND);
     glDepthFunc (GL_ALWAYS);
 
@@ -2595,8 +2593,9 @@ Standard_Boolean OpenGl_View::raytrace (const Standard_Integer        theSizeX,
                                                    theReadDrawFbo,
                                                    theGlContext);
 
-    // Restore depth function
+    // Restore depth function and mask
     glDepthFunc (aDepthFunc);
+    glDepthMask (aDepthMask);
 
     if (!aResult)
     {
index 85ebec2..d367df8 100644 (file)
@@ -4,6 +4,9 @@ uniform sampler2D uInputTexture;
 //! Ray tracing depth image.
 uniform sampler2D uDepthTexture;
 
+//! Gamma correction flag.
+uniform int uApplyGamma;
+
 //! Output pixel color.
 out vec4 OutColor;
 
@@ -14,6 +17,13 @@ void main (void)
   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);
+  if (uApplyGamma == 1)
+  {
+    // apply gamma correction (we use gamma = 2)
+    OutColor = vec4 (sqrt (aColor.rgb), aColor.a);
+  }
+  else
+  {
+    OutColor = aColor;
+  }
 }
diff --git a/tests/bugs/vis/bug27337 b/tests/bugs/vis/bug27337
new file mode 100644 (file)
index 0000000..32eda94
--- /dev/null
@@ -0,0 +1,18 @@
+puts "================"
+puts "0027337: \[Regression vs. 6.9.1\] Selection highlight is poor in ray traced mode with FSAA"
+puts "================"
+
+pload MODELING VISUALIZATION
+box b 10 10 10
+vdisplay b
+vsetdispmode 1
+vfit
+vrenderparams -rayTrace -fsaa
+vmoveto 200 200
+
+puts "Check result by color in the middle of the top face:"
+puts "should be color of shading and not of highlight (blue)"
+checkcolor 205 100 0.64 0.56 0.08
+
+puts "Check result by image: selection highlight should show only visible edges"
+checkview -screenshot -3d -path ${imagedir}/${test_image}.png