eScience Lectures Notes : Illumination and Shading in Java3D


Slide 1 : Illumination in Java3D

Illumination in Java3D

Introduction

Types of Lights

Ambient Lights

Ambient Lights Examples

Directional Lights

Point Lights

Point Light Attenuation

Spot Lights

Light Influencing Bounds

Light Influencing Bounds : Examples

Scoping Lights

Lighting Summary


Appearance

Coloring Attributes

Material Attributes

Transparency Attributes

Point and Line Attributes

Polygon Attributes

Rendering Attributes

Appearance Class Methods

Appearance Example Code

Appearance Summary


Slide 2 : Illumination in Java3D

Illumination in Java3D

Apparence

Lighting


Slide 3 : Types of Lights

Types of Lights

Java 3D provides four types of lights defined in the Light class

All lights share common attributes:

An on/off enable state

A color

A bounding volume and scope controlling the range of shapes they illuminate

Method Default
Light() enable flag : true
color : white (1,1,1)
scope : empty (universe scope)
influencing bounds : null
influencing bounding leaf : null
Light(boolean lightOn, Color3f color)
Light(Color3f color)
void setEnable( boolean OnOff ) true
void setColor( Color3f color ) 1.0, 1.0, 1.0

 


Slide 4 : Ambient Lights

Ambient Lights

AmbientLight extends the Light class



TransformGroup group = new TransformGroup( );
. . .
AmbientLight light = new AmbientLight( );
light.setEnable( true );
light.setColor( new Color3f( 1.0f, 1.0f, 1.
0f ) );
. . .
light.setInfluencingBounds( bounds );
group.addChild( light );


Slide 5 : Ambient Lights

Ambient Lights Examples

Ambient light + Headlight

Ambient light only

 


Slide 6 : Directional Lights

Directional Lights

Method Default
void setDirection( Vector3f dir )
0.0, 0.0, -1.0 


TransformGroup group = new TransformGroup( );
. . .
DirectionalLight light = new DirectionalLight( );
light.setEnable( true );
light.setColor( new Color3f( 1.0f, 1.0f, 1.0f ) );
light.setDirection( new Vector3f( 1.0f, 0.0f, 0.0f ) );

. . .
light.setInfluencingBounds( bounds );
group.addChild( light );

 


Slide 7 : Point Lights

Point Lights


Slide 8 : Point Light Attenuation

Point Light Attenuation

Point light rays are attenuated:

brightness =

lightIntensity
constant + linear*distance + quadratic*distance2

 

Method Default
void setPosition( Point3f pos ) 
0.0, 0.0, 0.0 
void setAttenuation( Point3f atten )
 1.0, 0.0, 0.0 


TransformGroup group = new TransformGroup( );
. . .
PointLight light = new PointLight( );
light.setEnable( true );
light.setColor( new Color3f( 1.0f, 1.0f, 1.0f ) );
light.setPosition( new Point3f( 0.0f, 1.0f, 0.0f ) );
light.setAttenuation( new Point3f( 1.0f, 0.0f, 0.0f ) );

. . .
light.setInfluencingBounds( bounds );
group.addChild( light );

 


Slide 9 : Spot Lights

Spot Lights

Method Default
void setDirection( Vector3f dir )
0.0, 0.0, -1.0
void setSpreadAngle( float angle )
PI
void setConcentration( float concen )
0.0 

Direction - The axis of the cone of light. The default direction is (0.0, 0.0, -1.0). The spot light direction is significant only when the spread angle is not PI radians (which it is by default).
* Spread angle - The angle in radians between the direction axis and a ray along the edge of the cone. Note that the angle of the cone at the apex is then twice this value. The range of values is [0.0,PI/2] radians, with a special value of PI radians. Values lower than 0 are clamped to 0 and values over PI/2 are clamped to PI. The default spread angle is PI radians.
* Concentration - Specifies how quickly the light intensity attenuates as a function of the angle of radiation as measured from the direction of radiation. The light's intensity is highest at the center of the cone and is attenuated toward the edges of the cone by the cosine of the angle between the direction of the light and the direction from the light to the object being lit, raised to the power of the spot concentration exponent. The higher the concentration value, the more focused the light source. The range of values is [0.0,128.0]. The default concentration is 0.0, which provides uniform light distribution.



TransformGroup group = new TransformGroup( );
. . .
SpotLight light = new SpotLight( );
light.setEnable( true );
light.setColor( new Color3f( 1.0f, 1.0f, 1.0f ) );
light.setPosition( new Point3f( 0.0f, 1.0f, 0.0f ) );
light.setAttenuation( new Point3f( 1.0f, 0.0f, 0.0f ) );
light.setDirection( new Vector3f( 1.0f, 0.0f, 0.0f ) );
light.setSpreadAngle( 0.785f ); // 45 degrees
light.setConcentration( 0.0f ); // Unfocused

