]> OCCT Git - occt.git/commitdiff
#attempt to fix scale
authormzernova <mzernova@opencascade.com>
Wed, 16 Aug 2023 15:18:15 +0000 (16:18 +0100)
committermzernova <mzernova@opencascade.com>
Wed, 11 Sep 2024 10:33:08 +0000 (11:33 +0100)
src/Graphic3d/Graphic3d_ShaderManager.cxx
src/Graphic3d/Graphic3d_StructureManager.cxx
src/OpenGl/OpenGl_View.cxx

index 324793bee36c971bb672c0bc30888408f2a72b4c..f7640fed46362b66204cde979ac8c07cbe1c2bba 100644 (file)
@@ -2217,7 +2217,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
     EOL"}";
 
   TCollection_AsciiString aSrcFrag = TCollection_AsciiString()
-  + EOL"vec4 grid (vec3 theFragPos3D, vec3 theColor, float theScale, bool theIsDrawAxis)"
+  + EOL"vec4 grid (vec3 theFragPos3D, vec3 theColor, float theScale, bool theIsDrawAxis, float theThickness)"
     EOL"{"
     EOL"  vec2 aCoord = theFragPos3D.xy * theScale;"
     EOL"  vec2 aDerivative = fwidth (aCoord);"
@@ -2225,6 +2225,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
     EOL"  float aLine = min (aGrid.x, aGrid.y);"
     EOL"  float aMinY = min (aDerivative.y, 1);"
     EOL"  float aMinX = min (aDerivative.x, 1);"
+
     EOL"  vec4 aColor = vec4 (theColor, round (1.0 - min (aLine, 1.0)));"
     EOL"  if (uIsDrawAxis && theIsDrawAxis)"
     EOL"  {"
@@ -2255,14 +2256,60 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
     EOL"  float aParam = -NearPoint.z / (FarPoint.z - NearPoint.z);"
     EOL"  vec3 aFragPos3D = NearPoint + aParam * (FarPoint - NearPoint);"
     EOL"  float aLinearDepth = computeLinearDepth (aFragPos3D);"
-    // TODO : Compute scale
-    //EOL"  float aScale = 100.0 / pow (10.0, uScale);"
-    EOL"  float aScaleBig = 10.0 / pow (2.0, 10.0);"
-    EOL"  float aScale = 10.0 / pow (2.0, uScale);"
-    EOL"  vec4 aBigGridColor = grid (aFragPos3D, vec3 (0.8), aScaleBig, true);"
-    //EOL"  vec4 aColor = aBigGridColor;"
+
+    //EOL"  float aScale = /*0.001*/ 1.0 / uScale;"
+
+/*
+pload ALL
+vinit
+vcamera -persp
+box b 100 100 100
+vdisplay b -dispmode 1
+vfit
+*/
+
+    /*EOL"  float aScale;"
+    EOL"  if (uScale < 10.0) {"
+    EOL"    aScale = 1.0;"
+    EOL"  }"
+    EOL"  else if (uScale < 100.0) {"
+    EOL"    aScale = 0.1;"
+    EOL"  }"
+    EOL"  else if (uScale < 1000.0) {"
+    EOL"    aScale = 0.01;"
+    EOL"  }"
+    EOL"  else if (uScale < 10000.0) {"
+    EOL"    aScale = 0.001;"
+    EOL"  }"
+    EOL"  else if (uScale < 100000.0) {"
+    EOL"    aScale = 0.0001;"
+    EOL"  }"
+    EOL"  else if (uScale < 1000000.0) {"
+    EOL"    aScale = 0.00001;"
+    EOL"  }"
+    EOL"  else if (uScale < 10000000.0) {"
+    EOL"    aScale = 0.000001;"
+    EOL"  }"
+    EOL"  else if (uScale < 100000000.0) {"
+    EOL"    aScale = 0.0000001;"
+    EOL"  }"
+    EOL"  else if (uScale < 1000000000.0) {"
+    EOL"    aScale = 0.00000001;"
+    EOL"  }"
+    EOL"  else if (uScale < 10000000000.0) {"
+    EOL"    aScale = 0.000000001;"
+    EOL"  }"
+    EOL"  else if (uScale < 100000000000.0) {"
+    EOL"    aScale = 0.0000000001;"
+    EOL"  }"
+    EOL"  else {"
+    EOL"    aScale = 0.00000000001;"
+    EOL"  }"*/
+
+
+    EOL"  vec4 aBigGridColor = grid (aFragPos3D, vec3 (0.8), uScale, true, 500.0);"
     EOL"  vec4 aColor = aBigGridColor.a == 0.0"
