Latexluv opened this issue on Jun 04, 2010 · 182 posts
bagginsbill posted Mon, 14 June 2010 at 2:44 PM
Quote - How does Poser avoid division by zero in D/cos(alpha) when alpha = 90 degrees? Does alpha ever reach 90 in Poser?
That's a great question. I took it into account, but first let's see if we can figure out if alpha can ever reach 90.
So - for alpha to be 90, it means that the polygon we're looking at (or micro-polygon - doesn't matter) has to be exactly parallel to the viewing vector. Which means the viewing vector cannot intersect the polygon. Which means the shader will never be called in this case, because by definition the perspective view of such a polygon has zero width, effectively making it invisible. Poser doesn't render invisible things.
However, in practice, due to round-off error, I allow for the possibility that the angle could get so close to 90 that cos(alpha) becomes effectively 0. And if it is 0, then we have a problem, because we can't divide by 0 - the value is undefined.
So in my shader, (not what I showed earlier) I don't actually use 1/cos(alpha). Instead, I add a slight bias, and use 1 / (.00001 + cos(alpha)). This means the denominator never goes to 0, no matter what.
It could go to 0 if cos(alpha) becomes negative, but that would mean the surface is pointing away from the camera - we'd be looking at the back of the polygon.
The truth, though, is that Poser doesn't use cos(alpha), but instead uses the absolute value of the cos(alpha), which means it is never negative, even when we are looking at a back-facing polygon.
Renderosity forum reply notifications are wonky. If I read a follow-up in a thread, but I don't myself reply, then notifications no longer happen AT ALL on that thread. So if I seem to be ignoring a question, that's why. (Updated September 23, 2019)