Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

The Raytracinator 2000!

Behold the Raytracinator 2000! With this program, scenes can't help but be rendered!

Image Image Image

This is an easily extendable raytracer written in pure Java with no external libraries (well, except for unit testing). Some examples of its usage are provided.

The raytracer supports the following:

  • Arbitrary shapes, including triangles and smooth triangles
  • Textures, patterns, and normal maps
  • .obj parser and a JSON scene parser.
  • Multithreading and BVH acceleration structure.
  • Extensive test suite.
  • Reasonably fast, all things considered.

I intend to expand on this raytracer in the future; however, I have focused on correct implementation before adding large amounts of features.

Why Java

There are three reasons I chose to use Java in spite of it at first seeming to be an unconventional language for a raytracer.

Firstly, a jar with no dependencies will run virtually anywhere. I can raytrace on my smart fridge, or perhaps a smartwatch, if I wish. Though I may have to wait a while.

Secondly, a raytracer made in cpp, Rust, or some other fast language is simply not notable. After all, driving a slow car 'fast' is much more fun than driving a fast car fast!

Thirdly, well, I just like Java.

Setup

The project can be pulled and set up as any other Java project. JDK 26 is a hard requirement, and compatibility is broken in JDK 21. To get the assets for the spherical reflections scene, Utah Teapot scene, and Pagani Zonda scene, you must install git lfs, then:

git lfs install git lfs fetch --all git lfs pull

In order to run: ./gradlew run --args="path/to/scene.json path/to/output.png"

Performance

The "zonda" scene took 4.5 hours on dual 2016 Xeon E5-2697As at 1080p with 16 anti-aliasing samples.

Architecture

Rendering a scene occurs in two stages.

Parsing A scene is described in JSON format (see Examples/); the JSON parser builds a description of the scene in memory. This part also includes parsing relevant OBJ files into a flat list of triangles, which is then turned into a BVH tree non-lazily.

Rendering The camera fires a ray per pixel into the scene; each ray is tested against the root BVHNode, which then recursively asks which shapes have been hit and where; then an intersection result is prepared with the color of the hit, accounting for material, texture, normal maps, etc., and how many rays it needs to draw from that point, e.g., in the case of reflection or translucency.

License

Copyright (c) 2026 Thomas Bestvina

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages