Strange pinching effect with raytraced reflections

This topic is 1052 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi all

Finally making progress on reflections. I cant seem to find what is wrong with my reflection rays. It is creating reflections that are pinched to the center of the spheres:

Vector3 ReflectionDirection = newRay.direction.nor().cpy().sub(surfNorm.scl(newRay.direction.cpy().dot(surfNorm))).scl(2.0f);

Ray ReflectionRay = new Ray(inter, ReflectionDirection);

CastRay(ReflectionRay, true);


Any idea why this is happening?

Share on other sites

Your code calculates (dir - dir * dot(dir, norm)) * 2, whereas you should be calculating dir - dir * dot(dir, norm) * 2, that is:

Vector3 ReflectionDirection = newRay.direction.nor().cpy().sub(surfNorm.scl(newRay.direction.cpy().dot(surfNorm)).scl(2.0f));


Or just:

Vector3 ReflectionDirection = newRay.direction.nor().cpy().sub(surfNorm.scl(2 * newRay.direction.cpy().dot(surfNorm)));


This is incidentally the main reason why I strongly dislike the lack of (reasonable) operator overloading in languages, it makes it impossible to write such things in a sane way (and, no, separating this simple equation into three or four temporary variables is not sane either). But anyway this is where the pinching comes from.

(actually it's pinching not so much because the reflection is wrong but really because of your error the resulting reflected vector is not unit length, which wreaks havoc on the rest of the ray tracing code something fierce; so a good thing to do whenever stuff looks really weird is to look at your directions vectors and check if they are actually unit length; if they aren't, you've screwed up somewhere)

Edited by Bacterius

1. 1
Rutin
23
2. 2
3. 3
JoeJ
20
4. 4
5. 5

• 28
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631738
• Total Posts
3001950
×