Shaders in Java 3DTM 1.4

Introduction and pointer to discussion forum

Here is the latest rough first draft of what we are thinking in terms of programmable shader support in Java 3DTM for 1.4. We plan to formalize the 1.4 API specification under the auspices of the Java Community Process (JCP). However, we very much want to involve the larger community in API discussions for programmable shaders, so please join in the discussion.

We have created a thread on the Java 3D discussion forum for discussing Java 3D Programmable Shaders. Feel free to post your comments on our ideas, or post some ideas of your own.

Class Hierarchy for Shader Objects

The proposed class hierarchy for programmable shaders in Java 3D is:

Click on the following link for a current look at the javadoc-generated API definitions for the proposed 1.4 API.

Example Usage

This is an example code excerpt showing how one might use the new programmable shader API in a Java 3D program.

Shader Parameters

Programmable shaders define two types of parameters: uniform and varying. As the names imply, uniform parameters are constant (within a primitive), while varying parameters can vary on per-vertex or per-fragment basis.

  1. Uniform parameters (attributes) are those parameters whose value is constant during the rendering of a primitive. Their values may change from primitive to primitive, but are constant for each vertex (for vertex shaders) or fragment (for fragment shaders) of a single primitive. Examples of uniform parameters include a transformation matrix, a texture map, lights, lookup tables, etc.

    We have created a new ShaderAttributeSet for allowing applications to specify uniform shader attributes. There are two ways in which values can be specified for uniform attributes: explicitly, by providing a value; and implicitly, by defining a binding between a Java 3D system attribute and a uniform attribute. This functionality is provided by two subclasses of ShaderAttribute: ShaderAttributeObject, which is used to specify explicitly defined attributes; and ShaderAttributeBinding, which is used to specify implicitly defined, automatically tracked attributes. See the javadoc for the new ShaderAttributeSet and ShaderAttribute classes for more details.

    Issues

    Automatic variables
    Depending on the shading language (and profile) being used, several Java 3D state attributes are automatically made available to the shader program as pre-defined uniform attributes. The application doesn't need to do anything to pass these attributes in to the shader program. The implementation of each shader language (e.g., Cg, GLSL) defines its own mapping from Java 3D attribute to uniform variable name.

    A partial list of Java 3D attributes that are mapped to shader attributes follows:

  2. Java 3D Attribute
    Cg shader variable
    GLSL shader variable
    ModelViewProjection
    glstate.matrix.mvp
    gl_ModelViewProjectionMatrix
    Light[n] pos
    glstate.light[n].position gl_LightSource[n].position
    ...
    ...
    ...

  3. Varying parameters are those parameters that are specified as per-vertex attributes. They are are interpolated across a primitive similarly to colors and texture coordinates in the fixed function pipeline.

    We need additional API to allow applications to pass in per-vertex varying parameters...
    TODO: Finish this...

TODO: more info here.

Page last updated — $Date$