Shaders in Java 3DTM 1.4

Introduction and pointer to discussion forum

If you wandered over here looking for a completed draft programmable shading specification for Java 3DTM 1.4 that you can review, you are in the wrong place; or more accurately, the right place at the wrong time. Come back in about 1-2 months and things should be in state where you can review a fairly complete draft specification. If, on the other hand, you'd like to help us define and evolve the programmable shading API in Java 3D 1.4, please read on.

This is a rough first draft of what we are thinking in terms of programmable shader support in Java 3D 1.4. As we mentioned at JavaOne, we plan to do 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

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

    We need additional API to allow applications to pass in uniform parameters that do not correspond to a pre-defined Java 3D attribute...
    TODO: Finish this...

    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$