picture home | pixelblog | qt_tools

omino code blog

We need code. Lots of code.
David Van Brink // Tue 2007.02.27 20:23 // {scripting}

Hacking Sawdust, Part II: Three Dimensions Into Two

This is the second of four parts. Read the first part first.

Suppose you wanted to make one of these:

Here’s one way to proceed.

First, use a three-dee modeling program to create a single sphere. I used LightWave.

Next, we need to translate height to brightness. I chose to write a “shader plugin” in LightWave. LightWave has a cute little scripting language called LScript which, like every misguided cute little language, resembles C or Perl or whatever, but isn’t. It’s really quite tragic. I’m thrilled that newer endeavors seem to favor standard languages; all of the Adobe apps use JavaScript. Good work, Adobe! And a pox upon those who still cling to TCL, despite its standard-ness. And don’t get me started on LSL… cute but oh so wrong.

Meanwhile, LScript actually does work just fine, and here’s the LightWave plugin I wrote. It should be fairly easy to read, and provide a good starting point for other simple shaders.

LightWave’s user-model is a train-wreck. Parts of the UI are deep and other parts are shallow, and some parts that appear shallow have a secret button to reveal incomprehensible depth. To apply this plugin, you need to go to the Shaders tab of the Surface Editor and apply an LScript shader. Then edit the Properties of the shader to apply the script above. See what I mean? But it works.

The other trick is to apply an orthographic camera. I haven’t explained what our goal is yet, so here it is: Create a “height-map” for a sphere, where white is high and black is low. An orthographic camera captures an undistorted view, like so.

And with the shader applied, renders like so.

That was a rather complicated way to get such a simple bitmap. A 20 line C or Perl program could have produced the bitmap for a sphere like that… the value is that I now have a toolflow for three-dimensional models — from a very good modeling program — into these “height map” thingies.

Next stop, Photoshop.

Mysterious Trivia
Interestingly, mapping height to brightness looks exactly like certain solar images. Normally, a glowing object appears “flat” in color, as every point radiates equivalently. This apparent dim-around-the-edges behavior might occur if the Sun tends to emit more photons perpendicular to its surface. (Or if it was transparent, but the Sun is in fact opaque.)
Chris Hatton // Wed 2007.06.27 03:403:40 am

While this is a working solution (and kudos for dealing with the uneasy world of LScript), unless I misunderstand your aims I can think of an alternative to using the script which turn out to be more flexible. Simply, apply a Gradient layer to the colour texture of your surface, specifying the gradient as ‘Y distance to target’. Use a null object at 0,0,0 for the target. Then set black at distance 0 and white at the maximum distance/height of your surface. Then continue to use the orthographic camera as you’ve stated.

David Van Brink // Wed 2007.06.27 09:169:16 am

Hi Chris — Ha! You’re so right. Sometimes I’m drawn to doing things the hard way. Thanks for the tip, and the pointer to one of the many many useful bits lf lightwave, which I’m learning of so slowly. :)

oh, i dont know. what do you think?

(c) 2003-2011 omino.com / contact poly@omino.com