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()
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);"
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;"
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"}";
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));