-    EOL"              ? grid (aFragPos3D, vec3 (0.2), aScale, false)"
+    EOL"              ? grid (aFragPos3D, vec3 (0.2), uScale * 10.0, false, 0.1)"
     EOL"              : aBigGridColor;"
     EOL"  float aDepth = computeDepth (aFragPos3D);"
     EOL"  float aFar  = gl_DepthRange.far;"
@@ -2273,30 +2320,28 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
     EOL"    discard;"
     EOL"  };"
     // TODO : Get actual background color
-    EOL"  vec4 aBackgroundColor = vec4 (0.0, 0.0, 0.0, 1.0);"
+    EOL"  vec4 aBackgroundColor = vec4 (0.0, 0.0, 0.0, aColor.a);"
     EOL"  if (abs (aLinearDepth) > 1.0)"
     EOL"  {"
-    EOL"    float anInterpVal = float (aLinearDepth > 0.0) - sign (aLinearDepth) * clamp (1.0 / (abs (aLinearDepth) - 1.0), 0.5, 1.0);"
-    EOL"    aColor = mix (aColor, aBackgroundColor, anInterpVal);"
+    EOL"    float aFading;"
+    //EOL"    if (aLinearDepth > 0.0) { aFading = 1.0 - (3.0 - aLinearDepth + 2.0) * 0.25; }"
+    //EOL"    else                    { aFading = 1.0 + (3.0 + aLinearDepth - 2.0) * 0.25; }"
+    EOL"    if (aLinearDepth > 0.0) { aFading = (aLinearDepth - 1.0) / ( 1.0 - 2.0) * (0.5 - 0.0) + 0.0; }"
+    EOL"    else                    { aFading = (aLinearDepth + 2.0) / (-1.0 + 2.0) * (1.0 - 0.5) + 0.5; }"
+    EOL"    aColor = mix (aColor, aBackgroundColor, aFading);"
+
+    //EOL"    float anInterpVal = float (aLinearDepth > 0.0) - sign (aLinearDepth) * clamp (1.0 / (abs (aLinearDepth) - 1.0), 0.5, 1.0);"
+    //EOL"    aColor = mix (aColor, aBackgroundColor, anInterpVal);"
     //EOL"    aColor = mix (aColor, aBackgroundColor, 0.99);"
     EOL"  }"
 
-    /*EOL"  if (aLinearDepth < -1.0)"
-    EOL"  {"
-    EOL"    aColor = vec4 (1.0, 0.0, 0.0, 1.0);"
-    EOL"  }"
-    EOL"  else if (aLinearDepth < 0.0)"
-    EOL"  {"
-    EOL"    aColor = vec4 (0.0, 1.0, 0.0, 1.0);"
-    EOL"  }"
-    EOL"  else if (aLinearDepth < 1.0)"
-    EOL"  {"
-    EOL"    aColor = vec4 (0.0, 0.0, 1.0, 1.0);"
-    EOL"  }"
-    EOL"  else"
-    EOL"  {"
-    EOL"    aColor = vec4 (1.0, 1.0, 0.0, 1.0);"
-    EOL"  }"*/
+    EOL"  if (aLinearDepth < -1.5)      { aColor = vec4 (0.0, 1.0, 1.0, 1.0); }"
+    EOL"  else if (aLinearDepth < -1.0) { aColor = vec4 (1.0, 0.0, 0.0, 1.0); }"
+    EOL"  else if (aLinearDepth < 0.0)  { aColor = vec4 (0.0, 1.0, 0.0, 1.0); }"
+    EOL"  else if (aLinearDepth < 1.0)  { aColor = vec4 (0.0, 0.0, 1.0, 1.0); }"
+    EOL"  else if (aLinearDepth < 1.5)  { aColor = vec4 (1.0, 0.0, 1.0, 1.0); }"
+    EOL"  else if (aLinearDepth < 2.0)  { aColor = vec4 (1.0, 0.0, 0.0, 1.0); }"
+    EOL"  else                          { aColor = vec4 (1.0, 1.0, 0.0, 1.0); }"
 
     EOL"  gl_FragDepth = aDepth;"
     EOL"  occFragColor = aColor;"
index 5abb44781f2c95d2267cab34af37a1e5c577ab7a..3fbd7478fa890d8d60f90bb0746c91f97583c816 100644 (file)
@@ -98,16 +98,16 @@ void Graphic3d_StructureManager::DisplayedStructures (Graphic3d_MapOfStructure&
 
   SG.Assign(myDisplayedStructure);
 
-  //JMBStandard_Integer Length  = myDisplayedStructure.Length ();
+  //JMBStandard_Integer Length  = myDisplayedStructure.Length();
 
   //JMBfor (Standard_Integer i=1; i<=Length; i++)
   //JMB SG.Add (myDisplayedStructure.Value (i));
 
 }
 
-Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures () const {
+Standard_Integer Graphic3d_StructureManager::NumberOfDisplayedStructures() const {
 
-Standard_Integer Length = myDisplayedStructure.Extent ();
+Standard_Integer Length = myDisplayedStructure.Extent();
 
         return (Length);
 
@@ -138,7 +138,7 @@ Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const St
 
   for (; it.More() && notfound; it.Next()) {
     const Handle(Graphic3d_Structure)& SG = it.Key();
-    if ( SG->Identification () == AId) {
+    if ( SG->Identification() == AId) {
       notfound  = Standard_False;
       SGfound = SG;
     }
@@ -152,7 +152,7 @@ Handle(Graphic3d_Structure) Graphic3d_StructureManager::Identification (const St
 
 }
 
-const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver () const 
+const Handle(Graphic3d_GraphicDriver)& Graphic3d_StructureManager::GraphicDriver() const 
 {
   return (myGraphicDriver);
 }
index caa08b902334150bf200ec2c74f5104b75f5670c..76042f81d102b9c2816a63362bae803d47a8d0c5 100644 (file)
@@ -2671,7 +2671,9 @@ void OpenGl_View::renderGrid()
 
   int k = (int)(log10 (aContext->Camera()->Scale()) / log10(2));
 
-  Standard_Integer aScale = k;
+  //Standard_Integer aScale = k;
+  const Standard_Real aCameraScale = aContext->Camera()->Scale();
+  Standard_Real aScale = 10.0 / pow (10.0, floor (log10 (Max (aCameraScale, 1.0))) + 1.0);
   //std::cout << "Scale: " << aScale << std::endl;
 
   //aContext->Camera()->SetZRange (aContext->Camera()->ZNear(), aContext->Camera()->ZFar() + 1.0);
@@ -2682,6 +2684,8 @@ void OpenGl_View::renderGrid()
     aProg->SetUniform (aContext, "uZNear", GLfloat (aContext->Camera()->ZNear()));
     aProg->SetUniform (aContext, "uZFar",  GLfloat (aContext->Camera()->ZFar()));
     aProg->SetUniform (aContext, "uScale", GLfloat (aScale));
+    std::cout << aContext->Camera()->Scale() << std::endl;
+    std::cout << aScale << std::endl;
     // TODO : add param to draw command
     aProg->SetUniform (aContext, "uIsDrawAxis", GLboolean (true));