Shader support in OCCT 6.7.0
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