Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for OCCT 7.6.2 #971

Merged
merged 6 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
215 changes: 215 additions & 0 deletions TIGLViewer/shaders/PhongShading-v7.6.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
// Created on: 2013-10-10
// Created by: Denis BOGOLEPOV
// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// 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 vec4 PositionWorld; //!< Vertex position in world space
varying vec4 uv; //!< Vertex uv coordinate

uniform bool enableZebra; //!< Whether the zebra stripe mode is enabled

vec3 Ambient; //!< Ambient contribution of light sources
vec3 Diffuse; //!< Diffuse contribution of light sources
vec3 Specular; //!< Specular contribution of light sources

//! Computes contribution of isotropic point light source
void pointLight (in int theId,
in vec3 theNormal,
in vec3 theView,
in vec3 thePoint)
{
vec3 aLight = occLight_Position (theId).xyz;
if (!occLight_IsHeadlight (theId))
{
aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 1.0));
}
aLight -= thePoint;

float aDist = length (aLight);
aLight = aLight * (1.0 / aDist);

float anAtten = 1.0 / (occLight_ConstAttenuation (theId)
+ occLight_LinearAttenuation (theId) * aDist);

vec3 aHalf = normalize (aLight + theView);

vec3 aFaceSideNormal = gl_FrontFacing ? theNormal : -theNormal;
float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));

float aSpecl = 0.0;
if (aNdotL > 0.0)
{
aSpecl = pow (aNdotH, occMaterial_Shininess (gl_FrontFacing));
}

Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
Specular += occLight_Specular (theId).rgb * aSpecl * anAtten;
}

//! Computes contribution of spotlight source
void spotLight (in int theId,
in vec3 theNormal,
in vec3 theView,
in vec3 thePoint)
{
vec3 aLight = occLight_Position (theId).xyz;
vec3 aSpotDir = occLight_SpotDirection (theId).xyz;
if (!occLight_IsHeadlight (theId))
{
aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 1.0));
aSpotDir = vec3 (occWorldViewMatrix * vec4 (aSpotDir, 0.0));
}
aLight -= thePoint;

float aDist = length (aLight);
aLight = aLight * (1.0 / aDist);

aSpotDir = normalize (aSpotDir);

// light cone
float aCosA = dot (aSpotDir, -aLight);
if (aCosA >= 1.0 || aCosA < cos (occLight_SpotCutOff (theId)))
{
return;
}

float anExponent = occLight_SpotExponent (theId);
float anAtten = 1.0 / (occLight_ConstAttenuation (theId)
+ occLight_LinearAttenuation (theId) * aDist);
if (anExponent > 0.0)
{
anAtten *= pow (aCosA, anExponent * 128.0);
}

vec3 aHalf = normalize (aLight + theView);

vec3 aFaceSideNormal = gl_FrontFacing ? theNormal : -theNormal;
float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));

float aSpecl = 0.0;
if (aNdotL > 0.0)
{
aSpecl = pow (aNdotH, occMaterial_Shininess (gl_FrontFacing));
}

Diffuse += occLight_Diffuse (theId).rgb * aNdotL * anAtten;
Specular += occLight_Specular (theId).rgb * aSpecl * anAtten;
}

//! Computes contribution of directional light source
void directionalLight (in int theId,
in vec3 theNormal,
in vec3 theView)
{
vec3 aLight = normalize (occLight_Position (theId).xyz);
if (!occLight_IsHeadlight (theId))
{
aLight = vec3 (occWorldViewMatrix * vec4 (aLight, 0.0));
}

vec3 aHalf = normalize (aLight + theView);

vec3 aFaceSideNormal = gl_FrontFacing ? theNormal : -theNormal;
float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));

float aSpecl = 0.0;
if (aNdotL > 0.0)
{
aSpecl = pow (aNdotH, occMaterial_Shininess (gl_FrontFacing));
}

Diffuse += occLight_Diffuse (theId).rgb * aNdotL;
Specular += occLight_Specular (theId).rgb * aSpecl;
}