. . .
light.setInfluencingBounds( bounds );
group.addChild( light );

 


Slide 10 : Light Influencing Bounds

Light Influencing Bounds

A light's illumination is bounded to a region of influence

A light region of influence is a bounded volume:

A light bounding volume can be relative to:


Slide 11 : Light Influencing Bounds : Examples

Light Influencing Bounds : Examples

Set bounds relative to the light's coordinate system

PointLight light = new PointLight( );
light.setInfluencingBounds( bounds );

Or relative to a bounding leaf's coordinate system

TransformGroup group = new TransformGroup( );
BoundingLeaf leaf = new BoundingLeaf( bounds );
group.addChild( leaf );
. . .
PointLight light = new PointLight( );
light.setInfluencingBoundingLeaf( leaf );

Large bounds Small bounds

Example : BoundingSphere(Point3d center, double radius)

 


Slide 12 : Scoping Lights

Scoping Lights



TransformGroup lightable = new TransformGroup( );
. . .
DirectionalLight light = new DirectionalLight( );
light.addScope( lightable );

 


Slide 13 : Lighting Summary

Lighting Summary

Class


Attributes


Light

Enable, Color, Influencing bounds, Scope

AmbientLight

-

DirectionalLight

Direction

PointLight

Position, Attenuation

  

SpotLight

Direction, Spread Angle, Concentration


Slide 14 : Appearance

Appearance

Control how Java 3D renders Geometry

All appearance control is encapsulated within the Appearance class, and its components

Diffuse

Specular

Diffuse & Specular

Shaded

Textured

Transparent

Unlit polygons

Unlit lines

Unlit points

 


Slide 15 : Coloring Attributes

Coloring Attributes


Slide 16 : Material Attributes

Material Attributes


Slide 17 : Transparency Attributes

Transparency Attributes


Slide 18 : Point and Line Attributes

Point and Line Attributes


Slide 19 : Polygon Attributes

Polygon Attributes

The PolygonAttributes object defines attributes for rendering polygon primitives. The polygon attributes that can be defined are: * Rasterization mode - defines how the polygon is drawn: as points, outlines, or filled.
* POLYGON_POINT - the polygon is rendered as points drawn at the vertices.
* POLYGON_LINE - the polygon is rendered as lines drawn between consecutive vertices.
* POLYGON_FILL - the polygon is rendered by filling the interior between the vertices. The default mode.* Face culling - defines which polygons are culled (discarded) before they are converted to screen coordinates.
* CULL_NONE - disables face culling.
* CULL_BACK - culls all front-facing polygons. The default.
* CULL_FRONT - culls all back-facing polygons.* Back-face normal flip - specifies whether vertex normals of back-facing polygons are flipped (negated) prior to lighting. The setting is either true, meaning to flip back-facing normals, or false. The default is false.
* Offset - the depth values of all pixels generated by polygon rasterization can be offset by a value that is computed for that polygon. Two values are used to specify the offset:* Offset bias - the constant polygon offset that is added to the final device coordinate Z value of polygon primitives.
* Offset factor - the factor to be multiplied by the slope of the polygon and then added to the final, device coordinate Z value of the polygon primitives.These values can be either positive or negative. The default for both of these values is 0.0.

 


Slide 20 : Rendering Attributes

Rendering Attributes

