Use the default line shader (original) (raw)

Source file: LineShaderExample

JavaDoc: DefaultLineShader

Run as Java webstart

This example demonstrates many of the features of the default line shader provided in the jReality scene graph. It is best studied in conjunction with the tutorial example featuring line set factories.

The underlying scene graph in this example consists of a cylindrical stack of circles, each represented by an indexed line set with twenty vertices. Each layer of the stack is attached to a different instance of the default line shader. The underlying geometric line sets are identical to each other, with the exception of some optional vertex and edge attributes (colors and relative radii) which interact with the settings of the line shader to produce different effects. In the center of each circle is a text label containing a number from 1 to 6, which can be matched to the index used in the source code to generate the scene.

The shader attributes for the line shader are created using the shader interfaces, rather than directly setting Appearance attributes. (See Introductory tutorial for more details about this distinction.)

The first two examples demonstrate the display of lines in the simplest form. (In the case of the JOGL backend, this is an edge drawn using an anti-aliased Bresenham algorithm). The rest of the examples render each line as a 3D geometric tube centered on the actual 1D line. In the latter case, many of the rendering parameters are derived from the polygon shader contained in the line shader. In the case of non-tube rendering, the size of the representation is set with the method setLineWidth which is a specified in pixels, while with tube rendering the size is specified with setTubeRadius.

To see the difference between these two coordinate systems, use the click wheel camera zoom tool provided in the example, to zoom in on the scene. The edges drawn in the first two example (non-tube) do not get larger (since pixels remain the same size) but the other points, drawn as tubes, do get larger when one zooms in.

The features demonstrated here include:

Note that when tubes are drawn, they will be drawn with smooth-shading or flat-shading, depending on the value of getSmoothShading() in the polygon shader interface associated to the line shader. The following code will guarantee that tubes are always drawn smooth, although other polygonal geometry would be drawn flat shaded (all attributes from the class CommonAttributes)::

ap.setAttribute(LINE_SHADER+"."+POLYGON_SHADER+"."+SMOOTH_SHADING, true); ap.setAttribute(POLYGON_SHADER+"."+SMOOTH_SHADING, false);

Note: The attribute LINE_LIGHTING_ENABLED (shader interface method setLineLighting) is not demonstrated in the example, but can be used if all following conditions are satisfied:

In this case, the lines will be rendered according to the current state of the lights and the vertex normals of the line set. [This feature should be packaged up into a non-default line shader!]

Conclusion: The final diffuse color attached to lines is a result of several factors:

Some of the features of the line shader (particularly those related to rendering hints, such as the rhs.setOpaqueTubesAndSpheres(), are only implemented at the current time for the JOGL backend.