|
Post by stevan on Jun 19, 2023 14:55:12 GMT
all tests up through the end of chapter 11 pass, but running the code for the image on page 159 which jamis gives in an earlier thread here: forum.raytracerchallenge.com/thread/91/ch-11-reflection-refraction-problemproduces the following image: this may be related to another problem. shade_hit calls reflected_color and refracted_color with remaining. in the book, reflected_color returns 0 0 0 if remaining<1, but refracted_color does not. this produces a stack error when running the code to produce the image above, even though all tests pass. to avoid the stack error, i've added the remaining<1 test to refracted_color and return 0 0 0 in that case. (i think i noticed that at least one other person did the same thing.) the call-hierarchy in my code is: shade_hit remaining -> reflected_color remaining, return 0 0 0 if remaining<1 -> color_at remaining-1 -> shade_hit remaining -> refracted_color remaining, return 0 0 0 if remaining<1 -> color_at remaining-1 -> shade_hut remaining suggestions welcome - thanks!
|
|
|
Post by Jamis on Jun 19, 2023 19:38:22 GMT
Hello stevan, sorry to hear you're running into issues. FWIW, the book does, in fact, recommend returning black in reflected_color if remaining <= 0 (see the pseudocode on page 148). So you're absolutely right to do it the way you are. Also, your call-hierarchy looks right to me. You're definitely getting some refraction effects around the edge of the sphere, and presumably around the inner sphere. I'm also seeing the reflections on the sphere, so that seems to be working. Probably something is wonky in your refraction logic? Without seeing your implementation, though, I'm not sure what specifically might be going on here. The best I can recommend is to do what I did (A LOT) when I was writing the book: choose a pixel that you feel is rendering incorrectly, and modify your ray tracer to only draw that pixel. Then...step through your program. :/ It's tedious work, to be sure, but stepping through it, double-checking the math and the logic, was a very successful strategy for me, many times.
|
|
|
Post by stevan on Jun 19, 2023 22:30:14 GMT
thanks jamis - i'll pursue the course you recommend and check back with results. lovely book! a 2nd edition/sequel would be wonderful!
|
|
|
Post by stevan on Jun 20, 2023 1:44:31 GMT
> the book does, in fact, recommend returning black in reflected_color if remaining <= 0 (see the pseudocode on page 148).
right - but what i had to do to avoid a stack error (remaining = -243) was implement the same early exit in the refracted_color function. i see that others did that as well. but if you believe that's not necessary that would be evidence that something has gone awry in my refraction logic.
i'd post a link to the code, but my implementation is in k, a high-performance ascii vector lanuguage based on APL and Lisp. i'm not sure that would shed much light!
|
|
|
Post by Jamis on Jun 21, 2023 1:14:44 GMT
Oh, my bad! I somehow misread that. But yes, refracted_color should also have that guard. There is no pseudocode in the book to demonstrate it, but there is a test (test #5, at the bottom of page 155) that is intended to demonstrate that behavior. So yes, if you've got the guard in your implementation, you're doing it right!
|
|