The RenderingAttributes object defines common rendering attributes for all primitive types. The rendering attributes are:* Alpha test function - used to compare the alpha test value with each per-pixel alpha value. If the test passes, the pixel is written, otherwise the pixel is not written. The alpha test function is set with the setAlphaTestFunction method. The alpha test function is one of the following:* ALWAYS - pixels are always drawn, irrespective of the alpha value. This effectively disables alpha testing. This is the default setting.
* NEVER - pixels are never drawn, irrespective of the alpha value.
* EQUAL - pixels are drawn if the pixel alpha value is equal to the alpha test value.
* NOT_EQUAL - pixels are drawn if the pixel alpha value is not equal to the alpha test value.
* LESS - pixels are drawn if the pixel alpha value is less than the alpha test value.
* LESS_OR_EQUAL - pixels are drawn if the pixel alpha value is less than or equal to the alpha test value.
* GREATER - pixels are drawn if the pixel alpha value is greater than the alpha test value.
* GREATER_OR_EQUAL - pixels are drawn if the pixel alpha value is greater than or equal to the alpha test value.* Alpha test value - the test value used by the alpha test function. This value is compared to the alpha value of each rendered pixel. The alpha test value is set with the setAlphaTestValue method. The default alpha test value is 0.0.
* Raster operation - the raster operation function for this RenderingAttributes component object. The raster operation is set with the setRasterOp method. The raster operation is enabled or disabled with the setRasterOpEnable method. The raster operation is one of the following:* ROP_COPY - DST = SRC. This is the default operation.
* ROP_XOR - DST = SRC ^ DST.* Vertex colors - vertex colors can be ignored for this RenderingAttributes object. This capability is set with the setIgnoreVertexColors method. If ignoreVertexColors is false, per-vertex colors are used, when present in the associated geometry objects, taking precedence over the ColoringAttributes color and Material diffuse color. If ignoreVertexColors is true, per-vertex colors are ignored. In this case, if lighting is enabled, the Material diffuse color will be used as the object color. if lighting is disabled, the ColoringAttributes color is used. The default value is false.
* Visibility flag - when set, invisible objects are not rendered (subject to the visibility policy for the current view), but they can be picked or collided with. This flag is set with the setVisible method. By default, the visibility flag is true.
* Depth buffer - can be enabled or disabled for this RenderingAttributes component object. The setDepthBufferEnable method enables or disabled the depth buffer. The setDepthBufferWriteEnable method enables or disables writing the depth buffer for this object. During the transparent rendering pass, this attribute can be overridden by the depthBufferFreezeTransparent attribute in the View object. Transparent objects include BLENDED transparent and antialiased lines and points. Transparent objects do not include opaque objects or primitives rendered with SCREEN_DOOR transparency. By default, the depth buffer is enabled and the depth buffer write is enabled.



Slide 21 : Appearance Class Methods

Appearance Class Methods

Method Default

Appearance( )

Unlit white


void setColoringAttributes( ColoringAttributes coloringAttributes )

White, Gouraud

void setMaterial( Material material )

None

void setTransparencyAttributes( TransparencyAttributes transparencyAttributes )

Opaque

void setLineAttributes( LineAttributes lineAttributes )

1 pixel wide


void setPointAttributes( PointAttributes pointAttributes )

1 pixel


void setPolygonAttributes( PolygonAttributes polygonAttributes )

Fill


void setRenderingAttributes( RenderingAttributes renderingAttributes )

Depth enable





Slide 22 : Appearance Example Code

Appearance Example Code

Create an Appearance node, then set one or more of its attribute components

Most of the following example are detailed... there are shorter way to do by using constructors !

Appearance app = new Appearance( ); 


// Coloring Attributes
// Intrinsic color, Gouraud shading 
ColoringAttributes ca = new ColoringAttributes( );
ca.setColor( 1.0f, 1.0f, 0.0f );
ca.setShadeModel( ColoringAttributes.SHADE_GOURAUD );
app.setColoringAttributes( ca ); //Material Attributes //Ambient, emissive, diffuse, and specular colors
Material mat = new Material( );
mat.setAmbientColor( 0.3f, 0.3f, 0.3f );
mat.setDiffuseColor( 1.0f, 0.0f, 0.0f );
mat.setEmissiveColor( 0.0f, 0.0f, 0.0f );
mat.setSpecularColor( 1.0f, 1.0f, 1.0f );
mat.setShininess( 80.0f );
app.setMaterial( mat ); // Transparency Attributes // Semi-transparent, alpha-blended
TransparencyAttributes ta = new TransparencyAttributes( );
ta.setTransparency( 0.5f );
ta.setTransparencyMode( TransparencyAttributes.BLENDED );
app.setTransparencyAttributes( ta ); // Point Attributes // 10 pixel points, not anti-aliased
PointAttributes pta = new PointAttributes( ); pta.setPointSize( 10.0f );
pta.setPointAntialiasingEnable( false );
app.setPointAttributes( pta ); // Line Attributes // 10 pixel lines, solid, not anti-aliased LineAttributes lta = new LineAttributes( ); lta.setLineWidth( 10.0f ); lta.setLineAntialiasingEnable( false ); lta.setLinePattern( LineAttributes.PATTERN_SOLID ); app.setLineAttributes( lta ); // Polygon Attributes // Filled polygons, front and back faces
PolygonAttributes pa = new PolygonAttributes( );
pa.setPolygonMode( PolygonAttributes.POLYGON_FILL );
pa.setCullFace( PolygonAttributes.CULL_NONE );
app.setPolygonAttributes( pa );
 







Slide 23 : Summary

Summary

Class Attributes

Appearance

Multiple attribute components

ColoringAttributes

Intrinsic color, Shading model

Material

Ambient color, Emissive color, Diffuse color, Specular color, Shininess

TransparencyAttributes

Transparency, Mode

PointAttributes

Point size, Anti-aliasing

LineAttributes

Line width, Pattern, Anti-aliasing

PolygonAttributes

Culling, Polygon mode, Z offset

RenderingAttributes

Depth and Alpha modes