Tuesday 28 October 2008

Creating LOD-friendly versions of existing sculpts

WARNING: Stuff for builders ahead (but not that hard)

Sculpties are great. You can make all kinds of shapes out of them while keeping your prim count nice and low. That's why this window is two prims, not seven or more:


Trouble with sculpties is that they were designed for organic or smooth shapes. That means that when you view them from a distance, they lose some of their geometry. For example, here's the defalut sculpty shape, an apple, viewed up close, and far away (but blown up to the same size in Photoshop):


It's still basically apple-shaped, even at distance... and of course, at distance, it only occupies a handful of pixels on your screen, so you can't really tell that it's less appley than before.

This process of simplifying sculpties the further they get from you is called "LOD culling" (LOD stands for Level Of Detail) and it's a performance trick - it means that you don't have to render the full detail of things that aren't near you. Most of the time, when we use sculpts the way Linden Labs intended, it works fine and keeps our framerates up.

Trouble is, us builders love to pervert the course of technology and we use sculpts to make things like that window up there. Railings, bookcases, stairs, and ladders all get done too. And when you "simplify" the geometry of a window frame, you don't get a simpler window. You get a tangled mess:


YIKES!

Not good, right? That happens because every single vertex (3D point) in that window is defining an important corner, whereas in the apple, the points are all just in a smooth curve.

So what can we do? Well, we can exploit the fact that LOD culling is affected by size. For example, here's a big window and a small window, side by side, from a moderate distance away:


See how the big window hasn't "broken" yet, while the little one has? But that big window is far too big for a house. In fact you could drape a canvas over it and live *in* it. So what we need is a sculpt that looks smaller than it really is.

And luckily, that's dead easy. What we need to make, effectively, is a model of a small window. A large instance of a small model = a normal sized result.

Sculpts, you may or may not know, use colours to represent points in space. Three dimensions = three colours red, green, blue). So the dead centre of a sculpty is represented by a medium grey colour, which is at 50% red, 50% blue, 50% green. It's drab:


While a normal sculpt is bright and colourful, because its points are all over the place:


(That's a piano pedal, by the way.)

So to make a sculpt "smaller", we need to make all those colours closer to the middle of the colour-space, i.e. closer to 50% grey.

To do that, in say, Adobe Photoshop ('cos that's what I happen to have here,) open up the sculpt image and create a new layer.


Then pick the 50% grey from the colour pallette:


Click the fill tool:


Click in the image to flood it with grey.
Now change the transparency of the grey layer to, say, 50 or 60%:


The sculpt image now looks faded, like this:


Finally, save that as a PNG or a TGA and import it back into SL.

When you apply it to a sculpt, you'll see that it now looks much smaller than it used to. But if you select the object and hold down ctrl and shift (to go into resizing mode,) you'll see that the object's real corners - its "bounding box" - are much bigger than the object looks:

So now SL thinks that your normal-sized window is actually much bigger than it really is, so it draws it at full detail from much longer distances. And you can have pretty that looks good even in long-distance photography:


Credits:
The window I used as an example is from Rhode Design.
The trees you can see in the last photo are from Sculptomancy, and they already use the technique in this article.

Caveats:
SL does things for a reason. LOD culling is there to save people's framerates from imploding. If you do this to every sculpt you make or use, all you'll do is make your place really laggy. Stick to just outdoor prims, like doors, windows, and trees. My stairs, for example, aren't like this, because you can only see them from indoors.

3 comments:

Anonymous said...

Very informative and useful. Thanks.

Anonymous said...

Hum yeah I got all that...

Anonymous said...

Come back! We have a plurk that proves you are aliveeeeee!