mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-07 18:30:55 +03:00
0024402: TKOpenGl - Implement clipping planes in Phong GLSL program
Limit number of lights (breaks compatibility with old hardware).
This commit is contained in:
parent
816d03eef3
commit
5495fa7e65
@ -509,7 +509,7 @@ void OpenGl_ShaderManager::PushClippingState (const Handle(OpenGl_ShaderProgram)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint aPlanesNb = 0;
|
GLint aPlanesNb = 0;
|
||||||
for (Graphic3d_SequenceOfHClipPlane::Iterator anIter (myContext->Clipping().Planes());
|
for (Graphic3d_SequenceOfHClipPlane::Iterator anIter (myContext->Clipping().Planes());
|
||||||
anIter.More(); anIter.Next())
|
anIter.More(); anIter.Next())
|
||||||
{
|
{
|
||||||
@ -526,8 +526,9 @@ void OpenGl_ShaderManager::PushClippingState (const Handle(OpenGl_ShaderProgram)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
OpenGl_Vec4* anEquations = new OpenGl_Vec4[aPlanesNb];
|
const Standard_Size MAX_CLIP_PLANES = 8;
|
||||||
GLint* aSpaces = new GLint [aPlanesNb];
|
OpenGl_Vec4* anEquations = new OpenGl_Vec4[MAX_CLIP_PLANES];
|
||||||
|
GLint* aSpaces = new GLint [MAX_CLIP_PLANES];
|
||||||
GLuint aPlaneId = 0;
|
GLuint aPlaneId = 0;
|
||||||
for (Graphic3d_SequenceOfHClipPlane::Iterator anIter (myContext->Clipping().Planes());
|
for (Graphic3d_SequenceOfHClipPlane::Iterator anIter (myContext->Clipping().Planes());
|
||||||
anIter.More(); anIter.Next())
|
anIter.More(); anIter.Next())
|
||||||
@ -546,8 +547,12 @@ void OpenGl_ShaderManager::PushClippingState (const Handle(OpenGl_ShaderProgram)
|
|||||||
aSpaces[aPlaneId] = myContext->Clipping().GetEquationSpace (aPlane);
|
aSpaces[aPlaneId] = myContext->Clipping().GetEquationSpace (aPlane);
|
||||||
++aPlaneId;
|
++aPlaneId;
|
||||||
}
|
}
|
||||||
theProgram->SetUniform (myContext, aLocEquations, aPlanesNb, anEquations[0].GetData());
|
|
||||||
theProgram->SetUniform (myContext, aLocSpaces, aPlanesNb, aSpaces);
|
theProgram->SetUniform (myContext,
|
||||||
|
theProgram->GetStateLocation (OpenGl_OCC_CLIP_PLANE_COUNT),
|
||||||
|
aPlanesNb);
|
||||||
|
theProgram->SetUniform (myContext, aLocEquations, MAX_CLIP_PLANES, anEquations);
|
||||||
|
theProgram->SetUniform (myContext, aLocSpaces, MAX_CLIP_PLANES, aSpaces);
|
||||||
|
|
||||||
delete[] anEquations;
|
delete[] anEquations;
|
||||||
delete[] aSpaces;
|
delete[] aSpaces;
|
||||||
|
@ -47,6 +47,7 @@ Standard_CString OpenGl_ShaderProgram::PredefinedKeywords[] =
|
|||||||
|
|
||||||
"occClipPlaneEquations", // OpenGl_OCC_CLIP_PLANE_EQUATIONS
|
"occClipPlaneEquations", // OpenGl_OCC_CLIP_PLANE_EQUATIONS
|
||||||
"occClipPlaneSpaces", // OpenGl_OCC_CLIP_PLANE_SPACES
|
"occClipPlaneSpaces", // OpenGl_OCC_CLIP_PLANE_SPACES
|
||||||
|
"occClipPlaneCount", // OpenGl_OCC_CLIP_PLANE_COUNT
|
||||||
|
|
||||||
"occLightSourcesCount", // OpenGl_OCC_LIGHT_SOURCE_COUNT
|
"occLightSourcesCount", // OpenGl_OCC_LIGHT_SOURCE_COUNT
|
||||||
"occLightSourcesTypes", // OpenGl_OCC_LIGHT_SOURCE_TYPES
|
"occLightSourcesTypes", // OpenGl_OCC_LIGHT_SOURCE_TYPES
|
||||||
|
@ -50,6 +50,7 @@ enum OpenGl_StateVariable
|
|||||||
// OpenGL clip planes state
|
// OpenGL clip planes state
|
||||||
OpenGl_OCC_CLIP_PLANE_EQUATIONS,
|
OpenGl_OCC_CLIP_PLANE_EQUATIONS,
|
||||||
OpenGl_OCC_CLIP_PLANE_SPACES,
|
OpenGl_OCC_CLIP_PLANE_SPACES,
|
||||||
|
OpenGl_OCC_CLIP_PLANE_COUNT,
|
||||||
|
|
||||||
// OpenGL light state
|
// OpenGL light state
|
||||||
OpenGl_OCC_LIGHT_SOURCE_COUNT,
|
OpenGl_OCC_LIGHT_SOURCE_COUNT,
|
||||||
|
@ -77,3 +77,4 @@ const int OccEquationCoords_World = 1; //!< world-space clipping plane
|
|||||||
//! Parameters of clipping planes
|
//! Parameters of clipping planes
|
||||||
uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
|
uniform vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
|
||||||
uniform int occClipPlaneSpaces [THE_MAX_CLIP_PLANES];
|
uniform int occClipPlaneSpaces [THE_MAX_CLIP_PLANES];
|
||||||
|
uniform int occClipPlaneCount; //!< Total number of clip planes
|
||||||
|
@ -13,9 +13,10 @@
|
|||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
varying vec3 View; //!< Direction to the viewer
|
varying vec3 View; //!< Direction to the viewer
|
||||||
varying vec3 Normal; //!< Vertex normal in view space
|
varying vec3 Normal; //!< Vertex normal in view space
|
||||||
varying vec4 Position; //!< Vertex position in view space.
|
varying vec4 Position; //!< Vertex position in view space.
|
||||||
|
varying vec4 PositionWorld; //!< Vertex position in world space
|
||||||
|
|
||||||
vec3 Ambient; //!< Ambient contribution of light sources
|
vec3 Ambient; //!< Ambient contribution of light sources
|
||||||
vec3 Diffuse; //!< Diffuse contribution of light sources
|
vec3 Diffuse; //!< Diffuse contribution of light sources
|
||||||
@ -172,6 +173,27 @@ vec4 computeLighting (in vec3 theNormal,
|
|||||||
//! Entry point to the Fragment Shader
|
//! Entry point to the Fragment Shader
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
// process clipping planes
|
||||||
|
for (int anIndex = 0; anIndex < occClipPlaneCount; ++anIndex)
|
||||||
|
{
|
||||||
|
vec4 aClipEquation = occClipPlaneEquations[anIndex];
|
||||||
|
int aClipSpace = occClipPlaneSpaces[anIndex];
|
||||||
|
if (aClipSpace == OccEquationCoords_World)
|
||||||
|
{
|
||||||
|
if (dot (aClipEquation.xyz, PositionWorld.xyz) + aClipEquation.w < 0.0)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (aClipSpace == OccEquationCoords_View)
|
||||||
|
{
|
||||||
|
if (dot (aClipEquation.xyz, Position.xyz) + aClipEquation.w < 0.0)
|
||||||
|
{
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gl_FragColor = computeLighting (normalize (Normal),
|
gl_FragColor = computeLighting (normalize (Normal),
|
||||||
normalize (View),
|
normalize (View),
|
||||||
Position);
|
Position);
|
||||||
|
@ -13,9 +13,10 @@
|
|||||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||||
// commercial license or contractual agreement.
|
// commercial license or contractual agreement.
|
||||||
|
|
||||||
varying vec3 View; //!< Direction to the viewer
|
varying vec3 View; //!< Direction to the viewer
|
||||||
varying vec3 Normal; //!< Vertex normal in view space
|
varying vec3 Normal; //!< Vertex normal in view space
|
||||||
varying vec4 Position; //!< Vertex position in view space
|
varying vec4 Position; //!< Vertex position in view space
|
||||||
|
varying vec4 PositionWorld; //!< Vertex position in world space
|
||||||
|
|
||||||
//! Computes the normal in view space
|
//! Computes the normal in view space
|
||||||
vec3 TransformNormal (in vec3 theNormal)
|
vec3 TransformNormal (in vec3 theNormal)
|
||||||
@ -29,8 +30,9 @@ vec3 TransformNormal (in vec3 theNormal)
|
|||||||
//! Entry point to the Vertex Shader
|
//! Entry point to the Vertex Shader
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
Position = occWorldViewMatrix * occModelWorldMatrix * occVertex; // position in the view space
|
PositionWorld = occModelWorldMatrix * occVertex;
|
||||||
Normal = TransformNormal (occNormal); // normal in the view space
|
Position = occWorldViewMatrix * PositionWorld;
|
||||||
|
Normal = TransformNormal (occNormal);
|
||||||
|
|
||||||
// Note: The specified view vector is absolutely correct only for the orthogonal projection.
|
// Note: The specified view vector is absolutely correct only for the orthogonal projection.
|
||||||
// For perspective projection it will be approximate, but it is in good agreement with the OpenGL calculations.
|
// For perspective projection it will be approximate, but it is in good agreement with the OpenGL calculations.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user