net.sf.j3d.threeD.raytracer.engine
Class RayTracingEngine

java.lang.Object
  extended by net.sf.j3d.threeD.raytracer.engine.RayTracingEngine

public class RayTracingEngine
extends Object

The RayTracingEngine class provides static methods for rendering scenes.

Author:
Mike Murray

Field Summary
static RGB black
           
static boolean castShadows
          Controls wether or not shadow casting will be done during rendering.
static double dropOffDistance
           
static double e
          A very small value (0.00000001) that is used in '>=' and '<=' operations to account for computational errors.
static boolean inProgress
          This value will be set to true when a render method starts and false when all render methods end.
static boolean premultiplyIntensity
          Controls wether the color of a point light source will be adjusted based on the intensity of the point light or wether this will be left up to the shader.
static boolean useRouletteFogSamples
          Controls the method for rendering fog in areas where no object is in view.
 
Constructor Summary
RayTracingEngine()
           
 
Method Summary
static RGB ambientLightingCalculation(Vector point, Vector rayDirection, Surface surface, Surface[] otherSurfaces, AmbientLight light)
          Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified AmbientLight object and returns an RGB object that represents the color of the point.
static double calculateAverageBrightness(Scene scene, int width, int height, int itr)
           
static double calculateAverageBrightness(Scene scene, int width, int height, int ssWidth, int ssHeight, int itr)
           
static double calculateAverageBrightness(Scene scene, int x, int y, int dx, int dy, int width, int height, int ssWidth, int ssHeight, int itr)
           
static Intersection closestIntersection(Ray ray, Surface[] surfaces)
          Returns an Intersection object that represents the closest intersection (>= RayTracingEngine.e) between a surface in the specified array of Surface objects and the ray represented by the specified Ray object.
static double closestIntersectionAt(Intersection intersect)
          Returns the value (>= RayTracingEngine.e) of the closest intersection point of the specified Intersection object If there are no positive intersections, -1.0 is returned.
static RGB directionalAmbientLightingCalculation(Vector point, Vector rayDirection, Surface surface, Surface[] otherSurfaces, DirectionalAmbientLight light, Light[] otherLights, ShaderParameters p)
          Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified DirectionalAmbientLight object and returns an RGB object that represents the color of the point.
static RGB lightingCalculation(Ray r, Surface[] allSurfaces, Light[] allLights, RGB fog, double fd, double fr, ShaderParameters p)
          Performs intersection and lighting calculations for the specified Ray, Surfaces, and Lights.
static RGB lightingCalculation(Vector point, Vector rayDirection, Surface surface, Surface[] otherSurfaces, Light[] lights, ShaderParameters p)
          Performs the lighting calculations for the specified surface at the specified point of intersection on that surface using the lighting data from the specified Light objects and returns an RGB object that represents the color of the point.
static RGB lightingCalculation(Vector point, Vector rayDirection, Surface surface, Surface[] otherSurfaces, Light light, Light[] otherLights, ShaderParameters p)
          Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified Light object and returns an RGB object that represents the color of the point.
static RGB pointLightingCalculation(Vector point, Vector rayDirection, Surface surface, Surface[] otherSurfaces, PointLight light, Light[] otherLights, ShaderParameters p)
          Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified PointLight object and returns an RGB object that represents the color of the point.
static Vector reflect(Vector vector, Vector normal)
          Reflects the specified Vector object across the normal vector represented by the second specified Vector object and returns the result.
static Vector refract(Vector vector, Vector normal, double ni, double nr, boolean v)
          Refracts the specified Vector object based on the specified normal vector and 2 specified indices of refraction.
static RGB[][] render(Scene scene, int x, int y, int dx, int dy, int width, int height, int ssWidth, int ssHeight, ProgressMonitor monitor)
           
static RGB[][] render(Scene scene, int width, int height, int ssWidth, int ssHeight, ProgressMonitor monitor)
          Computes all intersection and lighting calculations required to produce an image of the specified width and height that is a rendering of the specified Scene object and returns the image as an array of RGB objects.
static RGB[][] render(Scene scene, RenderParameters p, ProgressMonitor monitor)
          Renders the specified scene.
static RGB[][] render(Surface[] surfaces, Camera camera, Light[] lights, RenderParameters p, ProgressMonitor monitor)
          Computes all intersection and lighting calculations required to produce an image of the specified width and height that is a rendering of the specified set of Surface objects using the data from the specified Camera and Light object.
static Light[] separateLights(int index, Light[] allLights)
          Removes the Light object at the specified index from the specified Light object array and returns the new array.
static Surface[] separateSurfaces(int index, Surface[] allSurfaces)
          Removes the Surface object at the specified index from the specified Surface object array and returns the new array.
static Surface[] separateSurfaces(Surface surface, Surface[] allSurfaces)
          Removes the specified Surface object from the specified Surface object array and returns the new array.
static boolean shadowCalculation(Vector point, Surface[] surfaces, Light light)
          Performs the shadow calculations for the specified surfaces at the specified point using the data from the specified Light object.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

castShadows

public static boolean castShadows
Controls wether or not shadow casting will be done during rendering. By default set to true.


premultiplyIntensity

public static boolean premultiplyIntensity
Controls wether the color of a point light source will be adjusted based on the intensity of the point light or wether this will be left up to the shader. By default set to true.


inProgress

public static boolean inProgress
This value will be set to true when a render method starts and false when all render methods end.


useRouletteFogSamples

public static boolean useRouletteFogSamples
Controls the method for rendering fog in areas where no object is in view. If set to true, the fog will be mixed in with probability equal to the fog density times the drop off distance. Otherwise, the background color will be the fog color times the fog ratio.


dropOffDistance

public static double dropOffDistance

black

public static RGB black

e

public static final double e
A very small value (0.00000001) that is used in '>=' and '<=' operations to account for computational errors.

See Also:
Constant Field Values
Constructor Detail

RayTracingEngine

public RayTracingEngine()
Method Detail

render

public static RGB[][] render(Scene scene,
                             int width,
                             int height,
                             int ssWidth,
                             int ssHeight,
                             ProgressMonitor monitor)
Computes all intersection and lighting calculations required to produce an image of the specified width and height that is a rendering of the specified Scene object and returns the image as an array of RGB objects. The image is anti-aliased using the specified supersampling width (ssWidth) and height (ssHeight). and progress is reported to the specified ProgressMonitor object.


render

public static RGB[][] render(Scene scene,
                             int x,
                             int y,
                             int dx,
                             int dy,
                             int width,
                             int height,
                             int ssWidth,
                             int ssHeight,
                             ProgressMonitor monitor)

render

public static RGB[][] render(Scene scene,
                             RenderParameters p,
                             ProgressMonitor monitor)
Renders the specified scene.

Parameters:
scene - Scene object to render.
p - RenderParamters object to use.
monitor - ProgressMonitor to use.
Returns:
Rendered image data.

render

public static RGB[][] render(Surface[] surfaces,
                             Camera camera,
                             Light[] lights,
                             RenderParameters p,
                             ProgressMonitor monitor)
Computes all intersection and lighting calculations required to produce an image of the specified width and height that is a rendering of the specified set of Surface objects using the data from the specified Camera and Light object. The image is anti-aliased using the specified supersampling width (ssWidth) and height (ssHeight) and progress is reported to the specified ProgressMonitor object. The image is returned as an array of RGB objects.

Parameters:
surfaces - Surface objects in scene.
camera - Camera object for scene.
lights - Light objects in scene.
x - X coordinate of upper left corner of image.
y - Y coordinate of upper left corner of image.
dx - Width of image.
dy - Height of image.
width - Width of total image.
height - Height of total image.
ssWidth - Supersample width.
ssHeight - Supersample height.
monitor - ProgressMonitor instance to use.
Returns:
Image data.

calculateAverageBrightness

public static double calculateAverageBrightness(Scene scene,
                                                int width,
                                                int height,
                                                int itr)

calculateAverageBrightness

public static double calculateAverageBrightness(Scene scene,
                                                int width,
                                                int height,
                                                int ssWidth,
                                                int ssHeight,
                                                int itr)

calculateAverageBrightness

public static double calculateAverageBrightness(Scene scene,
                                                int x,
                                                int y,
                                                int dx,
                                                int dy,
                                                int width,
                                                int height,
                                                int ssWidth,
                                                int ssHeight,
                                                int itr)

lightingCalculation

public static RGB lightingCalculation(Ray r,
                                      Surface[] allSurfaces,
                                      Light[] allLights,
                                      RGB fog,
                                      double fd,
                                      double fr,
                                      ShaderParameters p)
Performs intersection and lighting calculations for the specified Ray, Surfaces, and Lights. This method may return null, which should be interpreted as black (or "nothing").


lightingCalculation

public static RGB lightingCalculation(Vector point,
                                      Vector rayDirection,
                                      Surface surface,
                                      Surface[] otherSurfaces,
                                      Light[] lights,
                                      ShaderParameters p)
Performs the lighting calculations for the specified surface at the specified point of intersection on that surface using the lighting data from the specified Light objects and returns an RGB object that represents the color of the point. A list of all other surfaces in the scene must be specified for reflection/shadowing. This list does not include the specified surface for which the lighting calculations are to be done.


lightingCalculation

public static RGB lightingCalculation(Vector point,
                                      Vector rayDirection,
                                      Surface surface,
                                      Surface[] otherSurfaces,
                                      Light light,
                                      Light[] otherLights,
                                      ShaderParameters p)
Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified Light object and returns an RGB object that represents the color of the point. A list of all other surfaces in the scene must be specified for reflection/shadowing. This list does not include the specified surface for which the lighting calculations are to be done.


ambientLightingCalculation

public static RGB ambientLightingCalculation(Vector point,
                                             Vector rayDirection,
                                             Surface surface,
                                             Surface[] otherSurfaces,
                                             AmbientLight light)
Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified AmbientLight object and returns an RGB object that represents the color of the point. A list of all other surfaces in the scene must be specified for reflection/shadowing. This list does not include the specified surface for which the lighting calculations are to be done.


directionalAmbientLightingCalculation

public static RGB directionalAmbientLightingCalculation(Vector point,
                                                        Vector rayDirection,
                                                        Surface surface,
                                                        Surface[] otherSurfaces,
                                                        DirectionalAmbientLight light,
                                                        Light[] otherLights,
                                                        ShaderParameters p)
Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified DirectionalAmbientLight object and returns an RGB object that represents the color of the point. A list of all other surfaces in the scene must be specified for reflection/shadowing. This list does not include the specified surface for which the lighting calculations are to be done.

Parameters:
point - The intersection point on the surface to be shaded.
rayDirection - Direction of the ray that intersected the surface to be shaded.
surface - The Surface object to use for shading calculations.
otherSurfaces - An array of Surface objects that are also in the scene.
light - The DirectionalAmbientLight instance to use for shading calculations.
otherLights[] - An array of Light objects that are also in the scene.
p - A ShaderParameters object that stores all parameters that are persisted during a single set of ray casting events (reflections, refractions, etc.) (null accepted).

pointLightingCalculation

public static RGB pointLightingCalculation(Vector point,
                                           Vector rayDirection,
                                           Surface surface,
                                           Surface[] otherSurfaces,
                                           PointLight light,
                                           Light[] otherLights,
                                           ShaderParameters p)
Performs the lighting calculations for the specified surface at the specified point of interesection on that surface using the lighting data from the specified PointLight object and returns an RGB object that represents the color of the point. A list of all other surfaces in the scene must be specified for reflection/shadowing. This list does not include the specified surface for which the lighting calculations are to be done. If the premultiplyIntensity option is set to true the color of the point light will be adjusted by the intensity of the light and the intensity will then be set to 1.0. If the premultiplyIntensity option is set to false, the color will be left unattenuated and the shaders will be responsible for adjusting the color based on intensity.


shadowCalculation

public static boolean shadowCalculation(Vector point,
                                        Surface[] surfaces,
                                        Light light)
Performs the shadow calculations for the specified surfaces at the specified point using the data from the specified Light object. Returns true if the point has a shadow cast on it.


reflect

public static Vector reflect(Vector vector,
                             Vector normal)
Reflects the specified Vector object across the normal vector represented by the second specified Vector object and returns the result.


refract

public static Vector refract(Vector vector,
                             Vector normal,
                             double ni,
                             double nr,
                             boolean v)
Refracts the specified Vector object based on the specified normal vector and 2 specified indices of refraction.

Parameters:
vector - A Vector object representing a unit vector in the direction of the incident ray normal A Vector object respresenting a unit vector that is normal to the surface refracting the ray ni A double value representing the index of refraction of the incident medium nr A double value representing the index of refraction of the refracting medium

closestIntersection

public static Intersection closestIntersection(Ray ray,
                                               Surface[] surfaces)
Returns an Intersection object that represents the closest intersection (>= RayTracingEngine.e) between a surface in the specified array of Surface objects and the ray represented by the specified Ray object. If there are no intersections >= RayTracingEngine.e then null is returned.


closestIntersectionAt

public static double closestIntersectionAt(Intersection intersect)
Returns the value (>= RayTracingEngine.e) of the closest intersection point of the specified Intersection object If there are no positive intersections, -1.0 is returned.


separateLights

public static Light[] separateLights(int index,
                                     Light[] allLights)
Removes the Light object at the specified index from the specified Light object array and returns the new array.


separateSurfaces

public static Surface[] separateSurfaces(int index,
                                         Surface[] allSurfaces)
Removes the Surface object at the specified index from the specified Surface object array and returns the new array.


separateSurfaces

public static Surface[] separateSurfaces(Surface surface,
                                         Surface[] allSurfaces)
Removes the specified Surface object from the specified Surface object array and returns the new array. If the specified Surface object is not matched, the whole array is returned.