OCCT on OSX. OpenGL warnings.

Good day. 

I ported the application from Linux to osx and now I get the following text in stdout. Apparently at the moment when opencascade is working out for the first time.
In this case, the program works fine, apart from this message .. What could it be?

MacBook-User:tools user$ zencad
TKOpenGl | Type: Error | ID: 0 | Severity: High | Message:
  #extension GL_EXT_gpu_shader4 : enable
// Enable extensions used in OCCT GLSL programs
#define FRAGMENT_SHADER
#define THE_MAX_LIGHTS 0
#define THE_MAX_CLIP_PLANES 0
#define THE_NB_FRAG_OUTPUTS 1
// 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.

//! @file Declarations.glsl
//! This files includes definition of common uniform variables in OCCT GLSL programs

//! @def THE_MAX_LIGHTS
//! Specifies the length of array of lights, which is 8 by default. Defined by Shader Manager.
// #define THE_MAX_LIGHTS 8

//! @def THE_MAX_CLIP_PLANES
//! Specifies the length of array of clipping planes, which is 8 by default. Defined by Shader Manager.
// #define THE_MAX_CLIP_PLANES 8

//! @def THE_NB_FRAG_OUTPUTS
//! Specifies the length of array of Fragment Shader outputs, which is 1 by default. Defined by Shader Manager.
// #define THE_NB_FRAG_OUTPUTS 1

// compatibility macros
#if (__VERSION__ >= 130)
  #define THE_ATTRIBUTE  in
  #define THE_SHADER_IN  in
  #define THE_SHADER_OUT out
  #define THE_OUT        out
  #define occTexture1D   texture
  #define occTexture2D   texture
  #define occTexture3D   texture
#else
  #define THE_ATTRIBUTE  attribute
  #define THE_SHADER_IN  varying
  #define THE_SHADER_OUT varying
  #define THE_OUT
  #define occTexture1D   texture1D
  #define occTexture2D   texture2D
  #define occTexture3D   texture3D
#endif

#ifdef GL_ES
  #define THE_PREC_ENUM lowp // enumerations should fit into lowp range
#else
  #define THE_PREC_ENUM
#endif

// Vertex attributes
#ifdef VERTEX_SHADER
  THE_ATTRIBUTE vec4 occVertex;
  THE_ATTRIBUTE vec3 occNormal;
  THE_ATTRIBUTE vec4 occTexCoord;
  THE_ATTRIBUTE vec4 occVertColor;
#elif defined(FRAGMENT_SHADER)
  #if (__VERSION__ >= 130)
    #ifdef OCC_ENABLE_draw_buffers
      out vec4 occFragColorArray[THE_NB_FRAG_OUTPUTS];
      #define occFragColorArrayAlias occFragColorArray
      #define occFragColor0 occFragColorArray[0]
    #else
      out vec4 occFragColor0;
    #endif
  #else
    #ifdef OCC_ENABLE_draw_buffers
      #define occFragColorArrayAlias gl_FragData
      #define occFragColor0 gl_FragData[0]
    #else
      #define occFragColor0 gl_FragColor
    #endif
  #endif

  #if (THE_NB_FRAG_OUTPUTS >= 2)
    #define occFragColor1 occFragColorArrayAlias[1]
  #else
    vec4 occFragColor1;
  #endif
  #if (THE_NB_FRAG_OUTPUTS >= 3)
    #define occFragColor2 occFragColorArrayAlias[2]
  #else
    vec4 occFragColor2;
  #endif
  #if (THE_NB_FRAG_OUTPUTS >= 4)
    #define occFragColor3 occFragColorArrayAlias[3]
  #else
    vec4 occFragColor3;
  #endif

  // Built-in outputs notation
  #define occFragColor    occFragColor0
  #define occFragCoverage occFragColor1

  //! Define the main Fragment Shader output - color value.
  void occSetFragColor (in vec4 theColor);
#endif

// Matrix state
uniform mat4 occWorldViewMatrix;  //!< World-view  matrix
uniform mat4 occProjectionMatrix; //!< Projection  matrix
uniform mat4 occModelWorldMatrix; //!< Model-world matrix

uniform mat4 occWorldViewMatrixInverse;    //!< Inverse of the world-view  matrix
uniform mat4 occProjectionMatrixInverse;   //!< Inverse of the projection  matrix
uniform mat4 occModelWorldMatrixInverse;   //!< Inverse of the model-world matrix

uniform mat4 occWorldViewMatrixTranspose;  //!< Transpose of the world-view  matrix
uniform mat4 occProjectionMatrixTranspose; //!< Transpose of the projection  matrix
uniform mat4 occModelWorldMatrixTranspose; //!< Transpose of the model-world matrix

uniform mat4 occWorldViewMatrixInverseTranspose;  //!< Transpose of the inverse of the world-view  matrix
uniform mat4 occProjectionMatrixInverseTranspose; //!< Transpose of the inverse of the projection  matrix
uniform mat4 occModelWorldMatrixInverseTranspose; //!< Transpose of the inverse of the model-world matrix

// light type enumeration
const int OccLightType_Direct = 1; //!< directional     light source
const int OccLightType_Point  = 2; //!< isotropic point light source
const int OccLightType_Spot   = 3; //!< spot            light source

// Light sources
uniform               vec4 occLightAmbient;      //!< Cumulative ambient color
#if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
uniform THE_PREC_ENUM int  occLightSourcesCount; //!< Total number of light sources
int   occLight_Type              (in int theId); //!< Type of light source
int   occLight_IsHeadlight       (in int theId); //!< Is light a headlight?
vec4  occLight_Diffuse           (in int theId); //!< Diffuse intensity for specified light source
vec4  occLight_Specular          (in int theId); //!< Specular intensity (currently - equals to diffuse intencity)
vec4  occLight_Position          (in int theId); //!< Position of specified light source
vec4  occLight_SpotDirection     (in int theId); //!< Direction of specified spot light source
float occLight_ConstAttenuation  (in int theId); //!< Const attenuation factor of positional light source
float occLight_LinearAttenuation (in int theId); //!< Linear attenuation factor of positional light source
float occLight_SpotCutOff        (in int theId); //!< Maximum spread angle of the spot light (in radians)
float occLight_SpotExponent      (in int theId); //!< Attenuation of the spot light intensity (from 0 to 1)
#endif

// Front material properties accessors
vec4  occFrontMaterial_Emission(void);     //!< Emission color
vec4  occFrontMaterial_Ambient(void);      //!< Ambient  reflection
vec4  occFrontMaterial_Diffuse(void);      //!< Diffuse  reflection
vec4  occFrontMaterial_Specular(void);     //!< Specular reflection
float occFrontMaterial_Shininess(void);    //!< Specular exponent
float occFrontMaterial_Transparency(void); //!< Transparency coefficient

// Back material properties accessors
vec4  occBackMaterial_Emission(void);      //!< Emission color
vec4  occBackMaterial_Ambient(void);       //!< Ambient  reflection
vec4  occBackMaterial_Diffuse(void);       //!< Diffuse  reflection
vec4  occBackMaterial_Specular(void);      //!< Specular reflection
float occBackMaterial_Shininess(void);     //!< Specular exponent
float occBackMaterial_Transparency(void);  //!< Transparency coefficient

#define occActiveSampler    occSampler0                //!< alias for backward compatibility
#define occSamplerBaseColor occSampler0                //!< alias to a base color texture
uniform               sampler2D occSampler0;           //!< current active sampler;
                                                       //!  occSampler1, occSampler2,... should be defined in GLSL program body for multitexturing
