mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +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:
@@ -77,3 +77,4 @@ const int OccEquationCoords_World = 1; //!< world-space clipping plane
|
||||
//! Parameters of clipping planes
|
||||
uniform vec4 occClipPlaneEquations[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
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
varying vec3 View; //!< Direction to the viewer
|
||||
varying vec3 Normal; //!< Vertex normal in view space
|
||||
varying vec4 Position; //!< Vertex position in view space.
|
||||
varying vec3 View; //!< Direction to the viewer
|
||||
varying vec3 Normal; //!< Vertex normal 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 Diffuse; //!< Diffuse contribution of light sources
|
||||
@@ -172,6 +173,27 @@ vec4 computeLighting (in vec3 theNormal,
|
||||
//! Entry point to the Fragment Shader
|
||||
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),
|
||||
normalize (View),
|
||||
Position);
|
||||
|
@@ -13,9 +13,10 @@
|
||||
// Alternatively, this file may be used under the terms of Open CASCADE
|
||||
// commercial license or contractual agreement.
|
||||
|
||||
varying vec3 View; //!< Direction to the viewer
|
||||
varying vec3 Normal; //!< Vertex normal in view space
|
||||
varying vec4 Position; //!< Vertex position in view space
|
||||
varying vec3 View; //!< Direction to the viewer
|
||||
varying vec3 Normal; //!< Vertex normal 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
|
||||
vec3 TransformNormal (in vec3 theNormal)
|
||||
@@ -29,8 +30,9 @@ vec3 TransformNormal (in vec3 theNormal)
|
||||
//! Entry point to the Vertex Shader
|
||||
void main()
|
||||
{
|
||||
Position = occWorldViewMatrix * occModelWorldMatrix * occVertex; // position in the view space
|
||||
Normal = TransformNormal (occNormal); // normal in the view space
|
||||
PositionWorld = occModelWorldMatrix * occVertex;
|
||||
Position = occWorldViewMatrix * PositionWorld;
|
||||
Normal = TransformNormal (occNormal);
|
||||
|
||||
// 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.
|
||||
|
Reference in New Issue
Block a user