home dev games gallery work
Lewpen.com»Research & Development»3D Graphics»Java 3D Engine»LRay - Java Raytracer

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.
The renderer makes several passes at successively higher resolutions, the last one for anti-aliasing.

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));

Files

LRay 100 Percent.html 302 bytes
LRay 640x480.html 300 bytes
LRay.java 21,492 bytes
LRay 1280x960.html 302 bytes
LRay 800x600.html 300 bytes
index.html 302 bytes
Related Articles

3D Engine with scene graph and cartoon rendering style

Using a BSP tree for reflections and object intersection

Games

The Dodge Game
Flatspace

2-Player Games:

Quake 2D
Meteora

Puzzle Games:

Mini Tetris
Sudoku Solver

Development

3D Graphics:

3D Graphics Articles
WebGL Examples
OpenGL Examples
Flash 3D Engine
Java 3D Engine

Development:

Programming Articles
Game Development Examples

Work

Portfolio
Clients
Startups & Projects
Expertise

Links

CubeLogix Studios
PHP Charts & Graphs
Local Legends Football