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 preliminary 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

NOTE: This section is under construction. For the most up to date API definition, please see the javadoc for the new ShaderAttributes class.

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 ShaderAttributes object with following new attributes: See the javadoc for the new ShaderAttributes class for more details. Issues

    Automatic variables
    Several Java 3D state attributes are automatically available to the shader program as pre-defined uniform parameters. The application doesn't need to do anything to pass these parameters 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$