Class SoFragmentShader

  • All Implemented Interfaces:
    SafeDisposable

    public class SoFragmentShader
    extends SoShaderObject
    Node that defines a fragment shader. This node defines a fragment shader.

    See SoShaderProgram for general information about using shaders and shader parameters.

    See parent class SoShaderObject for details about using the inherited fields.

    Notes:

    • Shaders in the scene graph.
      Shader object nodes cannot be inserted directly in a scene graph.
      They must be added to the shaderObject field of an SoShaderProgram node.
    • Predefined GLSL variables.
      Open Inventor uses a compatibility profile context for rendering. So legacy GLSL predefined variables, for example gl_FragColor, can be used in fragment shaders. However, if you use the GLSL "#version" directive in a shader, you should append the keyword "compatibility", for example: "#version 150 compatibility".
    • Transparency.
      To maintain compatibility with Open Inventor's high quality transparency algorithms like SORTED_PIXEL, fragment shaders should not output a color by setting gl_FragColor (or equivalent parameter) directly. Use the GLSL method OivDepthPeelingOutputColor() instead.

      Fragment shaders can access the depthPeeling API using Open Inventor's built-in "include" mechanism as shown below. (Note: In the "oiv_include" statement there must not be any white space in the string "//!oiv_include". The space character shown below is required by a limitation of our documentation tools.)

       // Fragment shader GLSL code
       
       // !oiv_include <Inventor/oivDepthPeeling_frag.h> 
       
       void main()
       {
           if (OivDepthPeel( gl_FragCoord.xyz )) {
       
               // Compute and set fragment color
               vec4 color = . . .
       
               OivDepthPeelingOutputColor( color );
           }
       }

    • Transparency.
      If a fragment shader makes geometry transparent (sets alpha values < 1), the application should set the SoShaderProgram.generateTransparency field to true. This ensures that Open Inventor knows to apply the correct handling for the current transparency mode.
    • Shadows.
      To integrate with Open Inventor's shadow casting algorithm, fragment shaders should call the GLSL methods OivComputeShadow() and OivGenerateShadowMap(). Please see SoShadowGroup for example code.

    File format/default:

    FragmentShader {

      sourceProgram ""
      sourceType FILENAME
      isActive true
      parameter NULL
    }

    See Also:
    SoGeometryShader, SoShaderObject, SoShaderProgram, SoTessellationControlShader, SoTessellationEvaluationShader, SoUniformShaderParameter, SoVertexShader
    • Constructor Detail

      • SoFragmentShader

        public SoFragmentShader()
        Constructor.
    • Method Detail

      • isSupported

        public static boolean isSupported​(SoShaderObject.SourceTypes sourceType)
        Calls isSupported(sourceType, (com.openinventor.inventor.misc.SoState)null).
      • isSupported

        public static boolean isSupported​(SoShaderObject.SourceTypes sourceType,
                                          SoState state)
        Indicates if fragment shaders in the specified language are supported by your graphics board. When using a debug build of Open Inventor, some "no context available" warning messages may be generated. You can ignore them or see SoGLExtension for an example of using SoGLContext to avoid them.
      • getMaxTextureImageUnit

        public static int getMaxTextureImageUnit()
        Returns the maximum number of texture image units.