-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
644 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import image.Image; | ||
import image.ImageWriter; | ||
import raytracer.RayTracer; | ||
import raytracer.RayTracerConfig; | ||
import raytracer.RayTracerImpl; | ||
import raytracer.RayTracerLights; | ||
import raytracer.scene.BallsScene; | ||
import raytracer.scene.LightsScene; | ||
import util.Dimension; | ||
import java.nio.file.Paths; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class App { | ||
public static void main(String[] args) throws Exception{ | ||
ImageWriter writer = new ImageWriter(Math::sqrt); | ||
// RayTracer rayTracer = new RayTracerImpl(new RayTracerConfig(new Dimension(400, 16d/9d), 50, 50), new BallsScene()); | ||
RayTracer rayTracer = new RayTracerLights(new RayTracerConfig(new Dimension(400, 16d/9d), 50, 50), new LightsScene()); | ||
long st = System.currentTimeMillis(); | ||
Image image = rayTracer.render(); | ||
System.out.printf("Processing time: %d seconds\n", TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - st)); | ||
writer.writeToFile(Paths.get("image.png"), image); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package image; | ||
|
||
import math.Color; | ||
import util.Pair; | ||
|
||
import java.util.*; | ||
|
||
public class ArrayImage implements Image{ | ||
private final int xLen; | ||
private final int yLen; | ||
private final Color[][] colors; | ||
|
||
public ArrayImage(int xLen, int yLen) { | ||
this.xLen = xLen; | ||
this.yLen = yLen; | ||
colors = new Color[xLen][yLen]; | ||
} | ||
|
||
public ArrayImage(Color[][] colors) { | ||
this.colors = colors; | ||
this.xLen = colors.length; | ||
this.yLen = colors[0].length; | ||
} | ||
|
||
@Override | ||
public Pair<Integer, Integer> getSize() { | ||
return new Pair<>(xLen, yLen); | ||
} | ||
|
||
@Override | ||
public Color getColor(int x, int y) { | ||
if(x >= xLen || y >= yLen){ | ||
throw new IllegalArgumentException("Coordinate out of image size"); | ||
} | ||
return colors[x][y]; | ||
} | ||
|
||
@Override | ||
public Iterator<Pixel> iterator() { | ||
List<Pixel> list = new ArrayList<>(); | ||
for (int i = 0; i < xLen; i++) { | ||
for (int j = 0; j < yLen; j++) { | ||
list.add(new Pixel(i, j, colors[i][j])); | ||
} | ||
} | ||
return list.iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package image; | ||
|
||
import math.Color; | ||
import util.Pair; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
public class ColorImage implements Image{ | ||
private final int x; | ||
private final int y; | ||
private final Color color; | ||
|
||
public ColorImage(int x, int y, Color color) { | ||
this.x = x; | ||
this.y = y; | ||
this.color = color; | ||
} | ||
|
||
public ColorImage(Color color) { | ||
this(1, 1, color); | ||
} | ||
|
||
@Override | ||
public Pair<Integer, Integer> getSize() { | ||
return new Pair<>(x, y); | ||
} | ||
|
||
@Override | ||
public Color getColor(int x, int y) { | ||
return color; | ||
} | ||
|
||
@Override | ||
public Iterator<Pixel> iterator() { | ||
List<Pixel> pixels = new ArrayList<>(); | ||
for (int i = 0; i < x; i++){ | ||
for (int j = 0; j < y; j++) { | ||
pixels.add(new Pixel(i, j, color)); | ||
} | ||
} | ||
return pixels.iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
package image; | ||
|
||
import math.Color; | ||
import util.Pair; | ||
|
||
public interface Image extends Iterable<Pixel>{ | ||
Pair<Integer, Integer> getSize(); | ||
Color getColor(int x, int y); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package material; | ||
|
||
import math.*; | ||
import texture.SolidColorTexture; | ||
import texture.Texture; | ||
|
||
public class DiffuseLight implements Material{ | ||
private final Texture texture; | ||
|
||
public DiffuseLight(Color color) { | ||
this.texture = new SolidColorTexture(color); | ||
} | ||
|
||
public DiffuseLight(Texture texture) { | ||
this.texture = texture; | ||
} | ||
|
||
@Override | ||
public boolean scatter(Ray rayIn, HitRecord record, Color attenuation, Ray scattered) { | ||
scattered.setOrigin(new Point()).setDirection(new Vector()); | ||
return false; | ||
} | ||
|
||
@Override | ||
public Color emitted(double u, double v, Point p) { | ||
return texture.value(u, v, p); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package material; | ||
|
||
import math.Point; | ||
import math.Ray; | ||
import math.Color; | ||
import math.HitRecord; | ||
|
||
public interface Material { | ||
boolean scatter(Ray rayIn, HitRecord record, Color attenuation, Ray scattered); | ||
|
||
default Color emitted(double u, double v, Point p){ | ||
return new Color(0, 0, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.