render
Class Material

java.lang.Object
  extended byrender.Material
All Implemented Interfaces:
java.lang.Runnable

public class Material
extends java.lang.Object
implements java.lang.Runnable

Deals with aspects of color and material properties of objects.

Stores color properties of material: diffuse light, specular light, and ambient light.
Holds information about transparency and whether the material is double sided.

Author:
Ken Perlin 2001

Field Summary
 boolean anisotropic
          Indicates whether the material is anisotropic (light reflection varies with respect to direction).
 boolean isDoubleSided
          Indicates whether the material is double sided.
 double noiseA
          Noise amplitude.
 double noiseF
          Noise frequency.
 int res
          Resolution of the material.
 int resP
          Bit depth of the resolution.
 boolean tableMode
          Flag determining wheter to precompute and store color tables for direct look up intead of on the fly computation.
 
Constructor Summary
Material()
           
 
Method Summary
 int computePixel(int[] data, int dx, int dy, int NB)
          Returns the packed integer of a particular pixel To do extra pixel computation, overload this method
 int countTable()
          Counts the non-zero entries in the lookup table.
 void getAmbient(double[] amb)
          Gets the ambient light components (r, g, b).
 void getDiffuse(double[] diff)
          Gets the diffuse color components in RGB (range 0 to 1).
 void getSpecular(double[] spec)
          Gets the specular components of color (r, g, b, exponent).
 int getTable(int ix, int iy, int iz)
          Looks up the appropriate color value from the table at x, y, z.
 Texture getTexture()
           
 double getTransparency()
          Returns the transparency of the material (0 transparent to 1 opaque).
 boolean hasTexture()
           
 void initTable(int p)
          Creates and initializes the lookup table to all black.
 boolean loadLookupTable(java.io.File saved)
          Reconstructs lookup table from output of lookupTableToString resP and res gets loaded as well returns whether or not succeeded
 boolean loadLookupTable(java.io.ObjectInputStream input)
           
 void recache()
           
 void run()
          Thread that runs in the background ( provided the resources are available - no mouse dragging for example) and computes the normal map table of values for quick look up later.
 boolean saveLookupTable(java.io.File file)
          Returns true if save was successful What it writes to the file: 1) first: resP 2) look up table's entries The output file of this is passed into loadlookupTable to recreate the material's lookup table without having to recalculate those values.
 Material setAmbient(double r, double g, double b)
          Sets the ambient lighting color values (range 0..1).
 Material setColor(double dr, double dg, double db)
          Sets the diffuse color of an object.
 Material setColor(double dr, double dg, double db, double dp)
          Sets the diffuse color of an object.
 Material setColor(double dr, double dg, double db, double sr, double sg, double sb, double sp)
          Sets the diffuse and specular values of color.
 Material setColor(double dr, double dg, double db, double dp, double sr, double sg, double sb, double sp)
          Sets the diffuse and specular values of color.
 Material setColor(double dr, double dg, double db, double sr, double sg, double sb, double sp, double ar, double ag, double ab)
          Sets the diffuse, specular and ambient values of color.
 Material setColor(double dr, double dg, double db, double dp, double sr, double sg, double sb, double sp, double ar, double ag, double ab)
          Sets the diffuse, specular and ambient values of color.
 Material setDiffuse(double r, double g, double b)
          Sets the diffuse components of light (range 0..1).
 Material setDiffuse(double r, double g, double b, double p)
          Sets the diffuse components of light (range 0..1).
 Material setDoubleSided(boolean t)
          Sets the double sided flag true to indicate whether the object is double sided.
 Material setSpecular(double r, double g, double b, double p)
          Sets the specular color components (r, g, b, exp).
 void setTable(int ix, int iy, int iz, int p)
          Sets the x, y, z, value in the lookup table to p.
 Material setTexture(Texture texel)
          Set a texture to the material.
 Material setTransparency(double t)
          Sets the transparency of the material (0 transparent to 1 opaque).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tableMode

public boolean tableMode
Flag determining wheter to precompute and store color tables for direct look up intead of on the fly computation.


resP

public int resP
Bit depth of the resolution.


res

public int res
Resolution of the material.


isDoubleSided

public boolean isDoubleSided
Indicates whether the material is double sided.


anisotropic

public boolean anisotropic
Indicates whether the material is anisotropic (light reflection varies with respect to direction).


noiseF

public double noiseF
Noise frequency.


noiseA

public double noiseA
Noise amplitude.

Constructor Detail

Material

public Material()
Method Detail

getTable

public int getTable(int ix,
                    int iy,
                    int iz)
Looks up the appropriate color value from the table at x, y, z.

Parameters:
ix - x
iy - y
iz - z
Returns:
the packed color value

setTable

public void setTable(int ix,
                     int iy,
                     int iz,
                     int p)
Sets the x, y, z, value in the lookup table to p.