//! Computes illumination from light sources
vec4 computeLighting (in vec3 theNormal,
in vec3 theView,
in vec4 thePoint)
{
// Clear the light intensity accumulators
Ambient = occLightAmbient.rgb;
Diffuse = vec3 (0.0);
Specular = vec3 (0.0);
vec3 aPoint = thePoint.xyz / thePoint.w;
for (int anIndex = 0; anIndex < occLightSourcesCount; ++anIndex)
{
int aType = occLight_Type (anIndex);
if (aType == OccLightType_Direct)
{
directionalLight (anIndex, theNormal, theView);
}
else if (aType == OccLightType_Point)
{
pointLight (anIndex, theNormal, theView, aPoint);
}
else if (aType == OccLightType_Spot)
{
spotLight (anIndex, theNormal, theView, aPoint);
}
}

vec3 aMatAmbient = occMaterial_Ambient (gl_FrontFacing);
vec4 aMatDiffuse = occMaterial_Diffuse (gl_FrontFacing);
vec3 aMatSpecular = occMaterial_Specular(gl_FrontFacing);
vec3 aMatEmission = occMaterial_Emission(gl_FrontFacing);
vec3 aColor = Ambient * aMatAmbient.rgb
+ Diffuse * aMatDiffuse.rgb
+ Specular * aMatSpecular.rgb
+ aMatEmission.rgb;

float attenuation = 1.0;
if (enableZebra)
{
vec3 v = vec3(0., 0., -1.);

// Direction of the view reflected on the surface
vec3 vReflect = 2. * (dot(theNormal, v)*theNormal - v);

// normal vector of the light stripe plane
vec3 lightDir = normalize(vec3(0., 1., 0.));

// View projected into light plane
vec3 vProj = normalize(v - dot(v, lightDir)*lightDir);

// x-position of the reflected view on the light plane
float posLightPlane = dot(vReflect, vProj);

attenuation = max(min(2.0, sin(posLightPlane*30.0)*3. + 2.0), -1.0);
}

return vec4 (aColor, aMatDiffuse.a) * vec4(attenuation, attenuation, attenuation, 1.0);
}

//! Entry point to the Fragment Shader
void main()
{
// process clipping planes
for (int anIndex = 0; anIndex < occClipPlaneCount; ++anIndex)
{
vec4 aClipEquation = occClipPlaneEquations[anIndex];
if (dot (aClipEquation.xyz, PositionWorld.xyz / PositionWorld.w) + aClipEquation.w < 0.0)
{
discard;
}
}

vec4 aColor = computeLighting (normalize (Normal), normalize (View), Position);
occSetFragColor (aColor);
}
45 changes: 45 additions & 0 deletions TIGLViewer/shaders/PhongShading-v7.6.vs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Created on: 2013-10-10
// Created by: Denis BOGOLEPOV
// Copyright (c) 2013-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// 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 vec4 PositionWorld; //!< Vertex position in world space
varying vec4 uv; //!< Vertex uv coordinates

//! Computes the normal in view space
vec3 TransformNormal (in vec3 theNormal)
{
vec4 aResult = occWorldViewMatrixInverseTranspose
* occModelWorldMatrixInverseTranspose
* vec4 (theNormal, 0.0);
return normalize (aResult.xyz);
}

//! Entry point to the Vertex Shader
void main()
{
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.
View = vec3 (0.0, 0.0, 1.0);

// Do fixed functionality vertex transform
gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
uv = occTexCoord;
}
1 change: 1 addition & 0 deletions TIGLViewer/src/ISession_Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ IMPLEMENT_STANDARD_RTTIEXT(ISession_Text,AIS_InteractiveObject)
#include <SelectMgr_Selection.hxx>
#include <Prs3d_Text.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_Root.hxx>
#include <PrsMgr_PresentationManager3d.hxx>
#include <gp_Pnt.hxx>
#include <TCollection_ExtendedString.hxx>
Expand Down
52 changes: 22 additions & 30 deletions TIGLViewer/src/TIGLAISTriangulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ TIGLAISTriangulation::TIGLAISTriangulation(const Handle(Poly_Triangulation)& Tri
maxy = DBL_MIN;
maxz = DBL_MIN;

const TColgp_Array1OfPnt& nodes = Triangulation->Nodes();
for (int i = nodes.Lower(); i <= nodes.Upper(); ++i) {
const gp_Pnt& p = nodes.Value(i);
for (int i = 1; i <= Triangulation->NbNodes(); ++i) {
const gp_Pnt& p = Triangulation->Node(i);
minx = min(minx, p.X());
miny = min(miny, p.Y());
minz = min(minz, p.Z());
Expand Down Expand Up @@ -108,9 +107,6 @@ void TIGLAISTriangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& a
Standard_Real ambient = 1.0;
#endif

const TColgp_Array1OfPnt& nodes = myTriangulation->Nodes(); //Nodes
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles(); //Triangle

Standard_Boolean hasVNormals = myTriangulation->HasNormals();
Standard_Boolean hasVColors = (myFlagColor == 1);

Expand All @@ -122,47 +118,45 @@ void TIGLAISTriangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& a
Standard_False //hasTexels
);

Standard_Integer i;
Standard_Integer j;

if (hasVNormals) {
const TShort_Array1OfShortReal& normals = myTriangulation->Normals();
if (hasVColors) {
const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) {
j = (i - nodes.Lower()) * 3;
anArray->AddVertex(nodes(i), AttenuateColor(colors(i), ambient));
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
for (int i = 1; i <= myTriangulation->NbNodes(); i++ ) {
anArray->AddVertex(myTriangulation->Node(i), AttenuateColor(colors(i), ambient));
auto aNormal = myTriangulation->Normal(i);
anArray->SetVertexNormal(i, aNormal.X(), aNormal.Y(), aNormal.Z());
}
}
// !hasVColors
else {
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) {
j = (i - nodes.Lower()) * 3;
anArray->AddVertex(nodes(i));
anArray->SetVertexNormal(i, normals(j+1), normals(j+2), normals(j+3));
for (int i = 1; i <= myTriangulation->NbNodes(); i++ ) {
anArray->AddVertex(myTriangulation->Node(i));
auto aNormal = myTriangulation->Normal(i);
anArray->SetVertexNormal(i, aNormal.X(), aNormal.Y(), aNormal.Z());

}
}
}
// !hasVNormals
else {
if (hasVColors) {
const TColStd_Array1OfInteger& colors = myColor->Array1();
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) {
anArray->AddVertex(nodes(i), AttenuateColor(colors(i), ambient));
for (int i = 1; i <= myTriangulation->NbNodes(); i++ ) {
anArray->AddVertex(myTriangulation->Node(i), AttenuateColor(colors(i), ambient));
}
}
// !hasVColors
else {
for ( i = nodes.Lower(); i <= nodes.Upper(); i++ ) {
anArray->AddVertex(nodes(i));
for (int i = 1; i <= myTriangulation->NbNodes(); i++ ) {
anArray->AddVertex(myTriangulation->Node(i));
}
}
}

Standard_Integer indexTriangle[3] = {0,0,0};
for ( i = triangles.Lower(); i<= triangles.Upper(); i++ ) {
triangles(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
for (Standard_Integer i = 1; i<= myTriangulation->NbTriangles(); i++ ) {
myTriangulation->Triangle(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
anArray->AddEdge(indexTriangle[0]);
anArray->AddEdge(indexTriangle[1]);
anArray->AddEdge(indexTriangle[2]);
Expand All @@ -172,18 +166,16 @@ void TIGLAISTriangulation::Compute(const Handle(PrsMgr_PresentationManager3d)& a
break;
}
case 0: {
const TColgp_Array1OfPnt& nodes = myTriangulation->Nodes();
const Poly_Array1OfTriangle& triangles = myTriangulation->Triangles();
Handle(Graphic3d_AspectLine3d) aspect = myDrawer->WireAspect()->Aspect();

Handle(Graphic3d_ArrayOfPrimitives) segments = new Graphic3d_ArrayOfSegments(nodes.Length(),triangles.Length()*6);
for (Standard_Integer i = nodes.Lower(); i <= nodes.Upper(); i++ ) {
segments->AddVertex(nodes(i));
Handle(Graphic3d_ArrayOfPrimitives) segments = new Graphic3d_ArrayOfSegments(myTriangulation->NbNodes(),myTriangulation->NbTriangles()*6);
for (Standard_Integer i = 1; i <= myTriangulation->NbNodes(); i++ ) {
segments->AddVertex(myTriangulation->Node(i));
}

Standard_Integer indexTriangle[3] = {0,0,0};
for (Standard_Integer i = triangles.Lower(); i<= triangles.Upper(); i++ ) {
triangles(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
for (Standard_Integer i = 1; i<= myTriangulation->NbTriangles(); i++ ) {
myTriangulation->Triangle(i).Get(indexTriangle[0], indexTriangle[1], indexTriangle[2]);
segments->AddEdge(indexTriangle[0]);
segments->AddEdge(indexTriangle[1]);
segments->AddEdge(indexTriangle[1]);
Expand Down
4 changes: 4 additions & 0 deletions TIGLViewer/src/TIGLQAspectWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ void TIGLQAspectWindow::Unmap() const
// function : DoResize
// purpose :
// =======================================================================
#if OCC_VERSION_HEX >= 0x070600
Aspect_TypeOfResize TIGLQAspectWindow::DoResize()
#else
Aspect_TypeOfResize TIGLQAspectWindow::DoResize() const
#endif
{
int aMask = 0;
Aspect_TypeOfResize aMode = Aspect_TOR_UNKNOWN;
Expand Down
Loading