uniform               vec4      occColor;              //!< color value (in case of disabled lighting)
uniform THE_PREC_ENUM int       occDistinguishingMode; //!< Are front and back faces distinguished?
uniform THE_PREC_ENUM int       occTextureEnable;      //!< Is texture enabled?
uniform               vec4      occTexTrsf2d[2];       //!< 2D texture transformation parameters
uniform               float     occPointSize;          //!< point size

//! Parameters of blended order-independent transparency rendering algorithm
uniform               int       occOitOutput;      //!< Enable bit for writing output color buffers for OIT (occFragColor, occFragCoverage)
uniform               float     occOitDepthFactor; //!< Influence of the depth component to the coverage of the accumulated fragment
uniform               float     occAlphaCutoff;    //!< alpha test cutoff value

//! Parameters of clipping planes
#if defined(THE_MAX_CLIP_PLANES) && (THE_MAX_CLIP_PLANES > 0)
uniform               vec4 occClipPlaneEquations[THE_MAX_CLIP_PLANES];
uniform THE_PREC_ENUM int  occClipPlaneCount;   //!< Total number of clip planes
#endif
// 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.

// This file includes implementation of common functions and properties accessors

#if defined(FRAGMENT_SHADER)
//! Output color (and coverage for accumulation by OIT algorithm).
void occSetFragColor (in vec4 theColor)
{
#if defined(OCC_ALPHA_TEST)
  if (theColor.a < occAlphaCutoff) discard;
#endif
#if defined(OCC_WRITE_WEIGHT_OIT_COVERAGE)
  float aWeight     = theColor.a * clamp (1e+2 * pow (1.0 - gl_FragCoord.z * occOitDepthFactor, 3.0), 1e-2, 1e+2);
  occFragCoverage.r = theColor.a * aWeight;
  occFragColor      = vec4 (theColor.rgb * theColor.a * aWeight, theColor.a);
#else
  occFragColor = theColor;
#endif
}
#endif

#if defined(THE_MAX_LIGHTS) && (THE_MAX_LIGHTS > 0)
// arrays of light sources
uniform THE_PREC_ENUM ivec2 occLightSourcesTypes[THE_MAX_LIGHTS]; //!< packed light sources types
uniform               vec4  occLightSources[THE_MAX_LIGHTS * 4];  //!< packed light sources parameters

// light source properties accessors
int   occLight_Type              (in int theId) { return occLightSourcesTypes[theId].x; }
int   occLight_IsHeadlight       (in int theId) { return occLightSourcesTypes[theId].y; }
vec4  occLight_Diffuse           (in int theId) { return occLightSources[theId * 4 + 0]; }
vec4  occLight_Specular          (in int theId) { return occLightSources[theId * 4 + 0]; }
vec4  occLight_Position          (in int theId) { return occLightSources[theId * 4 + 1]; }
vec4  occLight_SpotDirection     (in int theId) { return occLightSources[theId * 4 + 2]; }
float occLight_ConstAttenuation  (in int theId) { return occLightSources[theId * 4 + 3].x; }
float occLight_LinearAttenuation (in int theId) { return occLightSources[theId * 4 + 3].y; }
float occLight_SpotCutOff        (in int theId) { return occLightSources[theId * 4 + 3].z; }
float occLight_SpotExponent      (in int theId) { return occLightSources[theId * 4 + 3].w; }
#endif

// material state
uniform vec4 occFrontMaterial[5];
uniform vec4 occBackMaterial[5];

// front material properties accessors
vec4  occFrontMaterial_Ambient(void)      { return occFrontMaterial[0]; }
vec4  occFrontMaterial_Diffuse(void)      { return occFrontMaterial[1]; }
vec4  occFrontMaterial_Specular(void)     { return occFrontMaterial[2]; }
vec4  occFrontMaterial_Emission(void)     { return occFrontMaterial[3]; }
float occFrontMaterial_Shininess(void)    { return occFrontMaterial[4].x; }
float occFrontMaterial_Transparency(void) { return occFrontMaterial[4].y; }

