Craig Treptow
New Member
Doing this in Scala, while learning Scala.
Posts: 9
|
Post by Craig Treptow on Oct 13, 2021 0:55:59 GMT
Hello there!
I just finished chapter 8, and I now have shadows! Yay!
However, when I ran the whole test suite, I discovered a failing test entitled: "Shading an intersection from the inside".
The reason seems to be that my isShadowed function is returning true causing the ambient color to be returned (0.1, 0.1, 0.1). If it were false, my test would pass, since it would add the ambient, diffuse, and specular together.
So, I'm looking for a little guidance.
Should isShadowed be true for this test?
|
|
|
Post by Jamis on Oct 13, 2021 13:59:10 GMT
Hey, congrats on getting shadows working! That's great. As for the "Shading an intersection from the inside" test, it shouldn't be failing, and isShadowed should not be true for that test. Here's why: The default world has a single sphere of radius 1 at the origin, and a smaller sphere of radius 0.5 inside it, also at the origin. The default world also declares a point light source that is outside of those spheres. The test in question should be replacing that point light with a new one that is inside the inner sphere (at (0, 0.25, 0)), The test also positions the viewer at the origin, looking along the z axis. The test then creates an intersection with the "second object in w" (the inner sphere) at t=0.5. Because the light source and the viewer are both inside that sphere, there should be nothing casting a shadow at that point of intersection. The culprit could be any of several things. Here are a few to check: - Your isShadowed check may be returning true if there is any intersection with the shadow ray, even if the intersection lies behind the light source.
- The new light source in that test is not replacing the original one (which was external to the spheres). Or the new light source has been mispositioned.
- Because the intersection is on the inside of the sphere, you need to make sure you're using the correct normal vector (negated). But this is tested on page 95, in "The hit, when an intersection occurs on the inside", so you're probably okay.
Hopefully that gives you some ideas of where to look. If you'd like, I could take a peek too, if you've got your code online somewhere.
|
|
Craig Treptow
New Member
Doing this in Scala, while learning Scala.
Posts: 9
|
Post by Craig Treptow on Oct 13, 2021 19:06:59 GMT
Thank you for responding so quickly! My code is online (as ugly as it is) here: gitlab.com/CraigTreptow/scrayzI will read your reply more thoroughly and double-check my code (again) a little later today probably. Hopefully, something "clicks" today. LOL
|
|
|
Post by Jamis on Oct 14, 2021 14:10:41 GMT
I'll admit that I'm only very superficially familiar with scala, so my read-thru may have missed any number of things. But it all looks good to me. The one bit that piqued my skeptical nature was at line 122 of WorldFeature.scala, where you clone the world and assign a new light. Have you verified that w.light is the expected value after that? I suspect it probably is, but like I said, I wondered. If all of that is in order, the next step would be to walk through your code, step by step, either with a debugger or with copious print statements, to make sure that the values at each step are what you would expect. I'd look especially closely at the values you get in your isShadowed routine: what object is casting the shadow? At what point in world-space is the intersection occurring? Etc. Sorry I can't be of more help! But I'm happy to answer any questions I can.
|
|
Craig Treptow
New Member
Doing this in Scala, while learning Scala.
Posts: 9
|
Post by Craig Treptow on Oct 14, 2021 22:37:35 GMT
Yes, thank you. I have certainly been through multiple rounds of "copious print statements". I think I understand it "enough" until something like this crops up. I have given up on this effort with Elixir and Haskell for this sort of reason. I will endeavor to not give up with Scala! I think I will go back a number of chapters and read the material again as well as double-check my code. I should at least understand this stuff better after that. Hopefully, I'll even find my bug! I'm happy you still have this stuff loaded in your head after finishing the book!
|
|
|
Post by icolomby on Oct 15, 2021 20:56:10 GMT
Hi Craig,
The is_shadowed should be false for this test. The issue is because you are calculating the over_point in the wrong place. You need to negate the normalv before calculating the over_point. If you move your if isInside... above the the over_point calculation you should be good.
Ian.
|
|
Craig Treptow
New Member
Doing this in Scala, while learning Scala.
Posts: 9
|
Post by Craig Treptow on Oct 16, 2021 12:27:35 GMT
Ian, thank you! You just saved me a bunch of time today!
|
|