项目作者: LavaHoppers

项目描述 :
A simple but optimized path tracer written in Java with minimal imports.
高级语言: Java
项目地址: git://github.com/LavaHoppers/path-tracer.git
创建时间: 2021-05-18T02:27:47Z
项目社区:https://github.com/LavaHoppers/path-tracer

开源协议:

下载


Globaly Illuminated Dragon

Overview

This path tracer is a project used to experiment with the math used by commercial path tracers. I wanted this project to be easy to understand, so it is written in plain Java with minimal imports.

Features

Multithreading: The renderer can use any number of CPU cores to dramatically decrease the render time.

Bounding Volume Hierarchies: Upon loading a 3D object into the engine, it will algorithmically subdivide it’s mesh so the object can be rendered efficiently.

Global Illumination: Global illumination makes each object to act as a light source and allows for incredibly realistic lighting.

Real-time Display: You can watch your image render as the engine works on it in addition to the .png output.

Run it yourself

This project is light-weight so running it yourself is easy. The entire thing is compiled and run through a small batch script. Using batch does limit users to Windows, but that’s the price we pay for ease of use.

  • Install JDK on Windows
  • Clone this repository
  • Edit the run.bat file to change the render and directory settings

The render setting are specified by the args variable. For example, if I would like to render the image in 1080p with a real-time display I would have the following:

  1. :: run.bat
  2. SET args=1920 1080 -v

The first two numbers specify the resolution, and -v tells the path-tracer to create the realtime display.

The full list of rendering setting are as follows:

flag desc
-m int Enable multithreading and set pixel dimensions of the chunks
-a int Set the sub-pixel sampling (antialiasing) resolution. For example, Supplying an argument of 2 will sample the pixel 2*2=4 times in a grid-like fashion.
-o Enable .png file output on completion
-d Enable realtime image display
-v Verbose console output

Make sure to also create the directories in run.bat.

  1. :: run.bat
  2. :: Set the location for the *.class files
  3. SET bin=bin
  4. :: The dir containing the *.java files
  5. SET src=src

The last step is providing your own .obj files and configuring src/PathTracer.java to load them.

No .objs on hand? No problem. Here are the standard free ones:

You can easily configure src/PathTracer.java to load your object files by doing something like this:

  1. //src/PathTracer.java
  2. public static void main(String[] args) {
  3. /* parser code ... */
  4. scene.meshes.add(OBJReader.read("obj/teapot.obj"));
  5. scene.meshes.add(OBJReader.read("obj/bunny.obj"));
  6. /* rendering code ... */
  7. }