0029519: Visualization, TKOpenGl - fallback to Graphic3d_TOSM_FACET from Gouraud...
authorkgv <kgv@opencascade.com>
Tue, 20 Feb 2018 05:00:01 +0000 (08:00 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 2 Mar 2018 12:27:44 +0000 (15:27 +0300)
dox/dev_guides/upgrade/upgrade.md
src/OpenGl/OpenGl_PrimitiveArray.cxx
src/OpenGl/OpenGl_ShaderManager.hxx

index 6ab4f2f..b663b7c 100644 (file)
@@ -1521,6 +1521,15 @@ Multiple changes have been applied to lights management within TKV3d and TKOpenG
   Dedicated classes only hides visibility of unrelated light properties depending on its type.
 * Calling V3d_Viewer::UpdateLights() is no more required after modifying light sources properties (color, position, etc.).
 
+@subsection upgrade_730_shadingmodels Shading Models
+
+*Graphic3d_AspectFillArea3d* has been extended by a new property ::ShadingModel(), which previously has been defined globally for entire View.
+
+Previously, triangle array without normal vertex attributes was implicitly considered as unshaded,
+but now such array will be shaded using *Graphic3d_TOSM_FACET* model (e.g. by computing per-triangle normals).
+Therefore, *Graphic3d_TOSM_UNLIT* should be explicitly specified for disabling shading or triangles array.
+Alternatively, material without reflectance properties can be used for disabling shading as before.
+
 @subsection upgrade_730_tkopengl Custom low-level OpenGL elements
 
 The following API changes should be considered while porting custom OpenGl_Element objects:
index 3102b9a..fa805f2 100644 (file)
@@ -733,11 +733,6 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
     myIsVboInit = Standard_True;
   }
 
-  const Standard_Boolean hasColorAttrib = !myVboAttribs.IsNull()
-                                        && myVboAttribs->HasColorAttribute();
-  const Graphic3d_TypeOfShadingModel aShadingModel = aCtx->ShaderManager()->ChooseShadingModel (anAspectFace->ShadingModel(),
-                                                                                                !myVboAttribs.IsNull() &&  myVboAttribs->HasNormalAttribute());
-
   // Temporarily disable environment mapping
   Handle(OpenGl_TextureSet) aTextureBack;
   bool toDrawArray = true;
@@ -758,14 +753,19 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
     }
   }
 
+  Graphic3d_TypeOfShadingModel aShadingModel = Graphic3d_TOSM_UNLIT;
   if (toDrawArray)
   {
-    const bool             toHilight    = theWorkspace->ToHighlight();
-    const Standard_Boolean hasVertColor = hasColorAttrib && !toHilight;
+    const bool hasColorAttrib = !myVboAttribs.IsNull()
+                              && myVboAttribs->HasColorAttribute();
+    const bool toHilight    = theWorkspace->ToHighlight();
+    const bool hasVertColor = hasColorAttrib && !toHilight;
+    const bool hasVertNorm  = !myVboAttribs.IsNull() && myVboAttribs->HasNormalAttribute();
     switch (myDrawMode)
     {
       case GL_POINTS:
       {
+        aShadingModel = aCtx->ShaderManager()->ChooseMarkerShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
         const Handle(OpenGl_TextureSet)& aSpriteNormRes = anAspectMarker->SpriteRes (aCtx);
         const OpenGl_PointSprite* aSpriteNorm = !aSpriteNormRes.IsNull() ? dynamic_cast<const OpenGl_PointSprite*> (aSpriteNormRes->First().get()) : NULL;
         if (aSpriteNorm != NULL
@@ -786,6 +786,7 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
       case GL_LINES:
       case GL_LINE_STRIP:
       {
+        aShadingModel = aCtx->ShaderManager()->ChooseLineShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
         aCtx->ShaderManager()->BindLineProgram (NULL,
                                                 anAspectLine->Aspect()->Type(),
                                                 aShadingModel,
@@ -795,6 +796,7 @@ void OpenGl_PrimitiveArray::Render (const Handle(OpenGl_Workspace)& theWorkspace
       }
       default:
       {
+        aShadingModel = aCtx->ShaderManager()->ChooseFaceShadingModel (anAspectFace->ShadingModel(), hasVertNorm);
         const Handle(OpenGl_TextureSet)& aTextures = aCtx->ActiveTextures();
         const Standard_Boolean toEnableEnvMap = (!aTextures.IsNull() && (aTextures == theWorkspace->EnvironmentTexture()));
         aCtx->ShaderManager()->BindFaceProgram (aTextures,
index 637208f..115f067 100644 (file)
@@ -316,9 +316,10 @@ public:
     return myContext == theCtx;
   }
 
-  //! Choose Shading Model.
-  Graphic3d_TypeOfShadingModel ChooseShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
-                                                   bool theHasNodalNormals) const
+  //! Choose Shading Model for filled primitives.
+  //! Fallbacks to FACET model if there are no normal attributes.
+  Graphic3d_TypeOfShadingModel ChooseFaceShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
+                                                       bool theHasNodalNormals) const
   {
     if (!myContext->ColorMask())
     {
@@ -330,13 +331,42 @@ public:
       case Graphic3d_TOSM_DEFAULT:
       case Graphic3d_TOSM_UNLIT:
       case Graphic3d_TOSM_FACET:
-        break;
+        return aModel;
       case Graphic3d_TOSM_VERTEX:
       case Graphic3d_TOSM_FRAGMENT:
-        aModel = theHasNodalNormals ? aModel : Graphic3d_TOSM_UNLIT;
-        break;
+        return theHasNodalNormals ? aModel : Graphic3d_TOSM_FACET;
     }
-    return aModel;
+    return Graphic3d_TOSM_UNLIT;
+  }
+
+  //! Choose Shading Model for line primitives.
+  //! Fallbacks to UNLIT model if there are no normal attributes.
+  Graphic3d_TypeOfShadingModel ChooseLineShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
+                                                       bool theHasNodalNormals) const
+  {
+    if (!myContext->ColorMask())
+    {
+      return Graphic3d_TOSM_UNLIT;
+    }
+    Graphic3d_TypeOfShadingModel aModel = theCustomModel != Graphic3d_TOSM_DEFAULT ? theCustomModel : myShadingModel;
+    switch (aModel)
+    {
+      case Graphic3d_TOSM_DEFAULT:
+      case Graphic3d_TOSM_UNLIT:
+      case Graphic3d_TOSM_FACET:
+        return Graphic3d_TOSM_UNLIT;
+      case Graphic3d_TOSM_VERTEX:
+      case Graphic3d_TOSM_FRAGMENT:
+        return theHasNodalNormals ? aModel : Graphic3d_TOSM_UNLIT;
+    }
+    return Graphic3d_TOSM_UNLIT;
+  }
+
+  //! Choose Shading Model for Marker primitives.
+  Graphic3d_TypeOfShadingModel ChooseMarkerShadingModel (Graphic3d_TypeOfShadingModel theCustomModel,
+                                                         bool theHasNodalNormals) const
+  {
+    return ChooseLineShadingModel (theCustomModel, theHasNodalNormals);
   }
 
   //! Returns default Shading Model.