Post by bmitc on Jul 26, 2022 6:42:08 GMT
I am at the end of Chapter 9: Planes with the Putting It Together example. The base example seems to work correctly with an untransformed plane as the floor, but when I try to create a wall or any plane that is transformed in any way, I get behavior that is confusing me.
For example, the following scene:
generates the following image:
The code is in F#, but it should be easily understood. The combination transform is applied right to left (i.e., the transform at the end of the list is applied first). The sphere cut in half is at the origin.
As you can see, the lower floor, which is an untransformed plane is seemingly ray traced correctly. However, the wall that's been transformed so that's its slicing just off axis (done to test if the transforms worked as expected, which they seem to do) does not light up correctly. The wall is a plane that is vertical along the YZ axis and is rotated such that it splits the negative X axis and positive Z axis at 45 degrees, and it's translated just off the origin. All the tests in the book are implemented at this point and passing plus some additional ones, so there's 166 tests passing. I'm totally stumped on what could be going on and have combed through the code. Obviously, I must be missing something, so I was hoping someone here could see this and point where the trouble might be.
Again, despite it being F#, the code and tests especially are very close to the pseudocode in the book, and the code is heavily commented. So it should be able to be read by someone not familiar with F#. The only difference is not using OOP to handle the shapes (sphere and plane at this point) but rather discriminated unions and pattern matching, which is basically the same idea anyway.
Any thoughts on what might be making these strange lighting scenarios for my transformed planes? Thanks so much!
For example, the following scene:
//******************************************
// Scene objects
//******************************************
let floor = {plane with Material = Some {Material.Default with Color = color(0.5, 0.9, 0.9);
Specular = 0.0}}
let wall = {plane with Transform = Some (Combination [Translation (-1.0, 0.0, 0.0); Rotation (Y, -pi/4.0); Rotation (Z, pi/2.0)]);
Material = Some {Material.Default with Color = color(1.0, 1.0, 1.0);
Specular = 0.0}}
let middle = {sphere with Transform = Some (Translation(-0.5, 1.0, 0.5));
Material = Some {Material.Default with Color = color(0.1, 1.0, 0.5);
Diffuse = 0.7;
Specular = 0.3}}
let right = {sphere with Transform = Some (Combination [Translation(1.5, 0.5, -0.5); Scaling(0.5, 0.5, 0.5)]);
Material = Some {Material.Default with Color = color(0.5, 1.0, 0.1);
Diffuse = 0.7;
Specular = 0.3}}
let left = {sphere with Transform = Some (Combination [Translation(-1.5, 0.33, -0.75); Scaling(0.33, 0.33, 0.33)]);
Material = Some {Material.Default with Color = color(0.0, 0.5, 0.8);
Diffuse = 0.7;
Specular = 0.3}}
//******************************************
// World
//******************************************
let light = {Position = pointu<world>(-10.0, 10.0, -10.0); Intensity = color(1.0, 1.0, 1.0)}
let world = {Objects = [floor; wall; middle; left; right; {middle with Transform = None}]; LightSource = light}
let camera = {camera(250<pixels>, 125<pixels>, pi/1.5)
with Transform = viewTransform (point(0.0, 1.5, -5.0)) (point(0.0, 1.0, 0.0)) (vector(0.0, 1.0, 0.0)) }
let image = render camera world
generates the following image:
The code is in F#, but it should be easily understood. The combination transform is applied right to left (i.e., the transform at the end of the list is applied first). The sphere cut in half is at the origin.
As you can see, the lower floor, which is an untransformed plane is seemingly ray traced correctly. However, the wall that's been transformed so that's its slicing just off axis (done to test if the transforms worked as expected, which they seem to do) does not light up correctly. The wall is a plane that is vertical along the YZ axis and is rotated such that it splits the negative X axis and positive Z axis at 45 degrees, and it's translated just off the origin. All the tests in the book are implemented at this point and passing plus some additional ones, so there's 166 tests passing. I'm totally stumped on what could be going on and have combed through the code. Obviously, I must be missing something, so I was hoping someone here could see this and point where the trouble might be.
- My F# implementation is here (includes the current plane implementation): github.com/bmitc/the-ray-tracer-challenge-fsharp
- The modules are here: github.com/bmitc/the-ray-tracer-challenge-fsharp/tree/main/RayTracerChallenge/RayTracerChallenge
Again, despite it being F#, the code and tests especially are very close to the pseudocode in the book, and the code is heavily commented. So it should be able to be read by someone not familiar with F#. The only difference is not using OOP to handle the shapes (sphere and plane at this point) but rather discriminated unions and pattern matching, which is basically the same idea anyway.
Any thoughts on what might be making these strange lighting scenarios for my transformed planes? Thanks so much!