tonag
New Member
Posts: 8
|
Post by tonag on Aug 31, 2021 14:22:21 GMT
Hi! I'm stuck on chapter 12, as you can see the colors of my cube isn't right. I have written all the tests and all of them are passing. Does anyone have a clue what it could be judging by the image? local_intersect: let (xtmin, xtmax) = Cube.checkAxis ray.origin.X ray.direction.X let (ytmin, ytmax) = Cube.checkAxis ray.origin.Y ray.direction.Y let (ztmin, ztmax) = Cube.checkAxis ray.origin.Z ray.direction.Z
let tmin = [xtmin; ytmin; ztmin] |> List.max let tmax = [xtmax; ytmax; ztmax] |> List.min
match tmin > tmax with | true -> [] | false -> let i1 = Intersection.create object tmin let i2 = Intersection.create object tmax [i1; i2]
checkAxis: let checkAxis origin direction =
let tMinNumerator = (-1.) - origin let tMaxNumerator = 1. - origin
let tMin, tMax =
match Math.Abs(direction:float) >= epsilon with
| true ->
let tMin = tMinNumerator / direction let tMax = tMaxNumerator / direction
(tMin, tMax)
| false ->
let tMin = tMinNumerator * infinity let tMax = tMaxNumerator * infinity
(tMin, tMax)
if tMin > tMax then (tMax, tMin) else (tMin, tMax) Would appricate any help I could get thanks!
|
|
|
Post by Jamis on Aug 31, 2021 15:10:54 GMT
Hello tonag! The good news is that I don't think the issue is in your intersect routines --- the shape of the rendered cube looks right, which suggests the ray intersections are working. It looks more like the shading itself that is off, which might indicate a bug in how you're computing the normal at the point of intersection. Can you share your "local_normal_at" function (or equivalent)?
|
|
tonag
New Member
Posts: 8
|
Post by tonag on Aug 31, 2021 19:06:28 GMT
Hi Jamis! First of thank you for an amazing book! Yes I have looked over the code equivalent for my local_nomal_at. It looks like this:
let maxc = [point.X; point.Y; point.Z] |> List.map (fun v -> Math.Abs(v:float)) |> List.max
match maxc with | _ when (FloatHelper.equal maxc (Math.Abs(point.X:float))) -> Vector.create point.X 0. 0. | _ when (FloatHelper.equal maxc (Math.Abs(point.Y:float))) -> Vector.create 0. point.Y 0. | _ -> Vector.create 0. 0. point.Z
I think it looks correct but maybe you can spot something?
Thanks you!
|
|
tonag
New Member
Posts: 8
|
Post by tonag on Sept 2, 2021 18:36:23 GMT
I have also noticed that the colors of the cube only becomes weird when applying a transformation such as translation or scaling on the cube. This cube has only been rotated around the Y-axis my Pi/3.
|
|
|
Post by Jamis on Sept 3, 2021 15:31:34 GMT
Hmm! That's an interesting clue. What does your "normal_at" function look like, the one that transforms the point before computing the normal?
|
|
tonag
New Member
Posts: 8
|
Post by tonag on Sept 4, 2021 6:44:15 GMT
I have looked over my normalAt and still thinks it looks correct. But here is is: If anything is unclear or you're unfamilular with the syntax just let me know Thanks!
|
|
tonag
New Member
Posts: 8
|
Post by tonag on Sept 8, 2021 6:21:30 GMT
Finaly found it and feel really stupid. You where right the problem was in the normalAt-function. As you can see in the screenshot I use the original point instead of objectPoint.
|
|
|
Post by Jamis on Sept 8, 2021 15:07:50 GMT
I'm glad you found it! These renderer bugs can be super tricky to track down, but it's very satisfying when you find them.
|
|