moo
New Member
Posts: 5
|
Post by moo on May 19, 2019 21:35:05 GMT
Hi Firstly I need to say how much I'm enjoying the book. I'm having so much fun writing the ray tracer. However, I've hit a bit of a problem that I'm struggling with. I've reached Chapter 11 - Reflection and Refraction, and I'm struggling to combine the lighting, reflection and refraction colors. I'm using the Tuple add function, which makes the unit tests pass, but this causes object that are reflective or refractive to shift towards white. Objects that are reflective, and particularly objects that are transparent sort of glow as the various colors add up. I thought that maybe I was supposed to multiply the color tuples rather than add, but the unit tests don't pass when I do that, and the renders come out almost entirely black (because multiplying any color by black gives black). I've attached an example. What am I doing wrong? Michael Attachments:
|
|
|
Post by Jamis on May 20, 2019 19:51:16 GMT
Hey moo! Great question. I assume that the sphere in your picture has a material color of white? The important thing to remember about reflection (and refraction) is that the result (as you've found) is additive. This means that if your base color is bright, it will quickly become washed out with a higher reflection and/or refraction value. You can compensate for this in two ways. First, you can make the base color darker. A black surface makes a great mirror, because the reflected color is not modified by any surface color. Second, you can set the diffuse and ambient values lower, which has the effect of reducing the brightness of the surface color. As a rule of thumb, try to make sure your reflection, ambient, and diffuse values do not add to much more than 1. (If you have a surface that is both reflective and refractive, just use the higher of the two values for this purpose, since the two effectively get combined into a single value.) Further, if you have a surface that is reflective or refractive, set the ambient value much lower. The more mirror-like the surface, the closer to zero ambient should be. An example: if you want a highly reflective red ball, try ambient=0, diffuse=0.4, reflective=0.6, color=(1,0,0). A glass sphere might have ambient=0, diffuse=0, reflective=1, transparency=1. If you want a colored glass, use a strong color with a very small diffuse value, like ambient=0, diffuse=0.1, color=(1, 0, 0), transparency=0.9, reflective=0.9. Ultimately, the best way to grow your intuition about how these settings should be set is to just experiment with them, but hopefully this gives you some ideas. Good luck!
|
|
moo
New Member
Posts: 5
|
Post by moo on May 20, 2019 21:46:56 GMT
Hi Jamis Thanks for your reply. It's was very helpful. I've made the changes you've suggested to my scene and re-rendered it. I think it's much better! Attachments:
|
|