Esqarrouth
Esqarrouth

Reputation: 39181

ray tracing shadow bug

Comparison

http://pastebin.com/vkTJt0sT

I am trying to render an image similiar to the left one and having problem with shadows+reflections.

Right now, only the shadow code is open for showing the problem.

As you can see, the red ball should be shadowed near the green one, but the pixels all get messed up for some weird reason. When I close the shadow part of the code, it renders the red ball normally without shadows.

I think the root of this problem is also affecting reflections. hope you guys can give me some tips; I’m losing it.

Upvotes: 1

Views: 3082

Answers (2)

Esqarrouth
Esqarrouth

Reputation: 39181

Solved: There was an algorithmic problem which isn't easy to explain,

Another method is: Basicly I make a check if the cosine angle is bigger than 0.0001, if it is bigger then this I don't shadow it

Upvotes: 0

paddy
paddy

Reputation: 63451

Given that your left image shows cancer, this is a classic case of the shadow ray hitting the object off which it was reflected. When hit-testing a shadow ray, you need to exclude the surface that generated the ray. Just pass the source object into your shadow function, and ignore it.

This method only works for convex shapes. If you have shapes that do self-shadow (a torus, for example), you need to be more general. The usual approach is to define an epsilon (floating-point error tolerance) and ignore any intersection points that are nearer than that.

The other approach is to detect which side of a surface you hit. You should not self-shadow on a sphere because the ray is being cast in the same general direction as the surface normal (ie the dot product of the outgoing ray and the surface normal is positive) - this should not be counted as a shadow.

Upvotes: 4

Related Questions