Parameters:
ix - x
iy - y
iz - z
p - the packed color value

initTable

public void initTable(int p)
Creates and initializes the lookup table to all black.

Parameters:
p - bit depth resolution

countTable

public int countTable()
Counts the non-zero entries in the lookup table.

Returns:
the number of non-zero entries.

hasTexture

public boolean hasTexture()

setTexture

public Material setTexture(Texture texel)
Set a texture to the material. Need to bind the material to the geometry before calling mesh

Parameters:
texel -
Returns:

computePixel

public int computePixel(int[] data,
                        int dx,
                        int dy,
                        int NB)
Returns the packed integer of a particular pixel To do extra pixel computation, overload this method

Parameters:
data - array representing the pixel indices of data are: 0,1,2 are the x,y,z of the pixel 3,4,5 are the r,g,b values 6,7 are the u,v coordinates
dx - size of the pixel in x
dy - size of the pixel in y
NB - precision value

setDiffuse

public Material setDiffuse(double r,
                           double g,
                           double b)
Sets the diffuse components of light (range 0..1).

Parameters:
r - red
g - green
b - blue

setDiffuse

public Material setDiffuse(double r,
                           double g,
                           double b,
                           double p)
Sets the diffuse components of light (range 0..1).

Parameters:
r - red
g - green
b - blue
p - exponent

getDiffuse

public void getDiffuse(double[] diff)
Gets the diffuse color components in RGB (range 0 to 1).


setSpecular

public Material setSpecular(double r,
                            double g,
                            double b,
                            double p)
Sets the specular color components (r, g, b, exp).

Parameters:
r - red
g - green
b - blue
Returns:
the material

getSpecular

public void getSpecular(double[] spec)
Gets the specular components of color (r, g, b, exponent).

Parameters:
spec - array of doubles containing 4 specular light components

setAmbient

public Material setAmbient(double r,
                           double g,
                           double b)
Sets the ambient lighting color values (range 0..1).

Parameters:
r - red
g - green
b - blue
Returns:
the material

getAmbient

public void getAmbient(double[] amb)
Gets the ambient light components (r, g, b).


setColor

public Material setColor(double dr,
                         double dg,
                         double db)
Sets the diffuse color of an object.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double dp)
Sets the diffuse color of an object.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
dp - diffuse exponent
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double sr,
                         double sg,
                         double sb,
                         double sp)
Sets the diffuse and specular values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
sr - specular red
sg - specular green
sb - specular blue
sp - specular exponent
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double dp,
                         double sr,
                         double sg,
                         double sb,
                         double sp)
Sets the diffuse and specular values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
dp - diffuse exponent
sr - specular red
sg - specular green
sb - specular blue
sp - specular exponent
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double sr,
                         double sg,
                         double sb,
                         double sp,
                         double ar,
                         double ag,
                         double ab)
Sets the diffuse, specular and ambient values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
sr - specular red
sg - specular green
sb - specular blue
ar - ambient red
ag - ambient green
ab - ambient blue
Returns:
the material

setColor

public Material setColor(double dr,
                         double dg,
                         double db,
                         double dp,
                         double sr,
                         double sg,
                         double sb,
                         double sp,
                         double ar,
                         double ag,
                         double ab)
Sets the diffuse, specular and ambient values of color.

Parameters:
dr - diffuse red
dg - diffuse green
db - diffuse blue
dp - diffuse exponent
sr - specular red
sg - specular green
sb - specular blue
ar - ambient red
ag - ambient green
ab - ambient blue
Returns:
the material

getTexture

public Texture getTexture()

setDoubleSided

public Material setDoubleSided(boolean t)
Sets the double sided flag true to indicate whether the object is double sided.

Parameters:
t - new value of isDoubleSided
Returns:
the material

setTransparency

public Material setTransparency(double t)
Sets the transparency of the material (0 transparent to 1 opaque).

Parameters:
t - new transparency value
Returns:
the material

getTransparency

public double getTransparency()
Returns the transparency of the material (0 transparent to 1 opaque).

Returns:
the actual transparency of the material

recache

public void recache()

run

public void run()
Thread that runs in the background ( provided the resources are available - no mouse dragging for example) and computes the normal map table of values for quick look up later.

Specified by:
run in interface java.lang.Runnable

saveLookupTable

public boolean saveLookupTable(java.io.File file)
Returns true if save was successful What it writes to the file: 1) first: resP 2) look up table's entries The output file of this is passed into loadlookupTable to recreate the material's lookup table without having to recalculate those values. Assumes lookup table is done being constructed when this is called.


loadLookupTable

public boolean loadLookupTable(java.io.File saved)
Reconstructs lookup table from output of lookupTableToString resP and res gets loaded as well returns whether or not succeeded


loadLookupTable

public boolean loadLookupTable(java.io.ObjectInputStream input)