Post by jamesmcm on Oct 27, 2019 21:18:48 GMT
Hi,
Here is a comparison of my render vs. the book's render (book above, mine below):
As you can see, the walls don't render correctly but the spheres do.
I can't find any errors in the code, and all the tests pass.
The render code is as follows (Scala):
It seems it's rendering the right wall only (in front of the left wall), and neither are angled correctly.
Full code: github.com/jamesmcm/raytracer_challenge_scala/tree/master/src/main/scala/raytracer - see Demo.firstScene()
Here is a comparison of my render vs. the book's render (book above, mine below):
As you can see, the walls don't render correctly but the spheres do.
I can't find any errors in the code, and all the tests pass.
The render code is as follows (Scala):
def firstScene(): Unit = {
val floorMaterial: Material = Material.defaultMaterial().setColour(Colour(1, 0.9, 0.9)).setSpecular(0)
val floor: Sphere = Sphere.unitSphere().setTransform(Scaling(10, 0.01, 10)).setMaterial(floorMaterial)
val left_wall: Sphere = Sphere.unitSphere().setTransform(Translation(0, 0, 5)
* RotationY(-math.Pi/4) * RotationX(math.Pi/2) * Scaling(10, 0.01, 10)).setMaterial(floorMaterial)
val right_wall: Sphere = Sphere.unitSphere().setTransform(Translation(0, 0, 5)
* RotationY(math.Pi/4) * RotationX(math.Pi/2) * Scaling(10, 0.01, 10)).setMaterial(floorMaterial)
val middleMaterial: Material = Material.defaultMaterial().setColour(
Colour(0.1, 1, 0.5)).setDiffuse(0.7).setSpecular(0.3)
val middleSphere: Sphere = Sphere.unitSphere().setTransform(
Translation(-0.5, 1, 0.5)).setMaterial(middleMaterial)
val rightMaterial: Material = middleMaterial.setColour(Colour(0.5, 1, 0.1))
val rightSphere: Sphere = Sphere.unitSphere().setTransform(
Translation(1.5, 0.5, -0.5)*Scaling(0.5, 0.5, 0.5)).setMaterial(rightMaterial)
val leftMaterial: Material = middleMaterial.setColour(Colour(1, 0.8, 0.1))
val leftSphere: Sphere = Sphere.unitSphere().setTransform(
Translation(-1.5, 0.33, -0.75)*Scaling(0.33, 0.33, 0.33)).setMaterial(leftMaterial)
val world: World = World(List(Light.pointLight(Point(-10, 10, -10), Colour(1, 1, 1))),
List(floor, leftSphere, rightSphere, middleSphere, left_wall, right_wall))
val camera: Camera = Camera(200, 100, math.Pi/3).setTransform(viewTransform(Point(0, 1.5, -5),
Point(0, 1, 0), Vector(0, 1, 0)))
val canvas: Canvas = camera.render(world)
stringToFile("scene3.ppm", canvas.toPPM)
}
It seems it's rendering the right wall only (in front of the left wall), and neither are angled correctly.
Full code: github.com/jamesmcm/raytracer_challenge_scala/tree/master/src/main/scala/raytracer - see Demo.firstScene()