Shader support in OCCT 6.7.0

Forums: 

As implementation of one of the strategic steps in OCCT visualization component development road-map, support for GLSL shader programs has been added in Open CASCADE Technology 6.7.0.

Shader programs have become a part of aspect classes in Graphic3d package, thus application developers can provide individual shader programs for all supported kinds of graphic primitives: points, lines, shaded polygons and text.

Shader integration follows the general “compute, then render” paradigm:

  • Application-defined implementation of AIS_InteractiveObject::Compute() method creates Graphic3d_ShaderProgram instances and passes them to Graphic3d_Group through Graphic3d_Aspect* classes, just like any other visual attributes.
  • At render time, the shader programs are built and bound automatically to the OpenGL rendering context and only for the group of primitives they were associated with.

Shader management is fully automatic, just like in case of any other OpenGL resource. A certain limitation of the first implementation of shader support coming with OCCT 6.7.0, shader programs cannot use GLSL 1.40 (or newer) capabilities. However, to overcome this limitation partially, OCCT defines a subset of uniforms needed for shader operation, so that the shader programs do not rely on GLSL 1.30 predefined variables. Refer to Declarations.glsl in Shaders directory in the OCCT source tree for a complete list of uniforms defined by OCCT. In future OCCT release, redesign of the rendering logic will be continued, so as to eliminate GLSL version limitation completely. A sample pre-defined shader program that comes with OCCT 6.7.0 implements Phong shading. It is not used by default for performance reasons. Thus it is up to an application to provide its own interactive object class that takes advantage of this shader program. Refer to vshaderprog DRAW Test Harness command for a usage example. The snapshots below (obtained with help of vshaderprog command) illustrate the difference between the default OpenGL Gouraud shading (on the left) and Phong shading available in OCCT 6.7.0 (on the right):

A couple of snapshots below show results of other simple shader programs run by OCCT OpenGL renderer (the shader programs are not included into OCCT 6.7.0):


Fragment shader implementing custom clipping surface

Fragment shader suppressing fragments with a given step along the model Z axis
Berkay Elbir's picture

Hello Sergey,

I am new on OCCT and I want to write a code to sphere drawing by using shaders and textures on it. But I could not find any complete examples with shading and texturing to guide me.

Is there any implementation example?

Sergey Anikin's picture

Hello Berkay,

It is recommended to start with the source code of vshaderprog DRAW command, it can be found in src/ViewerTest/ViewerTest_OpenGlCommands.cxx. It shows how to attach a shader to an instance of interactive object class.
OCCT test cases in tests/v3d/glsl illustrate usage of this command.

Best regards,
Sergey

Berkay Elbir's picture

Hello Sergey,

Thanks for your answer. It was very helpful. But I tried to run DRAWEXE.exe, it needs tcl86t.dll. Then I downloaded Tcl from following link: http://www.activestate.com/activetcl/downloads

There is not tcl86t.dll inside it, tcl86.dll is exist. So How can I run DRAWEXE.exe ?

Sergey Anikin's picture

Hello Berkay,

You can find pre-built OCCT third-party binaries (including Tcl 8.6) here.

Still I wonder how you could get this problem...
Do you use pre-built OCCT binaries downloaded from somewhere?
Or do you build OCCT from sources?

I suggest you rebuild OCCT from sources as described in RESOURCES section of the development portal. If you follow the instructions carefully, you will never get this problem.

Best regards,
Sergey

Berkay Elbir's picture

Hello Sergey,

I managed to open DRAWEXE. I guess problem with compilation issue. I run it from builded version OCCT from binaries.

Thanks.

Berkay Elbir's picture

Hello Sergey,

May I ask you a question about performance issues? There are three scenarios:

1 - Drawing a 3D shape (Box,Sphere etc.) with AIS_InteractiveContext->Display function I mean default one and There is no texture on it.

2- Drawing a 3D shape (Box,Sphere etc.) with AIS_InteractiveContext->Display function I mean default one and There is texture on it with AIS_TexturedShape.

3- Drawing a 3D shape with a shader for example using VShaderProg and texture on it.

Which one is better for performance side?

Thanks,

Kirill Gavrilov's picture

The texture requires additional fetches during rendering, thus textured shape should be drawn slower than without (at the same circumstances - e.g. both with lighting), but actual hit would depend on texture dimensions, properties and hardware (e.g. it is possible that there would not be any performance penalty at all).

Concerning the custom GLSL program - it is completely depends on the program itself. If you would like to compare fixed pipeline vs. GLSL - than GLSL might be sometime slightly slower; if you compare per-pixel shading vs. per-vertex shading, than per-vertex shader is more optimal for performance.

Notice that within current master there are built-in GLSL programs (e.g. without calling VShaderProg) which would work instead of fixed pipeline if requested in OpenGl_GraphicDriver capabilities (vcaps -ffp 0 in Draw Harness).

Berkay Elbir's picture

Thanks for your answer. It was very helpful.