/**
 * Java Modular Image Synthesis Toolkit (JMIST)
 * Copyright (C) 2008-2013 Bradley W. Kimmel
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package ca.eandb.jmist.framework.shader.ray;

import ca.eandb.jmist.framework.Intersection;
import ca.eandb.jmist.framework.RayCaster;
import ca.eandb.jmist.framework.RayShader;
import ca.eandb.jmist.framework.color.Color;
import ca.eandb.jmist.framework.color.ColorModel;
import ca.eandb.jmist.framework.color.Spectrum;
import ca.eandb.jmist.framework.color.WavelengthPacket;
import ca.eandb.jmist.math.Ray3;

/**
 * A ray shader that shades a ray according to the distance to the
 * nearest intersection along the ray.
 * @author Brad Kimmel
 */
public final class DistanceRayShader implements RayShader {

	/**
	 * Serialization version ID.
	 */
	private static final long serialVersionUID = -4530038647449382442L;

	/**
	 * Creates a <code>DistanceRayShader</code>.
	 * @param caster The <code>RayCaster</code> to use.
	 */
	public DistanceRayShader(RayCaster caster) {
		this(caster, null);
	}

	/**
	 * Creates a <code>DistanceRayShader</code>.
	 * @param caster The <code>RayCaster</code> to use.
	 * @param missValue The <code>Spectrum</code> to assign to rays that do not
	 * 		intersect with any object.
	 */
	public DistanceRayShader(RayCaster caster, Spectrum missValue) {
		this.caster = caster;
		this.missValue = missValue;
	}

	/* (non-Javadoc)
	 * @see ca.eandb.jmist.framework.RayShader#shadeRay(ca.eandb.jmist.math.Ray3, ca.eandb.jmist.framework.color.WavelengthPacket)
	 */
	public Color shadeRay(Ray3 ray, WavelengthPacket lambda) {
		Intersection x = this.caster.castRay(ray);
		ColorModel cm = lambda.getColorModel();

		return (x != null) ? cm.getGray(x.getDistance(), lambda) : (missValue != null) ? missValue.sample(lambda) : cm.getBlack(lambda);
	}

	/** The ray caster to use. */
	private final RayCaster caster;

	private final Spectrum missValue;

}

@@ -1302,23 +1302,41 @@
 amework.
-RayCast
+NearestIntersectionRecord
 er;%0Aimpo
@@ -1370,24 +1370,70 @@
 .RayShader;%0A
+import ca.eandb.jmist.framework.SceneElement;%0A
 import ca.ea
@@ -2015,38 +2015,36 @@
 de%3E.%0A%09 * @param 
-caster
+root
  The %3Ccode%3ERayCa
@@ -2034,33 +2034,36 @@
 t The %3Ccode%3E
-RayCaster
+SceneElement
 %3C/code%3E to u
@@ -2097,32 +2097,33 @@
 yShader(
-RayCaster caster
+SceneElement root
 ) %7B%0A%09%09th
@@ -2125,22 +2125,20 @@
 %0A%09%09this(
-caster
+root
 , null);
@@ -2204,22 +2204,20 @@
  @param 
-caster
+root
  The %3Cco
@@ -2219,25 +2219,28 @@
 e %3Ccode%3E
-RayCaster
+SceneElement
 %3C/code%3E 
@@ -2388,32 +2388,33 @@
 yShader(
-RayCaster caster
+SceneElement root
 , Spectr
@@ -2440,23 +2440,19 @@
 his.
-caster = caster
+root = root
 ;%0A%09%09
@@ -2717,31 +2717,72 @@
 x = 
-this.caster.castRay(ray
+NearestIntersectionRecorder.computeNearestIntersection(ray, root
 );%0A%09
@@ -3008,24 +3008,25 @@
 nal 
-RayCaster caster
+SceneElement root
 ;%0A%0A%09

Modify DistanceRayShader to use SceneElement