Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
*.iml
out
*.class
.idea
*.iml
out
*.class
/target/
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
JAVAC = javac
JFLAGS =

ROOT_PACKAGE = 'src/main/java/com/github/idris/raytracer'

all:
$(JAVAC) $(JFLAGS) src/raytracer/*.java src/raytracer/pigments/*.java src/raytracer/shapes/*.java
$(JAVAC) $(JFLAGS) $(ROOT_PACKAGE)/*.java $(ROOT_PACKAGE)/pigments/*.java $(ROOT_PACKAGE)/shapes/*.java

clean:
$(RM) src/raytracer/*.class src/raytracer/pigments/*.class src/raytracer/shapes/*.class
$(RM) $(ROOT_PACKAGE)/*.class $(ROOT_PACKAGE)/*.class $(ROOT_PACKAGE)/*.class
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# RayTracer #

by Idris Mokhtarzada

I chose to write this RayTracer in Java because I am more comfortable with
Java as a language. Because there are concerns about speed with Java, I added
a multi-threaded mode (-multi) to be used when rendering large, anti-aliased
images.

## Requirements ##

Java JDK 5.0 or higher is required to compile and run this RayTracer.
Java JDK 6.0 is downloadable from the Java website:

<http://java.sun.com/javase/downloads/widget/jdk6.jsp>

Additionally, Apache Maven is required for building the project. Maven comes
with basically any Java IDE available, but you can install it manually from
here:

<https://maven.apache.org/download.cgi>

## Building ##

### Apache Maven ###

Compile and package with Maven:

`mvn clean compile package`

Maven will create a `target` directory with the runnable JAR inside.

### Manual ###

If you want to compile manually, you can simply type the following:

`javac src/main/java/com/github/idris/raytracer/*.java src/main/java/com/github/idris/raytracer/pigments/*.java src/main/java/com/github/idris/raytracer/shapes/*.java`

## Usage ##

Simply run the JAR from the command line:

`java -jar target/raytracer-*.jar`

The wildcard is a convenience to not hardcode the application version into the command
( instead of, for example `java -jar target/raytracer-0.1-SNAPSHOT.jar` )

### Make ###

A Makefile is included with the project, which will compile the Java source.

Use `make` to compile, and `make clean` to remove the compiled .class files.

### Manual build ###

After building, you can simply run the application using java as follows:

`java -cp src/main/java/ com.github.idris.raytracer.Main`

## Command line arguments ##

Run the jar without command line arguments to display a summary of parameters.

The -Djava.awt.headless=true flag alerts java not to popup a Java window.
This is especially useful when running the command on a terminal or in an ssh
connection.

## Implemented Features ##

Basic Features:

* shapes: spheres, planes
* pigments: solid, checker
* shadows
* reflection
* refraction

Extra Features:

* pigments: texmap
* anti-aliasing
To enable anti-aliasing, simply add "-aa" as a command line parameter
* multi-threading
To enable multi-threading, simply add "-multi" as a command line parameter
Note: Multi-threading is only optimal when the render time is very high.
For example, on my computer, when running test05.txt with
anti-aliasing enabled, and a canvas size of 800x600, multi-threading
saves about 6 seconds.
Also keep in mind, when using multi-threaded mode, there is no
incremental output. It only outputs the time it took to render.

## Test Files ##

Beyond the main test files (test01 - test05), there are some extra tests
included in the `samples` directory to demonstrate extra features:

* wood.txt - Looks very nice with "-aa" option!
(uses texture mapping. hardwood.bmp must be in the working directory)
* test-texmap.txt
(also uses texture mapping. spectrum.bmp must be in the working directory)

> Note: Samples using textures only work when ran from the project root.
> This will work:

```bash
foo@bar MINGW64 ~/dev/raytracer (master)
λ java -jar target/raytracer-0.1-SNAPSHOT.jar samples/wood.txt out.bmp 640 360 -multi -aa
Finished in: 4202ms
```

> This wont':

```bash
foo@bar MINGW64 ~/dev/raytracer/samples (master)
λ java -jar ../target/raytracer-0.1-SNAPSHOT.jar wood.txt out.bmp 640 360 -multi -aa
ERROR: Could not locate texmap file 'hardwood.bmp'.
```
66 changes: 0 additions & 66 deletions Readme.txt

This file was deleted.

40 changes: 40 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.idris</groupId>
<artifactId>raytracer</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>

<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>

<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.github.idris.raytracer.Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test-texmap.txt → samples/test-texmap.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
-80.0 160.0 -200.0 1 1 1 1 0 0

3
texmap spectrum.bmp
texmap samples/spectrum.bmp
0 .001 0 .12
0 0 0 0
checker .08 .25 .20 .93 .83 .82 40
Expand Down
0 test01.txt → samples/test01.txt
100755 → 100644
File renamed without changes.
0 test02.txt → samples/test02.txt
100755 → 100644
File renamed without changes.
0 test03.txt → samples/test03.txt
100755 → 100644
File renamed without changes.
0 test04.txt → samples/test04.txt
100755 → 100644
File renamed without changes.
0 test05.txt → samples/test05.txt
100755 → 100644
File renamed without changes.
2 changes: 1 addition & 1 deletion wood.txt → samples/wood.txt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
solid 1.0 0.0 0.0
solid 0.0 0.6 0.0
solid 0.0 0.0 1.0
texmap hardwood.bmp
texmap samples/hardwood.bmp
.5 0 0 0
0 .5 0 0
solid 0.1 0.8 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

import java.awt.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

public class Camera {
private Point eye;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

import java.awt.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

import java.awt.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

public class Log {
public static void error(String msg) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

import java.io.File;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

public class Matrix {
private double m[][];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

public class Point {
public double x, y, z;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer;
package com.github.idris.raytracer;

public class Ray {
public final Point origin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package raytracer;
package com.github.idris.raytracer;

import raytracer.shapes.Shape;
import com.github.idris.raytracer.shapes.Shape;

public class RayHit {
public final Ray ray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
package raytracer;

import raytracer.pigments.*;
import raytracer.shapes.*;
package com.github.idris.raytracer;

import com.github.idris.raytracer.shapes.Triangle;
import com.github.idris.raytracer.shapes.Polyhedron;
import com.github.idris.raytracer.shapes.Disc;
import com.github.idris.raytracer.shapes.Shape;
import com.github.idris.raytracer.shapes.Bezier;
import com.github.idris.raytracer.shapes.Parallelogram;
import com.github.idris.raytracer.shapes.Plane;
import com.github.idris.raytracer.shapes.Cylinder;
import com.github.idris.raytracer.shapes.Sphere;
import com.github.idris.raytracer.shapes.Polygon;
import com.github.idris.raytracer.shapes.Cone;
import com.github.idris.raytracer.pigments.SolidPigment;
import com.github.idris.raytracer.pigments.TexmapPigment;
import com.github.idris.raytracer.pigments.Pigment;
import com.github.idris.raytracer.pigments.CheckerPigment;
import com.github.idris.raytracer.pigments.Finish;
import com.github.idris.raytracer.pigments.GradientPigment;

import javax.imageio.ImageIO;
import java.awt.Color;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package raytracer;
package com.github.idris.raytracer;

import com.github.idris.raytracer.Log;
import com.github.idris.raytracer.Point;

public class Vector {
public double x, y, z;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package raytracer.pigments;
package com.github.idris.raytracer.pigments;

import raytracer.Point;
import com.github.idris.raytracer.Point;

import java.awt.Color;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package raytracer.pigments;
package com.github.idris.raytracer.pigments;

public class Finish {
public float amb, diff, spec, shiny, refl, trans, ior;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package raytracer.pigments;
package com.github.idris.raytracer.pigments;

import raytracer.*;
import com.github.idris.raytracer.Vector;
import com.github.idris.raytracer.ColorUtil;
import com.github.idris.raytracer.Log;
import com.github.idris.raytracer.Point;

import java.awt.Color;

Expand Down
Loading