// back material properties accessors
vec4  occBackMaterial_Ambient(void)       { return occBackMaterial[0]; }
vec4  occBackMaterial_Diffuse(void)       { return occBackMaterial[1]; }
vec4  occBackMaterial_Specular(void)      { return occBackMaterial[2]; }
vec4  occBackMaterial_Emission(void)      { return occBackMaterial[3]; }
float occBackMaterial_Shininess(void)     { return occBackMaterial[4].x; }
float occBackMaterial_Transparency(void)  { return occBackMaterial[4].y; }

// 2D texture coordinates transformation
vec2  occTextureTrsf_Translation(void) { return occTexTrsf2d[0].xy; }
vec2  occTextureTrsf_Scale(void)       { return occTexTrsf2d[0].zw; }
float occTextureTrsf_RotationSin(void) { return occTexTrsf2d[1].x; }
float occTextureTrsf_RotationCos(void) { return occTexTrsf2d[1].y; }

THE_SHADER_IN  vec2 ScreenSpaceCoord;
uniform int   uPattern;
uniform float uFactor;
vec4 getColor(void) { return occColor; }
void main()
{
  float anAngle      = atan (dFdx (ScreenSpaceCoord.x), dFdy (ScreenSpaceCoord.y));
  float aRotatePoint = gl_FragCoord.x * sin (anAngle) + gl_FragCoord.y * cos (anAngle);
  uint  aBit         = uint (floor (aRotatePoint / uFactor + 0.5)) & 15U;
  if ((uint (uPattern) & (1U << aBit)) == 0U) discard;
  vec4 aColor = getColor();
  if (aColor.a <= 0.1) discard;
  occSetFragColor (aColor);
}
TKOpenGl | Type: Error | ID: 0 | Severity: High | Message:
  Failed to compile shader object. Compilation log:
ERROR: 0:270: 'aBit' : syntax error: syntax error

 

Kirill Gavrilov's picture

It looks like you are using an obsolete version of OCCT.
Are you sure you are using the latest release OCCT 7.4.0, where this error should be already fixed?

w d's picture

Hello, excuse me.
I am learning and applying occt7.4.0. When learning its Graphic3d_ShaderProgram function, I want to achieve the xray effect of meshlib (see Annex 1 for details).
In contrast to the shader of meshlib xray (xray.vert and xray.frag, see attachments 2 and 3 for details), I rewritten a shader (xray.vs and xray.fs, see attachments 4 and 5), but
The effect is not the same as the effect of meshlib (see attachment 6 for details). The effect of my shader, gl_FragColor.a seems to have no effect. I removed the other code, set gl_FragColor.a to 0.8, but there is no transparency. I would like to ask you, is there any problem with the shader I rewritten? I wonder if occt has any documentation on how to write the shader? If so, can you tell me where I can find it?
Thank you very much.
I use Graphic3d_ShaderProgram in ocaf like this:
Handle (Graphic3d_ShaderProgram) aProgram;
aProgram = new Graphic3d_ShaderProgram ();
Handle (Graphic3d_ShaderObject) vertexshader = Graphic3d_ShaderObject :: CreateFromFile (Graphic3d_TOS_VERTEX, maSrcVert);
Handle (Graphic3d_ShaderObject) fragmentshader = Graphic3d_ShaderObject :: CreateFromFile (Graphic3d_TOS_FRAGMENT, maSrcFrag);
if (vertexshader.IsNull ())
{
return;
}
if (fragmentshader.IsNull ())
{
return;
}
if (! vertexshader-> IsDone ())
{
return;
}
if (! fragmentshader-> IsDone ())
{
return;
}
Standard_Boolean attach1 = aProgram-> AttachShader (vertexshader);
Standard_Boolean attach2 = aProgram-> AttachShader (fragmentshader);
if ((! attach1) || (! attach2))
{
return;
}
Standard_Boolean set1 = aProgram-> PushVariableFloat ("edgefalloff", 2.0f);
Standard_Boolean set2 = aProgram-> PushVariableFloat ("intensity", 2.0f);
Standard_Boolean set3 = aProgram-> PushVariableFloat ("ambient", 0.5f);
if ((! set1) || (! set2) || (! set3))
{
return;
}
if (! aProgram-> IsDone ())
{
return;
}
aProgram-> SetAlphaTest (false);
aProgram-> SetWeightOitOutput (false);

In addition, the shader of meshlib xray and the shader I rewritten are copied below respectively
Here is the meshlib xray shader
------ xray.frag ------------
// Application to vertex shader
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

void main ()
{
vec4 P = gl_ModelViewMatrix * gl_Vertex;
I = P.xyz-vec3 (0);
N = gl_NormalMatrix * gl_Normal;
Cs = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
------ xray.vert ------------

// vertex to fragment shader io
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

// globals
uniform float edgefalloff;
uniform float intensity;
uniform float ambient;

// entry point
void main ()
{
float opac = dot (normalize (-N), normalize (-I));
opac = abs (opac);
opac = ambient + intensity * (1.0-pow (opac, edgefalloff));
// opac = 1.0-opac;
gl_FragColor = opac * Cs;
gl_FragColor.a = opac;
}

Here is my shader
------ xray.vs ---------
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

//! 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 ()
{
  N = TransformNormal (occNormal);
  vec4 P = occWorldViewMatrix * occModelWorldMatrix * occVertex;
  I = P.xyz-vec3 (0);
  Cs = occColor;
  gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}
------ xray.fs ---------
// vertex to fragment shader io
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

// globals
uniform float edgefalloff;
uniform float intensity;
uniform float ambient;

// entry point
void main ()
{
    float opac = dot (normalize (-N), normalize (-I));
    opac = abs (opac);
    opac = ambient + intensity * (1.0-pow (opac, edgefalloff));
    // opac = 1.0-opac;
    
    gl_FragColor = opac * Cs;
    gl_FragColor.a = opac;
}

Kirill Gavrilov's picture

Use "Code snippet" formatting for the code - it is barely readable in current form.

Concerning transparency effect - it is managing by Blending parameters, not a GLSL program (shader just writes .a alpha component, which will be ignored by default).
This is managed by Graphic3d_Aspects::AlphaMode() property, which has Graphic3d_AlphaMode_BlendAuto default value, meaning that blending will be automatically enabled for materials having transparency. There is also Graphic3d_AlphaMode_Blend enabling blending unconditionally (e.g. when transparency is stored within the texture or computed dynamicall by GLSL program).

w d's picture

Sorry for using such a bad submission method, I will correct it.
Yes. I found this problem after many tests.. I also want to ask,Is the code in xray.vs and xray.frag the same effect? ​​Especially gl_NormalMatrix of xray.frag and TransformNormal (occNormal) of xray.vs. Because I
found that after modifying the blending mode, xray effects came out, but there were relatively large differences. Very Thank you.

------ xray.vs ---------
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

//! 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 ()
{
  N = TransformNormal (occNormal);
  vec4 P = occWorldViewMatrix * occModelWorldMatrix * occVertex;
  I = P.xyz-vec3 (0);
  Cs = occColor;
  gl_Position = occProjectionMatrix * occWorldViewMatrix * occModelWorldMatrix * occVertex;
}


------ xray.frag ------------
// Application to vertex shader
varying vec3 N;
varying vec3 I;
varying vec4 Cs;

void main ()
{
    vec4 P = gl_ModelViewMatrix * gl_Vertex;
    I = P.xyz-vec3 (0);
    N = gl_NormalMatrix * gl_Normal;
    Cs = gl_Color;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}
Nikolay Sorokin's picture

Thx. Nice to hear.
Yes, it is 7.3.0 for now.