Compute the thickness of an non-convex object

May 19, 2007 at 10:24 pm (Tips & Tricks)

Knowing the thickness of an object can be useful, for things like computing single-scattering of light through a participating media (think fog or a translucent material). The most obvious thing to do is render out the depth of the back faces, render out the depth of the front face, then use the difference between the two as the thickness of the object. This is fine-and-dandy for convex objects, but not so practical for more complicated objects. Look at a simple example of such an object in the below figure. A handy way to compute the thickness regardless of the object is to sum up the depths of all front faces at a pixel, then sum up the depth of all back faces, and subtract. You don’t have to resort to something like depth peeling to get these depths, just turn on additive blending when you render out depth for front and back faces. This was shared with me by my friend Thorsten Scheuerman but can originally be found in the NVIDIA Fog Volume SDK sample.


Thickness diagram


1 Comment

  1. Keenan said,

    Hey – (you may already realize that) you can do this in a single pass using GL’s two-sided color mode (GL_VERTEX_PROGRAM_TWO_SIDE_ARB) which lets you specify a different output color for front and back faces. Alternatively, you could have the vertex shader set the color depending on which direction the triangle is facing. To blend negative and positive values in the same pass you may need to turn off color clamping with glColorClampARB(). Don’t know if you’re using GL, though!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: