-
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
1 parent
4cc5447
commit e6ab79f
Showing
26 changed files
with
368,731 additions
and
123 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,20 @@ | ||
# The Ray Tracer Challenge Output Images | ||
|
||
- These are the the images that are generated at the end of their respective chapters at the end of the Ray Tracer | ||
Challenge and converted to PNG. | ||
|
||
- **Be aware** that you look at the following images (depicted for artistic purposes only) at your own discretion. | ||
|
||
|
||
- In particular, the file `ch15_world2.png` depicts ray tracing of male genitalia, and should not | ||
be viewed by anyone who is not prepared to see such a thing. This is the rendering an open source male genitalia file | ||
with: | ||
- 49,156 points, each with a surface normal; amd | ||
- 49,152 quadrilaterals (which are translated to 98,304 triangles). | ||
|
||
|
||
- This is to demonstrate the functionality of the `SmoothTriangle` class amd the | ||
ability of `KDTree`s to render large files quickly. | ||
|
||
- This file is deemed to pass: [GitHub Sexually Obscene Content](https://docs.github.com/en/site-policy/acceptable-use-policies/github-sexually-obscene-content) | ||
as is is not pornographic; consensual; and has no graphic depictions of sexual acts. |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,58 @@ | ||
package apps | ||
|
||
import input.OBJParser | ||
import light.PointLight | ||
import material.Material | ||
import math.Color | ||
import math.Matrix | ||
import math.Tuple | ||
import pattern.CheckerPattern | ||
import scene.Camera | ||
import scene.World | ||
import shapes.Cube | ||
import java.io.File | ||
import kotlin.math.PI | ||
import kotlin.system.measureTimeMillis | ||
|
||
fun main() { | ||
// 49.156 points. | ||
// 49,152 quadrilaterals -> 98,304 triangles. | ||
val modelStart = System.currentTimeMillis() | ||
val model = OBJParser.fromURL({}.javaClass.getResource("/flaccid.obj")) | ||
.groups.getValue(OBJParser.DefaultGroup) | ||
|
||
val model1 = run { | ||
val t = Matrix.translate(0, 0, -5) * Matrix.rotateY(4 * PI / 5) * | ||
Matrix.translate(0, 3, 0) * Matrix.scale(0.05, 0.05,0.05) | ||
val m = Material(Color.fromHex(0xffe5b2), specular = 0, shininess = 36, transparency = 0) | ||
model.withTransformation(t).withMaterial(m) | ||
} | ||
println("Time elapsed (processing model): ${(System.currentTimeMillis() - modelStart) / 1000.0} s") | ||
|
||
val room = run { | ||
val m = Material(CheckerPattern(Color(0.25, 0.25, 0.25), Color(0.75, 0.75, 0.75), | ||
Matrix.scale(0.25, 0.25, 0.25)), specular = 0) | ||
val t = Matrix.scale(30, 30, 30) | ||
Cube(t, m) | ||
} | ||
|
||
val world = run { | ||
val light1 = PointLight(Tuple.point(-5, 10, -15), Color(0.6, 0.4, 0.4)) | ||
val light2 = PointLight(Tuple.point(8, 15, -10), Color(0.4, 0.6, 0.4)) | ||
World(listOf(room, model1), listOf(light1, light2)) | ||
} | ||
|
||
val camera = run { | ||
val from = Tuple.point(0, 5, -25) | ||
val to = Tuple.point(0, 5, 0) | ||
val up = Tuple.VY | ||
val t = from.viewTransformationFrom(to, up) | ||
Camera(1200, 1200, PI / 2, t) | ||
} | ||
|
||
val elapsed = measureTimeMillis { | ||
val canvas = camera.render(world) | ||
canvas.toPPMFile(File("output/ch15_world2.ppm")) | ||
} | ||
println("Time elapsed (rendering): ${elapsed / 1000.0} s") | ||
} |
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
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
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,36 @@ | ||
package shapes | ||
|
||
// By Sebastian Raaphorst, 2023. | ||
|
||
import material.Material | ||
import math.Intersection | ||
import math.Matrix | ||
import math.Tuple | ||
|
||
class PlainTriangle( | ||
p1: Tuple, | ||
p2: Tuple, | ||
p3: Tuple, | ||
transformation: Matrix = Matrix.I, | ||
material: Material? = null, | ||
castsShadow: Boolean = true, | ||
parent: Shape? = null | ||
): Triangle(p1, p2, p3, transformation, material, castsShadow, parent) { | ||
|
||
// Calculate the normal. | ||
internal val normal = e2.cross(e1).normalized | ||
|
||
override fun withParent(parent: Shape?): Shape = | ||
PlainTriangle(p1, p2, p3, transformation, material, castsShadow, parent) | ||
|
||
override fun withMaterial(material: Material): Shape = | ||
PlainTriangle(p1, p2, p3, transformation, material, castsShadow, parent) | ||
|
||
// For plain triangles, we ignore u and v. | ||
override fun createIntersection(t: Double, uv: Pair<Double, Double>?): Intersection = | ||
Intersection(t, this) | ||
|
||
// Note that this will still return a normal if the point is not on the triangle. | ||
override fun localNormalAt(localPoint: Tuple, hit: Intersection): Tuple = | ||
normal | ||
} |
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,41 @@ | ||
package shapes | ||
|
||
// By Sebastian Raaphorst, 2023. | ||
|
||
import material.Material | ||
import math.Intersection | ||
import math.Matrix | ||
import math.Tuple | ||
|
||
class SmoothTriangle( | ||
p1: Tuple, | ||
p2: Tuple, | ||
p3: Tuple, | ||
internal val n1: Tuple, | ||
internal val n2: Tuple, | ||
internal val n3: Tuple, | ||
transformation: Matrix = Matrix.I, | ||
material: Material? = null, | ||
castsShadow: Boolean = true, | ||
parent: Shape? = null | ||
): Triangle(p1, p2, p3, transformation, material, castsShadow, parent) { | ||
init { | ||
if (!n1.isVector() || !n2.isVector() || !n3.isVector()) | ||
throw IllegalArgumentException("Smooth triangle requires three vector normals: $n1, $n2, $n3.") | ||
} | ||
|
||
override fun withParent(parent: Shape?): Shape = | ||
SmoothTriangle(p1, p2, p3, n1, n2, n3, transformation, material, castsShadow, parent) | ||
|
||
override fun withMaterial(material: Material): Shape = | ||
SmoothTriangle(p1, p2, p3, n1, n2, n3, transformation, material, castsShadow, parent) | ||
|
||
override fun localNormalAt(localPoint: Tuple, hit: Intersection): Tuple { | ||
val uv = hit.uv ?: throw IllegalArgumentException("SmoothTriangle received hit with u/v=null.") | ||
val (u, v) = uv | ||
return n2 * u + n3 * v + n1 * (1 - u - v) | ||
} | ||
|
||
override fun createIntersection(t: Double, uv: Pair<Double, Double>?): Intersection = | ||
Intersection(t, this, uv) | ||
} |
Oops, something went wrong.