]> OCCT Git - occt.git/commitdiff
add scale
authormzernova <marina.zernova@opencascade.com>
Mon, 10 Oct 2022 13:00:20 +0000 (16:00 +0300)
committermzernova <mzernova@opencascade.com>
Wed, 11 Sep 2024 10:33:07 +0000 (11:33 +0100)
src/Graphic3d/Graphic3d_ShaderManager.cxx
src/OpenGl/OpenGl_View.cxx

index d70a83d4b99f99424588fafb43d8a117d4813b13..9f61c2f4f94a091d7a0d27ec17d0f68f1cb01697 100644 (file)
@@ -2194,6 +2194,7 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
   aStageInOuts.Append (Graphic3d_ShaderObject::ShaderVariable ("mat4 MVP", Graphic3d_TOS_VERTEX | Graphic3d_TOS_FRAGMENT));
   aUniforms.Append (Graphic3d_ShaderObject::ShaderVariable ("float uZNear", Graphic3d_TOS_FRAGMENT));
   aUniforms.Append (Graphic3d_ShaderObject::ShaderVariable ("float uZFar", Graphic3d_TOS_FRAGMENT));
+  aUniforms.Append (Graphic3d_ShaderObject::ShaderVariable ("float uScale", Graphic3d_TOS_FRAGMENT));
   aUniforms.Append (Graphic3d_ShaderObject::ShaderVariable ("bool uIsDrawAxis", Graphic3d_TOS_FRAGMENT));
 
   TCollection_AsciiString aSrcVert = TCollection_AsciiString()
@@ -2216,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)"
     EOL"{"
     EOL"  vec2 aCoord = theFragPos3D.xy * theScale;"
     EOL"  vec2 aDerivative = fwidth (aCoord);"
@@ -2255,9 +2256,12 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
     EOL"  vec3 aFragPos3D = NearPoint + aParam * (FarPoint - NearPoint);"
     EOL"  float aLinearDepth = computeLinearDepth (aFragPos3D);"
     // TODO : Compute scale
-    EOL"  vec4 aBigGridColor = grid (aFragPos3D, vec3 (0.8), 0.01, true);"
+    //EOL"  float aScale = 100.0 / pow (10.0, uScale);"
+    EOL"  float aScale = 10.0 / pow (2.0, uScale);"
+    EOL"  vec4 aBigGridColor = grid (aFragPos3D, vec3 (0.8), aScale * 0.1, true);"
+    //EOL"  vec4 aColor = aBigGridColor;"
     EOL"  vec4 aColor = aBigGridColor.a == 0.0"
-    EOL"              ? grid (aFragPos3D, vec3 (0.2), 0.1, false)"
+    EOL"              ? grid (aFragPos3D, vec3 (0.2), aScale, false)"
     EOL"              : aBigGridColor;"
     EOL"  float aDepth = computeDepth (aFragPos3D);"
     EOL"  float aFar  = gl_DepthRange.far;"
@@ -2273,7 +2277,38 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
     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"    aColor = mix (aColor, aBackgroundColor, 0.99);;"
+
+    EOL"    if (gl_FragCoord.x < 200.0)"
+    EOL"    {"
+    EOL"      if (anInterpVal < 0.25)"
+    EOL"        aColor = vec4 (1.0, 0.0, 0.0, 1.0);"
+    EOL"      else if (anInterpVal < 0.5)"
+    EOL"        aColor = vec4 (0.0, 1.0, 0.0, 1.0);"
+    EOL"      else if (anInterpVal < 0.75)"
+    EOL"        aColor = vec4 (0.0, 0.0, 1.0, 1.0);"
+    EOL"      else"
+    EOL"        aColor = vec4 (1.0, 1.0, 0.0, 1.0);"
+    EOL"    }"
     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"  gl_FragDepth = aDepth;"
     EOL"  occFragColor = aColor;"
     EOL"}";
index c26975bfcdd5d9edf12e0eb01573b35e0a8fff8e..44cfa80a1426016e1dc7d760d40fed789ce8b9f7 100644 (file)
@@ -2611,11 +2611,35 @@ void OpenGl_View::renderGrid()
   aContext->core11fwd->glEnable (GL_BLEND);
   aContext->core11fwd->glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 
+  aContext->core11fwd->glEnable(GL_MULTISAMPLE);
+
+  Graphic3d_Vec4 anUnprojPnt = aContext->WorldViewState.Current().Inverted() * aContext->ProjectionState.Current().Inverted() * Graphic3d_Vec4 (1.0, 1.0, 0.0, 1.0);
+  Graphic3d_Vec3 aVal = anUnprojPnt.xyz() / anUnprojPnt.w();
+  std::cout << anUnprojPnt.w() << std::endl;
+  std::cout << aVal.x() << " " << aVal.y() << " " << aVal.z() << std::endl;
+
+  //Standard_Integer aScale = TCollection_AsciiString(RealToInt(aContext->Camera()->Scale())).Length();
+
+  unsigned x = (unsigned) aContext->Camera()->Scale();
+  x = x - 1;
+  x = x | (x >> 1);
+  x = x | (x >> 2);
+  x = x | (x >> 4);
+  x = x | (x >> 8);
+  x = x | (x >> 16);
+  x = x + 1;
+
+  int k = (int)(log10 (aContext->Camera()->Scale()) / log10(2));
+
+  Standard_Integer aScale = k;
+  std::cout << "Scale: " << aScale << std::endl;
+
   if (aContext->ShaderManager()->BindGridProgram())
   {
     const Handle(OpenGl_ShaderProgram)& aProg = aContext->ActiveProgram();
     aProg->SetUniform (aContext, "uZNear", GLfloat (aContext->Camera()->ZNear()));
-    aProg->SetUniform (aContext, "uZFar", GLfloat (aContext->Camera()->ZFar()));
+    aProg->SetUniform (aContext, "uZFar",  GLfloat (aContext->Camera()->ZFar()));
+    aProg->SetUniform (aContext, "uScale", GLfloat (aScale));
     // TODO : add param to draw command
     aProg->SetUniform (aContext, "uIsDrawAxis", GLboolean (true));