mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-04 18:06:22 +03:00
#current progress
This commit is contained in:
parent
fb9efc49b6
commit
caf420c6d6
@ -573,6 +573,38 @@ Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIncludeAuxili
|
||||
aCamera,
|
||||
aWinSize.x(), aWinSize.y(),
|
||||
theToIncludeAuxiliary);
|
||||
/*std::cout << "Identification: " << Identification() << std::endl;
|
||||
std::cout << "aWinSize: " << aWinSize.x() << " " << aWinSize.y() << std::endl;
|
||||
std::cout << "theToIncludeAuxiliary: " << (theToIncludeAuxiliary ? "true" : "false") << std::endl;
|
||||
std::cout << "ProjectionMatrix: " << std::endl;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
std::cout << aCamera->ProjectionMatrix().GetValue(i, j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "OrientationMatrix: " << std::endl;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
for (int j = 0; j < 4; j++)
|
||||
{
|
||||
std::cout << aCamera->OrientationMatrix().GetValue(i, j) << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
std::cout << std::endl;*/
|
||||
|
||||
if (aBox.IsVoid())
|
||||
{
|
||||
//std::cout << "add void box" << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
//std::cout << "add NOT void box" << std::endl;
|
||||
}
|
||||
aResult.Add (aBox);
|
||||
}
|
||||
return aResult;
|
||||
|
@ -505,6 +505,12 @@ void Graphic3d_Camera::SetZRange (const Standard_Real theZNear,
|
||||
return;
|
||||
}
|
||||
|
||||
if (theZFar != 3000)
|
||||
{
|
||||
//std::cout << "SetZRange: " << theZNear << " " << theZFar << std::endl;
|
||||
}
|
||||
//std::cout << "SetZRange: " << theZNear << " " << theZFar << std::endl;
|
||||
|
||||
myZNear = theZNear;
|
||||
myZFar = theZFar;
|
||||
|
||||
|
@ -2198,12 +2198,12 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
|
||||
aUniforms.Append (Graphic3d_ShaderObject::ShaderVariable ("bool uIsDrawAxis", Graphic3d_TOS_FRAGMENT));
|
||||
|
||||
TCollection_AsciiString aSrcVert = TCollection_AsciiString()
|
||||
+ EOL"vec3 gridPlane[6] = vec3[] (vec3( 1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0),"
|
||||
EOL" vec3(-1, -1, 0), vec3( 1, 1, 0), vec3( 1, -1, 0));"
|
||||
+ EOL"vec3 gridPlane[6] = vec3[] (vec3( 1.0, 1.0, 0.0), vec3(-1.0, -1.0, 0.0), vec3(-1.0, 1.0, 0.0),"
|
||||
EOL" vec3(-1.0, -1.0, 0.0), vec3( 1.0, 1.0, 0.0), vec3( 1.0, -1.0, 0.0));"
|
||||
|
||||
EOL"vec3 UnprojectPoint (float aX, float anY, float aZ)"
|
||||
EOL"{"
|
||||
EOL" vec4 anUnprojPnt = occModelWorldMatrixInverse * occWorldViewMatrixInverse * occProjectionMatrixInverse * vec4 (aX, anY, aZ, 1.0);"
|
||||
EOL" vec4 anUnprojPnt = occWorldViewMatrixInverse * occProjectionMatrixInverse * vec4 (aX, anY, aZ, 1.0);"
|
||||
EOL" return anUnprojPnt.xyz / anUnprojPnt.w;"
|
||||
EOL"}"
|
||||
|
||||
@ -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)"
|
||||
EOL"{"
|
||||
EOL" vec2 aCoord = theFragPos3D.xy * theScale;"
|
||||
EOL" vec2 aDerivative = fwidth (aCoord);"
|
||||
@ -2257,8 +2257,9 @@ Handle(Graphic3d_ShaderProgram) Graphic3d_ShaderManager::getGridProgram() const
|
||||
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), aScale * 0.1, true);"
|
||||
EOL" vec4 aBigGridColor = grid (aFragPos3D, vec3 (0.8), aScaleBig, true);"
|
||||
//EOL" vec4 aColor = aBigGridColor;"
|
||||
EOL" vec4 aColor = aBigGridColor.a == 0.0"
|
||||
EOL" ? grid (aFragPos3D, vec3 (0.2), aScale, false)"
|
||||
@ -2277,19 +2278,7 @@ 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" aColor = mix (aColor, aBackgroundColor, 0.99);"
|
||||
EOL" }"
|
||||
|
||||
/*EOL" if (aLinearDepth < -1.0)"
|
||||
|
@ -232,7 +232,7 @@ public:
|
||||
{
|
||||
prepareGridProgram();
|
||||
}
|
||||
return myContext->BindProgram (myGridProgram);
|
||||
return bindProgramWithState (myGridProgram, Graphic3d_TypeOfShadingModel_Unlit);
|
||||
}
|
||||
|
||||
//! Generates shader program to render environment cubemap as background.
|
||||
|
@ -2604,19 +2604,59 @@ void OpenGl_View::renderGrid()
|
||||
{
|
||||
const Handle(OpenGl_Context)& aContext = myWorkspace->GetGlContext();
|
||||
|
||||
aContext->ShaderManager()->UpdateModelWorldStateTo (aContext->ModelWorldState.Current());
|
||||
/*aContext->ShaderManager()->UpdateModelWorldStateTo (aContext->ModelWorldState.Current());
|
||||
aContext->ShaderManager()->UpdateProjectionStateTo (aContext->ProjectionState.Current());
|
||||
aContext->ShaderManager()->UpdateWorldViewStateTo (aContext->WorldViewState.Current());
|
||||
aContext->ShaderManager()->UpdateWorldViewStateTo (aContext->WorldViewState.Current());*/
|
||||
|
||||
if (MinMaxValues (Standard_True).IsVoid())
|
||||
{
|
||||
Bnd_Box aDummy;
|
||||
aDummy.Set (gp::Origin());
|
||||
aContext->Camera()->ZFitAll (1.0, aDummy, aDummy);
|
||||
}
|
||||
|
||||
Standard_Real aZNear = aContext->Camera()->ZNear();
|
||||
Standard_Real aZFar = aContext->Camera()->ZFar();
|
||||
|
||||
aContext->Camera()->SetZRange (aZNear, Max (aZNear * 1.001, aZFar));
|
||||
|
||||
aContext->ProjectionState.SetCurrent (aContext->Camera()->ProjectionMatrixF());
|
||||
|
||||
aContext->ApplyProjectionMatrix();
|
||||
aContext->ApplyWorldViewMatrix();
|
||||
|
||||
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;
|
||||
Graphic3d_Vec3 gridPlane[4] = { Graphic3d_Vec3 (1.0, 1.0, 0.0), Graphic3d_Vec3(-1.0, 1.0, 0.0),
|
||||
Graphic3d_Vec3(-1.0, -1.0, 0.0), Graphic3d_Vec3 (1.0, -1.0, 0.0) };
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
if (!aContext->WorldViewState.Current().Inverted().IsEqual (aContext->ShaderManager()->WorldViewState().WorldViewMatrixInverse()))
|
||||
{
|
||||
std::cout << "WorldViewState not equal" << std::endl;
|
||||
}
|
||||
if (!aContext->ProjectionState.Current().Inverted().IsEqual (aContext->ShaderManager()->ProjectionState().ProjectionMatrixInverse()))
|
||||
{
|
||||
std::cout << "ProjectionState not equal" << std::endl;
|
||||
}
|
||||
Graphic3d_Vec4 aNearPntVar = aContext->ShaderManager()->WorldViewState().WorldViewMatrixInverse() * aContext->ShaderManager()->ProjectionState().ProjectionMatrixInverse()
|
||||
* Graphic3d_Vec4 (gridPlane[i].x(), gridPlane[i].y(), 0.0, 1.0);
|
||||
Graphic3d_Vec3 aNearPnt = aNearPntVar.xyz() / aNearPntVar.w();
|
||||
Graphic3d_Vec4 aFarPntVar = aContext->WorldViewState.Current().Inverted() * aContext->ProjectionState.Current().Inverted()
|
||||
* Graphic3d_Vec4 (gridPlane[i].x(), gridPlane[i].y(), 1.0, 1.0);
|
||||
Graphic3d_Vec3 aFarPnt = aFarPntVar.xyz() / aFarPntVar.w();
|
||||
float aParam = -aNearPnt.z() / (aFarPnt.z() - aNearPnt.z());
|
||||
Graphic3d_Vec3 aFragPos3D = aNearPnt + (aFarPnt - aNearPnt).Multiplied (aParam);
|
||||
|
||||
//std::cout << aFragPos3D.x() << " " << aFragPos3D.y() << " " << aFragPos3D.z() << std::endl;
|
||||
}
|
||||
|
||||
//std::cout << "ZNear: " << aContext->Camera()->ZNear() << std::endl;
|
||||
//std::cout << "ZFar : " << aContext->Camera()->ZFar() << std::endl;
|
||||
|
||||
//Standard_Integer aScale = TCollection_AsciiString(RealToInt(aContext->Camera()->Scale())).Length();
|
||||
|
||||
@ -2632,7 +2672,9 @@ void OpenGl_View::renderGrid()
|
||||
int k = (int)(log10 (aContext->Camera()->Scale()) / log10(2));
|
||||
|
||||
Standard_Integer aScale = k;
|
||||
std::cout << "Scale: " << aScale << std::endl;
|
||||
//std::cout << "Scale: " << aScale << std::endl;
|
||||
|
||||
//aContext->Camera()->SetZRange (aContext->Camera()->ZNear(), aContext->Camera()->ZFar() + 1.0);
|
||||
|
||||
if (aContext->ShaderManager()->BindGridProgram())
|
||||
{
|
||||
@ -2643,10 +2685,11 @@ void OpenGl_View::renderGrid()
|
||||
// TODO : add param to draw command
|
||||
aProg->SetUniform (aContext, "uIsDrawAxis", GLboolean (true));
|
||||
|
||||
aContext->ShaderManager()->PushState (aContext->ActiveProgram());
|
||||
aContext->core20fwd->glDrawArrays (GL_TRIANGLES, 0, 6);
|
||||
aContext->BindProgram (NULL);
|
||||
}
|
||||
|
||||
aContext->Camera()->SetZRange (aZNear, aZFar);
|
||||
}
|
||||
|
||||
// =======================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user