Thursday, March 27, 2008

The Solution

My esteemed Cordelia,

I must apologise. When I came to the close of my last Missive, I must have left you in a frightful state. To appeal to your fancy with stories of the wonders of parallax mapping, only to cruelly cut down the technique with diagrams of despair...! it strains morality. But fear not, Cordelia: I have a solution to the problems of parallax mapping. I will first solve a problem that you may not yet have thought of (although it is intimately related to the problem already discussed): That of a ray entering below the polygonal surface.

Let us return to the issue of the polygonal versus the virtual surface. Until now, I have treated them as two separate entities, linked by large-scale shape but unconnected otherwise. But this is not so! Pray examine, Cordelia, the other feature present in the first picture of that last posting: to wit, the brown line. If the polygonal surface places a maximum on the height of the virtual surface (normal to that polygon), then the brown line may be thought of as a minimum. These are two of the extents of the area in which the entire virtual surface must fall. In the two-dimensional case here, we need define two more: the left and right. Behold:


What, you may ask, does this gain us? Well, in this ideal case, nothing. But now consider this less auspicious viewing ray.


In this case, the viewing ray has no intersection whatsoever with the polygonal surface. How, then, is it to be rendered? The fragment program is never invoked!

And indeed, with classical parallax mapping it would not be. But in this picture I have also given the answer: The side itself is rasterized, and invokes the fragment program. Not the same fragment program as for the top face, for you may be certain, Cordelia, that it would be quite confused by its unexpected orientation and produce all manner of outlandish results. But some small modifications can easily correct this problem and lead to the correct generation of texture indices, ray marching, &c.

Nota bene: the sides, like the top, will benefit from backface culling. After all, a ray entering the box I have defined here will only produce a first intersection with the inside of one of the sides if it originates inside the box itself (a situation I do not here address) or through the bottom. But if the parent object is polyhedral and closed, no such ray can arise save one which originates in the cavity of the parent object, which is again a situation I do not here address. In the common case, therefore, the only possible explanation for a backface collision with either the top or the sides is that polygons have been rendered in a suboptimal manner, and that a later polygon will overdraw this one. Better, then, not to render this first erroneous polygon at all.

With condolences on the mishap that recently befell your livery,

Ben

No comments: