User Tools

Site Tools


tutorials:light-modeling-visualizing-light-rays

Visualizing light rays

Sometimes it is interesting to see the traces of light rays emitted by a light source when they travel through a scene. In GroIMP, this can be done using the integrated LightModelVisualizer.

To use it, all one needs to do is to add a LightModelVisualizer object into the scene. The two input parameter of the LightModelVisualizer class are defining the number of visualized light rays and the recursion depth the light rays are followed.

To calculate the light rays visualization, the LightModelVisualizer object needs to be selected, ether in the 3D View or 2D Graph Explorer.

protected void init () [
    Axiom ==> LightModelVisualizer(175, 10);
]

When selected, go to the Attribute Editor and press 'compute'.

The following scene (given in OpenGL view on the left and Wireframe on the right) contains one spot light with a very slight opening angle, producing a thin beam of light rays that is reflected by several mirrors before finally hitting the end screen or the red sphere in the front.

Please pay attention to the changing colour of the initial white rays when they are reflected or transmitted. Also interesting to notice are the inner reflections within the green box and the red sphere. And keep in mind that only rays that hit an object are visualized.

Given below, is the code to generate the above scene.

/**
 * To visualize the light rays, select the yellow point at the origin, 
 * go to the 'Attribute Editor' and press 'compute'.
 */
 
const Phong MIRROR = new Phong();
const Phong S1 = new Phong();
const Phong S2 = new Phong();
const Phong S3 = new Phong();
 
static {
   MIRROR.setSpecular(new Graytone(1));// 1
   MIRROR.setDiffuse(new Graytone(0));// 0
   MIRROR.setShininess(new Graytone(1));// 1
 
   S1.setDiffuse(new RGBColor(1,0,1));
   S1.setDiffuseTransparency(new RGBColor(0,1,0));  
 
   S2.setDiffuse(new Graytone(0.4));
   S2.setDiffuseTransparency(new Graytone(0.6));
 
   S3.setDiffuse(new RGBColor(1,0,0));
   S3.setDiffuseTransparency(new Graytone(0.7)); 
}
 
module Wall extends Parallelogram(0.6, 0.6);
 
 
protected void init () [
	Axiom ==> LightModelVisualizer(175, 10), 
		^ RU(90) RL(60) M(0.25)
		LightNode.(setLight(new SpotLight().(setPower(1000),setInnerAngle(0.0199),setOuterAngle(0.02))))
 
		, ^ Translate(0.7,-1,-0.25) Wall.(setShader(MIRROR)) // mirror 1
		, ^ Translate(1.75,1,-0.25) Wall.(setShader(MIRROR)) // mirror 2
		, ^ Translate(2.3,0,-0.25) Wall.(setShader(S1)) // semi-transparent 
		, ^ Translate(3.25,1.5,0) Sphere(0.5).(setShader(S3))
		, ^ Translate(3.25,-1.25,-0.5) RH(-45) Box(1.5,0.25,2).(setShader(S2)) 
		, ^ Translate(4.5,-2.5,-1.5) RH(45) Parallelogram(3,5).(setShader(BLACK)) 
		;
]
tutorials/light-modeling-visualizing-light-rays.txt · Last modified: 2025/01/11 18:40 by MH