Package gov.nih.mipav.view.renderer.J3D
Class SoftwareLight
- java.lang.Object
-
- gov.nih.mipav.view.renderer.J3D.SoftwareLight
-
- Direct Known Subclasses:
SoftwareLightAmbient
,SoftwareLightDirectional
,SoftwareLightPoint
public abstract class SoftwareLight extends java.lang.Object
The base class for lights in a general lighting system to calculate colors at a point in space. Each point has a position, a normal vector, and material attributes that specify various colors, shininess, and an alpha value to support blending of colors. Each light has three colors: an ambient color, a diffuse color, and a specular color. For now, only the derived class MjAmbientLight affects the ambient lighting. Classes MjDirectionalLight, MjPointLight, and MjSpotLight make no contribution to ambient light, only to diffuse and specular light. This can change if need be. A light has an intensity. Although the intensity is intended to be in [0,1], it can be made larger to provide oversaturation. Each light also has a Boolean variable indicating if the light is on or off. The derived light classes include ambient, direction, point, and spot lights. The point and spot lights can have their effects attenuated with distance. The spot light can have its effect attenuated based on angle from the axis of the spot cone. The base class provides storage for the attenuation factors. Only a point or spot light should change these.See ShearWarpRendering.pdf for a detailed description of the lighting model.
-
-
Field Summary
Fields Modifier and Type Field Description javax.vecmath.Color3f
ambient
The colors associated with the light, typically all white.javax.vecmath.Color3f
diffuse
DOCUMENT ME!float
intensity
The intensity of the light, typically in [0,1].protected float
m_fAttenuate
Attenuation for point and spot lights based on distance of the vertex from the light source.protected float
m_fSpot
Attenuation for spot lights based on angle between the unit-length axis of the spot cone and the vector from the spot light position to the vertex.protected javax.vecmath.Color3f
m_kColor
The color m_kColor is the object returned in the colorOf functions.protected javax.vecmath.Vector3f
m_kNormal
DOCUMENT ME!protected javax.vecmath.Vector3f
m_kReflect
To avoid memory re allocations.protected javax.vecmath.Vector3f
m_kView
Values updated in the initView method which must be called by all lights (except AmbientLight).boolean
on
A flag indicating whether or not the light is on.javax.vecmath.Color3f
specular
DOCUMENT ME!
-
Constructor Summary
Constructors Modifier Constructor Description protected
SoftwareLight()
Construct a light.protected
SoftwareLight(SoftwareLight kThat)
Copy (deep) constructor.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addAmbient(javax.vecmath.Color3f kMatAmbient)
Calculate the color due to ambient lighting.protected float
addDiffuse(SoftwareMaterial kMaterial, SoftwareVertexProperty kVertexProperty, javax.vecmath.Vector3f kDirection)
Calculate the color due to diffuse lighting.protected void
addSpecular(SoftwareMaterial kMaterial, SoftwareVertexProperty kVertexProperty, javax.vecmath.Vector3f kDirection, float fDdN)
Calculate the color due to specular lighting.abstract javax.vecmath.Color3f
colorOf(SoftwareMaterial kMaterial, SoftwareVertexProperty kVertexProperty, javax.vecmath.Point3f kEye)
Compute the contribution of color from this light on the specified material with specified vertex properties.abstract SoftwareLight
copy()
Create a deep copy of this Light instance.protected void
initView(javax.vecmath.Point3f kEye, SoftwareVertexProperty kVertexProperty)
Calculate the view direction based on the vertex and the eye point (in model coordinates).protected float
normalize(javax.vecmath.Vector3f kV)
Replace a vector by a unit-length vector in the same direction.
-
-
-
Field Detail
-
ambient
public final javax.vecmath.Color3f ambient
The colors associated with the light, typically all white. The color channels are all in [0,1], hence the use of Color3f.
-
diffuse
public final javax.vecmath.Color3f diffuse
DOCUMENT ME!
-
intensity
public float intensity
The intensity of the light, typically in [0,1]. The intensity may be chosen larger than 1 to create oversaturation effects.
-
on
public boolean on
A flag indicating whether or not the light is on.
-
specular
public final javax.vecmath.Color3f specular
DOCUMENT ME!
-
m_fAttenuate
protected float m_fAttenuate
Attenuation for point and spot lights based on distance of the vertex from the light source. The value is always 1 for ambient and directional lights since those lights have no light position, in which case distance to a vertex is undefined. See the document ShearWarpRendering.pdf for details about attenuation.
-
m_fSpot
protected float m_fSpot
Attenuation for spot lights based on angle between the unit-length axis of the spot cone and the vector from the spot light position to the vertex. The value is always 1 for ambient, directional, and point lights. See the document ShearWarpRendering.pdf for details about attenuation.
-
m_kColor
protected final javax.vecmath.Color3f m_kColor
The color m_kColor is the object returned in the colorOf functions. This object is a Point3f because the final colors represents colors, each in the range [0,255]. Color3f specifies that color values are in [0,1], so I avoided this type in case Java wants to throw exceptions when the values are outside [0,1]. Notice that the material colors are Point3f in [0,255]^3 and the light colors are Color3f in [0,1]^3, so the products of material and light colors are Point3f in [0,255]^3.
-
m_kNormal
protected final javax.vecmath.Vector3f m_kNormal
DOCUMENT ME!
-
m_kReflect
protected final javax.vecmath.Vector3f m_kReflect
To avoid memory re allocations. The reflection vector is used in addSpecular.
-
m_kView
protected final javax.vecmath.Vector3f m_kView
Values updated in the initView method which must be called by all lights (except AmbientLight).
-
-
Constructor Detail
-
SoftwareLight
protected SoftwareLight()
Construct a light. The default colors are all black, the intensity is zero, and the light is off. The attenuation parameter are set to 1 for ambient and directional lights. Point and spot lights can modify the attenuation parameters as desired.
-
SoftwareLight
protected SoftwareLight(SoftwareLight kThat)
Copy (deep) constructor.- Parameters:
kThat
- Light What to make "this" light like.
-
-
Method Detail
-
colorOf
public abstract javax.vecmath.Color3f colorOf(SoftwareMaterial kMaterial, SoftwareVertexProperty kVertexProperty, javax.vecmath.Point3f kEye)
Compute the contribution of color from this light on the specified material with specified vertex properties.- Parameters:
kMaterial
- SoftwareMaterial Default properties for the material including emissive, ambient, diffuse, and specular colors along with the specular shininess which can be used to disable specular highlighting.kVertexProperty
- SoftwareVertexProperty Properties of the vertex which include its position and normal vector along with optional material property overrides for the diffuse and specular colors.kEye
- Point3f The location of the observer in the coordinate system defined for the light.- Returns:
- Color3f Reference to the computed color contribution by this light with this vertex and its material properties. The instance returned is owned by this light.
-
copy
public abstract SoftwareLight copy()
Create a deep copy of this Light instance.- Returns:
- Light Deep copy of this Light instance.
-
addAmbient
protected final void addAmbient(javax.vecmath.Color3f kMatAmbient)
Calculate the color due to ambient lighting. See the document ShearWarpRendering.pdf for details about the lighting model. This function is used in the colorOf functions in derived classes.- Parameters:
kMatAmbient
- the material ambient color
-
addDiffuse
protected final float addDiffuse(SoftwareMaterial kMaterial, SoftwareVertexProperty kVertexProperty, javax.vecmath.Vector3f kDirection)
Calculate the color due to diffuse lighting. See the document ShearWarpRendering.pdf for details about the lighting model. This function is used in the colorOf functions in derived classes.- Parameters:
kMaterial
- SoftwareMaterial Default properties for the material including emissive, ambient, diffuse, and specular colors along with the specular shininess which can be used to disable specular highlighting.kVertexProperty
- SoftwareVertexProperty Properties of the vertex which include its position and normal vector along with optional material property overrides for the diffuse and specular colors.kDirection
- The unit-length direction of the light at the point. This direction depends on the type of light.- Returns:
- The dot product of the direction and normal vector. If the dot product is nonnegative, there is no diffuse lighting at the point. Consequently, there is no specular lighting at the point. The caller of addDiffuse uses the returned dot product to test if addSpecular needs to be called.
-
addSpecular
protected final void addSpecular(SoftwareMaterial kMaterial, SoftwareVertexProperty kVertexProperty, javax.vecmath.Vector3f kDirection, float fDdN)
Calculate the color due to specular lighting. See the document ShearWarpRendering.pdf for details about the lighting model. This function is used in the colorOf functions in derived classes.- Parameters:
kMaterial
- SoftwareMaterial Default properties for the material including emissive, ambient, diffuse, and specular colors along with the specular shininess which can be used to disable specular highlighting.kVertexProperty
- SoftwareVertexProperty Properties of the vertex which include its position and normal vector along with optional material property overrides for the diffuse and specular colors.kDirection
- The unit-length direction of the light at the point. This direction depends on the type of light.fDdN
- The dot product between the direction and normal. This is the return value of addDiffuse.
-
initView
protected final void initView(javax.vecmath.Point3f kEye, SoftwareVertexProperty kVertexProperty)
Calculate the view direction based on the vertex and the eye point (in model coordinates). Reverse the direction of the normal vector if it is backfacing (relative to the view direction).- Parameters:
kEye
- Point3f The location of the observer. Usually this is the camera location, but it is not necessary.kVertexProperty
- SoftwareVertexProperty Contains the position of the point to be lit and the unit-length vector at the point.
-
normalize
protected final float normalize(javax.vecmath.Vector3f kV)
Replace a vector by a unit-length vector in the same direction. If the input vector is (nearly) the zero vector, the replacement vector is the zero vector.- Parameters:
kV
- the vector to be normalized- Returns:
- the length of the input vector
-
-