-
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.
Merge pull request #1 from VxDxK/next-step
Next step
- Loading branch information
Showing
78 changed files
with
2,284 additions
and
295 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ target/ | |
!**/src/test/**/target/ | ||
|
||
image.ppm | ||
image.png | ||
|
||
### IntelliJ IDEA ### | ||
.idea/ | ||
|
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,68 @@ | ||
import math.Color; | ||
import math.Point; | ||
import math.Points; | ||
import util.PerlinNoise; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.OutputStreamWriter; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.Arrays; | ||
import java.util.function.Function; | ||
|
||
import static util.Util.clamp; | ||
|
||
public class Perlin { | ||
public static void main(String[] args) throws Exception{ | ||
try (OutputStream stream = Files.newOutputStream(Paths.get("image.ppm")); | ||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(stream); | ||
BufferedWriter writer = new BufferedWriter(outputStreamWriter)){ | ||
long start = System.currentTimeMillis(); | ||
new Perlin(writer); | ||
System.out.println("Processing time: " + (((double)(System.currentTimeMillis() - start))/1000)); | ||
} | ||
Convertor.main(args); | ||
} | ||
|
||
Perlin(BufferedWriter writer) throws Exception{ | ||
int width = 100; | ||
int height = 100; | ||
|
||
PerlinNoise perlinNoise = new PerlinNoise(); | ||
PerlinNoise r = new PerlinNoise(); | ||
PerlinNoise g = new PerlinNoise(); | ||
PerlinNoise b = new PerlinNoise(); | ||
|
||
writer.write("P3\n" + width + " " + height + "\n255\n"); | ||
for(int j = 0; j < height; j++){ | ||
System.out.print("Lines remaining " + (height - j) + "\r"); | ||
for(int i = 0; i < width; i++){ | ||
Color red = new Color(1, 0, 0).scale(15 * r.turbulence(Points.scale(new Point(i, 0, j), 0.1), 1)); | ||
Color green = new Color(0, 1, 0).scale(10 * g.turbulence(Points.scale(new Point(i, 0, j), 0.1), 1)); | ||
Color blue = new Color(0, 0, 1).scale(10 * b.turbulence(Points.scale(new Point(i, 0, j), 0.1), 1)); | ||
|
||
Color start = new Color(); | ||
|
||
Color mixed = new Color(start.getRed() + red.getRed() + green.getRed() + blue.getRed(), | ||
start.getGreen() + red.getGreen() + green.getGreen() + blue.getGreen(), | ||
start.getBlue() + red.getBlue() + green.getBlue() + blue.getBlue()); | ||
mixed = mixed.scale((1d/4d)); | ||
double scaling = perlinNoise.noise(Points.scale(new Point(i, 0, j), 0.1)); | ||
Color pixelColor = new Color(1, 1, 1).scale(scaling); | ||
writeColor(writer, mixed, x -> x); | ||
} | ||
} | ||
writer.flush(); | ||
} | ||
|
||
private void writeColor(BufferedWriter writer, Color color, Function<Double, Double> gammaCorrectionFunction) throws IOException { | ||
double r = gammaCorrectionFunction.apply(color.getRed()); | ||
double g = gammaCorrectionFunction.apply(color.getGreen()); | ||
double b = gammaCorrectionFunction.apply(color.getBlue()); | ||
writer.write((int)(256 * clamp(r, 0d, 0.999)) + " " + (int)(256 * clamp(g, 0d, 0.999)) + " " + (int)(256 * clamp(b, 0d, 0.999)) + '\n'); | ||
} | ||
|
||
} |
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
2 changes: 1 addition & 1 deletion
2
src/main/java/util/camera/Camera.java → src/main/java/camera/Camera.java
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,4 +1,4 @@ | ||
package util.camera; | ||
package camera; | ||
|
||
import math.Ray; | ||
|
||
|
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,24 @@ | ||
package camera; | ||
|
||
import math.Ray; | ||
|
||
public class MotionBlurCamera implements Camera{ | ||
private final Camera camera; | ||
private final double shutterOpeningMoment; | ||
private final double shutterClosingMoment; | ||
|
||
public MotionBlurCamera(Camera camera, double shutterOpeningMoment, double shutterClosingMoment) { | ||
if(shutterClosingMoment < shutterOpeningMoment){ | ||
throw new IllegalArgumentException("shutterClosingMoment can`t be less then shutterOpeningMoment"); | ||
} | ||
this.camera = camera; | ||
this.shutterOpeningMoment = shutterOpeningMoment; | ||
this.shutterClosingMoment = shutterClosingMoment; | ||
} | ||
|
||
@Override | ||
public Ray getRay(double s, double t) { | ||
double shutterOpenMoment = (Math.random() * (shutterClosingMoment - shutterOpeningMoment)) + shutterOpeningMoment; | ||
return camera.getRay(s, t).setTimeMoment(shutterOpenMoment); | ||
} | ||
} |
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(); | ||
} | ||
} |
Oops, something went wrong.