de.grogra.imp3d.shading
Class Phong

java.lang.Object
  extended by de.grogra.graph.impl.Edge
      extended by de.grogra.graph.impl.Node
          extended by de.grogra.imp3d.shading.ChannelMapNode
              extended by de.grogra.imp3d.shading.ColorMapNode
                  extended by de.grogra.imp3d.shading.Material
                      extended by de.grogra.imp3d.shading.Phong
All Implemented Interfaces:
Icon, IconSource, ChannelMap, ColorMap, Manageable, PersistenceCapable, Shareable, RenderedIcon, Scattering, Shader, UserFields, XObject, Map, java.io.Serializable

public class Phong
extends Material

A Phong shader represents a Phong-like reflector. Its bidirectional reflection/transmission distribution functions are as follows:

At a given point x, let cd be the diffuse color (components R, G, B) at that point, α the alpha-component of the diffuse color and ct the transparency color. For each color component, set

cαt = 1 + α (ct - 1)
Let cs be the specular color and n the shininess exponent. Let r be the reflection coefficient as computed by Math2.fresnel(javax.vecmath.Vector3f, javax.vecmath.Vector3f, float, javax.vecmath.Vector3f, javax.vecmath.Vector3f). The bidirectional reflection distribution function is
BRDF(x, ωi, ωo) = kd / π + ks (n + 2) max(cos β, 0)n / 2π
where β is the angle between ωi and the direction of ideal reflection of ωo.

The bidirectional transmission distribution function is

BTDF(x, ωi, ωt) = ktt / ηi)2 δω+i - T(ωt))
where η stands for the index of refraction, T for the direction of transmission according to Fresnel's formulas, and δω+ is the δ-distribution with respect to projected solid angle ω+.

Author:
Ole Kniemeyer
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class de.grogra.graph.impl.Node
Node.AccessorBridge, Node.FieldAttributeAccessor, Node.NType
 
Nested classes/interfaces inherited from interface de.grogra.util.Map
Map.Chain
 
Field Summary
static Node.NType $TYPE
           
static Node.NType.Field ambient$FIELD
           
static ColorMap DEFAULT_AMBIENT
           
static ColorMap DEFAULT_DIFFUSE
           
static ColorMap DEFAULT_DIFFUSE_TRANSPARENCY
           
static ColorMap DEFAULT_EMISSIVE
           
static float DEFAULT_SHININESS
           
static ColorMap DEFAULT_SPECULAR
           
static ColorMap DEFAULT_TRANSPARENCY
           
static float DEFAULT_TRANSPARENCY_SHININESS
           
static Node.NType.Field diffuse$FIELD
           
static Node.NType.Field diffuseTransparency$FIELD
           
static Node.NType.Field emissive$FIELD
           
static Node.NType.Field interpolatedTransparency$FIELD
           
static float MAX_SHININESS
           
static Node.NType.Field shininess$FIELD
           
static Node.NType.Field specular$FIELD
           
static Node.NType.Field transparency$FIELD
           
static Node.NType.Field transparencyShininess$FIELD
           
 
Fields inherited from class de.grogra.imp3d.shading.ChannelMapNode
AMBIENT, COLOR, COLOR_2, DIFFUSE_TRANSPARENCY, DISPLACEMENT, EMISSIVE, FIRST_OP, INPUT, input$FIELD, MIN_UNUSED_SPECIAL_OF_TARGET, SECOND_OP, SHININESS, SPECULAR, TRANSPARENCY, TRANSPARENCY_SHININESS
 
Fields inherited from class de.grogra.graph.impl.Node
ADDITIONAL_FIELDS, bits, DELETED, EXTENT_BIT, EXTENT_MASK, extentIndex$FIELD, extentTail$FIELD, HAS_OBSERVERS, IS_INTERPRETIVE, isInterpretive$FIELD, LAST_EXTENT_INDEX, layer$FIELD, MARK, mark$FIELD, MIME_TYPE, MIN_UNUSED_SPECIAL_OF_SOURCE, name$FIELD, USED_BITS
 
Fields inherited from interface de.grogra.ray.physics.Shader
LAMBERTIAN_VARIANCE
 
Fields inherited from interface de.grogra.ray.physics.Scattering
DELTA_FACTOR, IS_NON_OPAQUE, MIN_UNUSED_FLAG, NEEDS_NORMAL, NEEDS_POINT, NEEDS_TANGENTS, NEEDS_TRANSFORMATION, NEEDS_UV, RANDOM_RAYS_GENERATE_ORIGINS
 
Fields inherited from interface de.grogra.icon.Icon
DEFAULT, DISABLED
 
Fields inherited from interface de.grogra.util.Map
DEFAULT_VALUE, EMPTY_MAP
 
Constructor Summary
Phong()
           
 
Method Summary
 void accept(ChannelMapNodeVisitor visitor)
           
 void accept(ShaderVisitor visitor)
           
 Phong clone()
           
 float computeBSDF(Environment env, Vector3f in, Spectrum specIn, Vector3f out, boolean adjoint, Spectrum bsdf)
          Evaluates bidirectional scattering distribution function for given input.
 void computeMaxRays(Environment env, Vector3f out, Spectrum outSpec, Ray reflected, Tuple3f refVariance, Ray transmitted, Tuple3f transVariance)
          Computes, for the given input, the reflected and transmitted importance rays for which the reflection/transmission probability densities (integrated over the spectrum) attain a maximum.
static float convertShininess(float x)
           
static Phong createPhong()
           
 void generateRandomRays(Environment env, Vector3f out, Spectrum specOut, RayList rays, boolean adjoint, java.util.Random rnd)
          Pseudorandomly generates, for the given input, a set of scattered rays.
 ChannelMap getAmbient()
           
 int getAverageColor()
          Returns an average color for the scattering entity.
 ChannelMap getDiffuse()
           
 ChannelMap getDiffuseTransparency()
           
 ChannelMap getEmissive()
           
 int getFlags()
           
protected  Node.NType getNTypeImpl()
          This method returns the Node.NType which describes the managed fields of the class of this node.
 ChannelMap getShininess()
           
 ChannelMap getSpecular()
           
 ChannelMap getTransparency()
           
 ChannelMap getTransparencyShininess()
           
 boolean isInterpolatedTransparency()
           
 boolean isTransparent()
           
static void main(java.lang.String[] args)
           
protected  Node newInstance()
          This method returns a new instance of the class of this node.
 void setAmbient(ChannelMap value)
           
 void setDiffuse(ChannelMap value)
           
 void setDiffuseTransparency(ChannelMap value)
           
 void setEmissive(ChannelMap value)
           
 void setInterpolatedTransparency(boolean value)
           
 void setShininess(ChannelMap value)
           
 void setSpecular(ChannelMap value)
           
 void setTransparency(ChannelMap value)
           
 void setTransparencyShininess(ChannelMap value)
           
 void shade(Environment env, RayList rays, Vector3f out, Spectrum outSpec, Tuple3d outColor)
          Computes color of outgoing light ray for given input.
 
Methods inherited from class de.grogra.imp3d.shading.Material
renderLine, renderLine
 
Methods inherited from class de.grogra.imp3d.shading.ColorMapNode
drawImage, getIcon, getIconBounds, getIconSource, getImage, getImage, getImageSource, getInputData, getPreferredIconSize, getRenderedImage, getSizeRatio, isMutable, paintIcon, prepareIcon, renderImage
 
Methods inherited from class de.grogra.imp3d.shading.ChannelMapNode
accept, getFloatValue, getInput, getObjectValue, setInput
 
Methods inherited from class de.grogra.graph.impl.Node
addEdgeBitsTo, addReference, appendBranchNode, appendBranchNode, appendReferencesTo, clone, cloneGraph, dump, dumpTree, dup, dupUnmanagedFields, edgeChanged, fieldModified, findAdjacent, get, getAccessor, getAccessor, getAttributes, getAxisParent, getBoolean, getBranch, getBranchLength, getBranchNode, getBranchTail, getByte, getChar, getCommonAncestor, getCurrentGraphState, getDirectChildCount, getDouble, getEdgeAttributeAccessor, getEdgeAttributes, getEdgeBitsTo, getEdgeTo, getExtentIndex, getFirst, getFirstEdge, getFloat, getGraph, getId, getIndex, getInstantiator, getInt, getLayer, getLong, getManageableType, getName, getNeighbor, getNext, getNType, getObject, getOrCreateEdgeTo, getOrNull, getPersistenceManager, getPredecessor, getProvider, getShort, getSource, getStamp, getSuccessor, getSymbol, getSymbolColor, getTarget, getTransaction, getUserField, getUserFieldCount, getXClass, getXData, hasName, initProvider, initXClass, insertBranchNode, insertBranchNode, instantiateGraph, isAncestorOf, isDirection, isManagingInstance, isMarked, isRoot, isSource, isTarget, manageableReadResolve, manageableWriteReplace, paramString, removeAll, removeEdgeBitsTo, removeFromChain, removeFromChain, removeReference, setBranch, setBranch, setExtentIndex, setGraphForDeserialization, setLayer, setMark, setName, setSuccessor, setSuccessor, specialEdgeAdded, specialEdgeRefModified, specialEdgeRemoved, toString, writeReplace
 
Methods inherited from class de.grogra.graph.impl.Edge
addEdgeBits, getBitMark, getEdgeBits, getObjectMark, getSpecialEdgeDescriptor, parseEdgeKeys, remove, removeEdgeBits, setBitMark, setEdgeBits, setObjectMark, testEdgeBits
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.grogra.math.ChannelMap
accept, getFloatValue, getObjectValue, getStamp
 
Methods inherited from interface de.grogra.pf.ui.RenderedIcon
getStamp
 
Methods inherited from interface de.grogra.persistence.PersistenceCapable
getBitMark, getObjectMark, setBitMark, setObjectMark
 

Field Detail

$TYPE

public static final Node.NType $TYPE

ambient$FIELD

public static final Node.NType.Field ambient$FIELD

DEFAULT_AMBIENT

public static final ColorMap DEFAULT_AMBIENT

DEFAULT_DIFFUSE

public static final ColorMap DEFAULT_DIFFUSE

DEFAULT_DIFFUSE_TRANSPARENCY

public static final ColorMap DEFAULT_DIFFUSE_TRANSPARENCY

DEFAULT_EMISSIVE

public static final ColorMap DEFAULT_EMISSIVE

DEFAULT_SHININESS

public static final float DEFAULT_SHININESS
See Also:
Constant Field Values

DEFAULT_SPECULAR

public static final ColorMap DEFAULT_SPECULAR

DEFAULT_TRANSPARENCY

public static final ColorMap DEFAULT_TRANSPARENCY

DEFAULT_TRANSPARENCY_SHININESS

public static final float DEFAULT_TRANSPARENCY_SHININESS
See Also:
Constant Field Values

diffuse$FIELD

public static final Node.NType.Field diffuse$FIELD

diffuseTransparency$FIELD

public static final Node.NType.Field diffuseTransparency$FIELD

emissive$FIELD

public static final Node.NType.Field emissive$FIELD

interpolatedTransparency$FIELD

public static final Node.NType.Field interpolatedTransparency$FIELD

MAX_SHININESS

public static final float MAX_SHININESS
See Also:
Constant Field Values

shininess$FIELD

public static final Node.NType.Field shininess$FIELD

specular$FIELD

public static final Node.NType.Field specular$FIELD

transparency$FIELD

public static final Node.NType.Field transparency$FIELD

transparencyShininess$FIELD

public static final Node.NType.Field transparencyShininess$FIELD
Constructor Detail

Phong

public Phong()
Method Detail

accept

public void accept(ChannelMapNodeVisitor visitor)
Overrides:
accept in class ChannelMapNode

accept

public void accept(ShaderVisitor visitor)

clone

public Phong clone()
Overrides:
clone in class Node

computeBSDF

public float computeBSDF(Environment env,
                         Vector3f in,
                         Spectrum specIn,
                         Vector3f out,
                         boolean adjoint,
                         Spectrum bsdf)
Description copied from interface: Scattering
Evaluates bidirectional scattering distribution function for given input.

The computed spectrum is an integral over the spectrum of the following product:

|cos θ| BSDF(ωi, νi; ωo, νo)
where BSDF is the bidirectional scattering distribution function (= BRDF + BTDF) at the point env.point, ωi the (negated) direction of the incoming light ray, νi the frequency where the incoming ray is sampled, ωo the direction of the outgoing light ray, νo the frequency where the outgoing ray is sampled, and θ the angle between the surface normal and out.

If adjoint is false, in and out describe true light rays from light sources to sensors. In this case, ωi = in, ωo = out, and the integral is

bsdf(ν) = |cos θ| ∫ BSDF(in, νi; out, ν) specIni) dνi
Otherwise, adjoint is true. in and out then describe importance rays (inverse light rays from sensors to light sources). In this case, ωi = out, ωo = in, and the integral is
bsdf(ν) = |cos θ| ∫ BSDF(out, ν; in, νo) specIno) dνo

If this Scattering instance is in fact a Light source, adjoint is false, and the BSDF is defined as BSDF(in, μ; ω, ν) = L1(ω, ν) δ(μ - ν), i.e., the directional distribution of the emitted radiance at env.point, see Emitter. In this case, in is not used.

If this Scattering instance is in fact a Sensor, adjoint is true, and the BSDF is defined as BSDF(ω, ν; in, μ) = W1(ω, ν) δ(μ - ν), i.e., the directional distribution of the emitted importance at env.point, see Emitter. In this case, in is not used.

The computation should be physically valid. This excludes, e.g., ambient or emissive light contributions.

The returned value is the value of the probability density pω that would be calculated by Scattering.generateRandomRays(de.grogra.ray.physics.Environment, javax.vecmath.Vector3f, de.grogra.ray.physics.Spectrum, de.grogra.ray.util.RayList, boolean, java.util.Random) if the ray happened to be one of the randomly generated rays.

Parameters:
env - the environment for scattering
in - the (negated) direction unit vector of the incoming ray (i.e., pointing away from the surface)
specIn - the spectrum of the incoming ray
out - the direction unit vector of the outgoing ray (i.e., pointing away from the surface)
adjoint - light ray or importance ray?
bsdf - the computed spectrum of the outgoing ray will be placed in here
Returns:
the value of the probability density for the ray direction

computeMaxRays

public void computeMaxRays(Environment env,
                           Vector3f out,
                           Spectrum outSpec,
                           Ray reflected,
                           Tuple3f refVariance,
                           Ray transmitted,
                           Tuple3f transVariance)
Description copied from interface: Shader
Computes, for the given input, the reflected and transmitted importance rays for which the reflection/transmission probability densities (integrated over the spectrum) attain a maximum. The reflection probability density (measured with respect to solid angle) for the outgoing importance direction (i.e., incoming light direction) ω, given a fixed incident direction in, is
pr(ω) = cos θ BRDF(ω, in) / R
where BRDF is the bidirectional reflectivity distribution function, θ the angle between the surface normal and ω, and R the total reflectivity for the incident direction, i.e., the integral over cos θ BRDF(ω, in). The transmission probability density is defined correspondingly.

The color-fields are set to the total reflectivity/transparency for the incident direction for each color component R, G, B. Thus, for physically plausible BRDF/BTDF, the component-wise sum of reflected.color and transmitted.color lies in the interval [0, 1], and the difference to 1 is the amount absorbed.

The color may be zero if there is no reflected or transmitted ray, respectively, i.e., if the surface is fully transparent, opaque, or absorbing. The origin-fields of the rays will never be set.

The computed variances are defined to be, for each color component, (approximations for) the angular mean quadratic deviations of the densities from the returned maximal ray directions. E.g., for perfect reflection/transmission, these variances are zero, whereas for a perfect lambertian reflector, the variance of reflection is ∫ cos θ (1 / π) θ2 dω = (π2 - 4) / 8. This is the value of Shader.LAMBERTIAN_VARIANCE.

The ray properties which are not mentioned are neither used nor modified. These are the origin and its density, and the direction density.

Parameters:
env - the environment for scattering
out - the (negated) direction unit vector of the incoming ray (i.e., pointing away from the surface)
outSpec - spectrum of incoming ray
reflected - the reflected ray with maximal probability
refVariance - the angular mean quadratic deviation from reflected
transmitted - the transmitted ray with maximal probability
transVariance - the angular mean quadratic deviation from transmitted

convertShininess

public static float convertShininess(float x)

createPhong

public static Phong createPhong()

generateRandomRays

public void generateRandomRays(Environment env,
                               Vector3f out,
                               Spectrum specOut,
                               RayList rays,
                               boolean adjoint,
                               java.util.Random rnd)
Description copied from interface: Scattering
Pseudorandomly generates, for the given input, a set of scattered rays. The scattered rays are generated such that they can be used for a Monte Carlo integration of a function f(ω;ν) over cos θ BSDF(ωi, νi; ωo, νo) in the following way: Let di and si denote the directions and spectra of the N generated rays (N = rays.size). Then, for every frequency ν the sum
1 / N ∑i si(ν) f(di; ν)
is an unbiased estimate for the integral
∫ cos θ f(ω; ν) g(ω, ν; out, μ) specOut(μ) dμ dω
θ is the angle between the surface normal and ω. The domain of integration is the whole sphere, since the bidirectional scattering distribution includes both reflection and transmission (BSDF = BRDF + BTDF).

If this Scattering instance is in fact a Light source, adjoint is true, and the BSDF is defined as BSDF(out, μ; ω, ν) = L1(ω, ν) δ(μ - ν), i.e., the directional distribution of the emitted radiance at env.point, see Emitter. In this case, out is not used.

If this Scattering instance is in fact a Sensor, adjoint is false, and the BSDF is defined as BSDF(ω, ν; out, μ) = W1(ω, ν) δ(μ - ν), i.e., the directional distribution of the emitted importance at env.point, see Emitter. In this case, out is not used.

Let pω be the probability density used for the ray direction (measured with respect to solid angle ω), then the field directionDensity of the ray i is set to pω(di). For ideal specular reflection or transmission, or for directional lights or sensors, pω is not a regular function, the value directionDensity will be set to a multiple of Scattering.DELTA_FACTOR.

The ray properties which are not mentioned in the given formulas are neither used nor modified. These are the origin and its density.

Parameters:
env - the environment for scattering
out - the direction unit vector of the outgoing ray (i.e., pointing away from the surface)
specOut - the spectrum of the outgoing ray
rays - the rays to be generated
adjoint - represents out a light ray or an importance ray?
rnd - pseudorandom generator
See Also:
Scattering.computeBSDF(de.grogra.ray.physics.Environment, javax.vecmath.Vector3f, de.grogra.ray.physics.Spectrum, javax.vecmath.Vector3f, boolean, de.grogra.ray.physics.Spectrum)

getAmbient

public ChannelMap getAmbient()

getAverageColor

public int getAverageColor()
Description copied from interface: Scattering
Returns an average color for the scattering entity. This color is used for simplified graphical representations of the corresponding objects.

Returns:
an average color in Java's default sRGB color space, encoded as an int (0xAARRGGBB).

getDiffuse

public ChannelMap getDiffuse()

getDiffuseTransparency

public ChannelMap getDiffuseTransparency()

getEmissive

public ChannelMap getEmissive()

getFlags

public int getFlags()

getNTypeImpl

protected Node.NType getNTypeImpl()
Description copied from class: Node
This method returns the Node.NType which describes the managed fields of the class of this node. This method has to be implemented in every concrete subclass.

Overrides:
getNTypeImpl in class Node
Returns:
type describing the managed fields of the class of this node

getShininess

public ChannelMap getShininess()

getSpecular

public ChannelMap getSpecular()

getTransparency

public ChannelMap getTransparency()

getTransparencyShininess

public ChannelMap getTransparencyShininess()

isInterpolatedTransparency

public boolean isInterpolatedTransparency()

isTransparent

public boolean isTransparent()

main

public static void main(java.lang.String[] args)

newInstance

protected Node newInstance()
Description copied from class: Node
This method returns a new instance of the class of this node. This method has to be implemented in every concrete subclass.

Overrides:
newInstance in class Node
Returns:
new instance of class of this node

setAmbient

public void setAmbient(ChannelMap value)

setDiffuse

public void setDiffuse(ChannelMap value)

setDiffuseTransparency

public void setDiffuseTransparency(ChannelMap value)

setEmissive

public void setEmissive(ChannelMap value)

setInterpolatedTransparency

public void setInterpolatedTransparency(boolean value)

setShininess

public void setShininess(ChannelMap value)

setSpecular

public void setSpecular(ChannelMap value)

setTransparency

public void setTransparency(ChannelMap value)

setTransparencyShininess

public void setTransparencyShininess(ChannelMap value)

shade

public void shade(Environment env,
                  RayList rays,
                  Vector3f out,
                  Spectrum outSpec,
                  Tuple3d outColor)
Description copied from interface: Shader
Computes color of outgoing light ray for given input. The computed value is, for each color component j = R, G, B, the following sum over all incident rays k:
k |cos θk| BSDFjk, out) ck,j
where BSDFj is the bidirectional scattering distribution function (= BRDF + BTDF) at the point env.point, ωk and ck the direction and color of ray k, and θk the angle between the surface normal and ωk.

The computation may include physically invalid contributions, which may not fit into the formula above, e.g., ambient or emissive light contributions.

Parameters:
env - the environment for scattering
rays - the incoming rays
out - the direction unit vector of the outgoing ray (i.e., pointing away from the surface)
outSpec - spectrum of outgoing ray
outColor - the output color will be placed in here