org.sunflow.core.light

Class ImageBasedLight

Implemented Interfaces:
LightSource, PrimitiveList, RenderObject, Shader

public class ImageBasedLight
extends java.lang.Object
implements PrimitiveList, LightSource, Shader

Constructor Summary

ImageBasedLight()

Method Summary

PrimitiveList
getBakingPrimitives()
Create a new PrimitiveList object suitable for baking lightmaps.
int
getNumPrimitives()
Returns the number of individual primtives in this aggregate object.
int
getNumSamples()
Get the maximum number of samples that can be taken from this light source.
void
getPhoton(double randX1, double randY1, double randX2, double randY2, Point3 p, Vector3 dir, Color power)
Gets a photon to emit from this light source by setting each of the arguments.
float
getPower()
Get the total power emitted by this light source.
float
getPrimitiveBound(int primID, int i)
Retrieve the bounding box component of a particular primitive in object space.
Color
getRadiance(ShadingState state)
Gets the radiance for a specified rendering state.
void
getSamples(ShadingState state)
Samples the light source to compute direct illumination.
BoundingBox
getWorldBounds(Matrix4 o2w)
Compute a bounding box of this object in world space, using the specified object-to-world transformation matrix.
void
init(String name, SunflowAPI api)
void
intersectPrimitive(Ray r, int primID, IntersectionState state)
Intersect the specified primitive in local space.
void
prepareShadingState(ShadingState state)
Prepare the specified ShadingState by setting all of its internal parameters.
void
scatterPhoton(ShadingState state, Color power)
Scatter a photon with the specied power.
boolean
update(ParameterList pl, SunflowAPI api)
Update this object given a list of parameters.

Constructor Details

ImageBasedLight

public ImageBasedLight()

Method Details

getBakingPrimitives

public PrimitiveList getBakingPrimitives()
Create a new PrimitiveList object suitable for baking lightmaps. This means a set of primitives laid out in the unit square UV space. This method is optional, objects which do not support it should simply return null.
Specified by:
getBakingPrimitives in interface PrimitiveList
Returns:
a list of baking primitives

getNumPrimitives

public int getNumPrimitives()
Returns the number of individual primtives in this aggregate object.
Specified by:
getNumPrimitives in interface PrimitiveList
Returns:
number of primitives

getNumSamples

public int getNumSamples()
Get the maximum number of samples that can be taken from this light source. This is currently only used for statistics reporting.
Specified by:
getNumSamples in interface LightSource
Returns:
maximum number of samples to be taken from this light source

getPhoton

public void getPhoton(double randX1,
                      double randY1,
                      double randX2,
                      double randY2,
                      Point3 p,
                      Vector3 dir,
                      Color power)
Gets a photon to emit from this light source by setting each of the arguments. The two sampling parameters are points on the unit square that can be used to sample a position and/or direction for the emitted photon.
Specified by:
getPhoton in interface LightSource
Parameters:
randX1 - sampling parameter
randY1 - sampling parameter
randX2 - sampling parameter
randY2 - sampling parameter
p - position to shoot the photon from
dir - direction to shoot the photon in
power - power of the photon

getPower

public float getPower()
Get the total power emitted by this light source. Lights that have 0 power will not emit any photons.
Specified by:
getPower in interface LightSource
Returns:
light source power

getPrimitiveBound

public float getPrimitiveBound(int primID,
                               int i)
Retrieve the bounding box component of a particular primitive in object space. Even indexes get minimum values, while odd indexes get the maximum values for each axis.
Specified by:
getPrimitiveBound in interface PrimitiveList
Parameters:
primID - primitive index
i - bounding box side index
Returns:
value of the request bound

getRadiance

public Color getRadiance(ShadingState state)
Gets the radiance for a specified rendering state. When this method is called, you can assume that a hit has been registered in the state and that the hit surface information has been computed.
Specified by:
getRadiance in interface Shader
Parameters:
state - current render state
Returns:
color emitted or reflected by the shader

getSamples

public void getSamples(ShadingState state)
Samples the light source to compute direct illumination. Light samples can be created using the LightSample class and added to the current ShadingState. This method is responsible for the shooting of shadow rays which allows for non-physical lights that don't cast shadows. It is recommended that only a single shadow ray be shot if ShadingState.getDiffuseDepth() is greater than 0. This avoids an exponential number of shadow rays from being traced.
Specified by:
getSamples in interface LightSource
Parameters:
state - current state, including point to be shaded
See Also:
LightSample

getWorldBounds

public BoundingBox getWorldBounds(Matrix4 o2w)
Compute a bounding box of this object in world space, using the specified object-to-world transformation matrix. The bounds should be as exact as possible, if they are difficult or expensive to compute exactly, you may use Matrix4.transform(BoundingBox). If the matrix is null no transformation is needed, and object space is equivalent to world space.
Specified by:
getWorldBounds in interface PrimitiveList
Parameters:
o2w - object to world transformation matrix
Returns:
object bounding box in world space

init

public void init(String name,
                 SunflowAPI api)

intersectPrimitive

public void intersectPrimitive(Ray r,
                               int primID,
                               IntersectionState state)
Intersect the specified primitive in local space.
Specified by:
intersectPrimitive in interface PrimitiveList
Parameters:
r - ray in the object's local space
primID - primitive index to intersect
state - intersection state

prepareShadingState

public void prepareShadingState(ShadingState state)
Prepare the specified ShadingState by setting all of its internal parameters.
Specified by:
prepareShadingState in interface PrimitiveList
Parameters:
state - shading state to fill in

scatterPhoton

public void scatterPhoton(ShadingState state,
                          Color power)
Scatter a photon with the specied power. Incoming photon direction is specified by the ray attached to the current render state. This method can safely do nothing if photon scattering is not supported or relevant for the shader type.
Specified by:
scatterPhoton in interface Shader
Parameters:
state - current state
power - power of the incoming photon.

update

public boolean update(ParameterList pl,
                      SunflowAPI api)
Update this object given a list of parameters. This method is guarenteed to be called at least once on every object, but it should correctly handle empty parameter lists. This means that the object should be in a valid state from the time it is constructed. This method should also return true or false depending on whether the update was succesfull or not.
Specified by:
update in interface RenderObject
Parameters:
pl - list of parameters to read from
api - reference to the current scene
Returns:
true if the update is succesfull, false otherwise