LRay - Java Raytracer

LRay is a Java reference raytracer. It demonstrates the basic principles of raytracing and is easy to expand to feature other primitives and textures.

Articles

The renderer makes several passes at successively higher resolutions, the last one for anti-aliasing.

Java applet, run by CheerpJ. Main class: LRay

Primitives:

Currently supports spheres and planes but the structure is in place to make any other primitives. The code needs to be restructured to perform CSG and for general efficiency reasons.

Textures:

At the moment just reflection and procedural colour maps. Added fuzzy diffuse reflection but it makes rendering really slow (looks lovely though!).

Creating Scenes

The scene is set up inside the LRay.run() method using the scene generation API:

Texture texOrange = new Texture(1.0, 0.7, 0.0, 0.0, 0.5);
Texture texPurple = new Texture(0.7, 0.0, 1.0, 0.0, 0.5);
Texture texWhite  = new Texture(1.0, 1.0, 1.0, 0.0, 0.7);
Texture texBlack  = new Texture(0.0, 0.0, 0.0, 0.0, 0.0);
Texture texMirror  = new Texture(0.45, 0.45, 0.45, 0.0, 0.7);
Texture texChecks  = new Texture(new ChecksColourMap(0.6, 0.6, 0.6, 0.3, 0.3, 0.3), 0.7);
Texture texSky  = new Texture(new ChecksColourMap(0.6, 0.8, 1.0, 0.2, 0.3, 0.5), 0.3);

Scene s = new Scene();

s.addLight(new Light(1.0, 5.0, 2.0, 1.0, 1.0, 1.0));
s.addLight(new Light(-1.0, 7.0, 3.0, 0.7, 0.7, 0.7));

s.addEntity(new Plane( 0.0, 1.0,  0.0, -1.5, texChecks));

s.addEntity(new Sphere( 1.0, -1.0, 6.0, 1.0, texOrange));
s.addEntity(new Sphere( 1.0,  3.0, 6.0, 1.5, texPurple));
s.addEntity(new Sphere(-1.0,  2.0, 5.0, 1.2, texSky));

s.addEntity(new Sphere(-3.0,  1.0, 6.0, 1.5, texWhite ));
s.addEntity(new Sphere(-3.0, -1.0, 6.0, 1.5, texPurple));

s.addEntity(new Sphere( 4.0, 3.5, 4.0, 0.7, texWhite));

s.addEntity(new Sphere( 3.0, -1.5,  2.0, 0.7, texWhite));
s.addEntity(new Sphere( 4.0, -1.5,  5.0, 0.7, texPurple));
s.addEntity(new Sphere( 5.0, -1.5,  8.0, 0.7, texWhite));
s.addEntity(new Sphere( 6.0, -1.5, 11.0, 0.7, texPurple));
s.addEntity(new Sphere( 7.0, -1.5, 14.0, 0.7, texWhite));
s.addEntity(new Sphere( 8.0, -1.5, 17.0, 0.7, texPurple));

Source 6 files