Friday, June 8, 2007

Making a Simple Plant

Plants are everywhere in Second Life, from the free Linden made plants everyone can place to the beautiful creations in Svarga. The complex plant life in Svarga takes some serious building skills, but it's not very difficult to make a simple, texture based plant. Done well, these can look very realistic, especially at a distance. Done poorly, they stick out like a sore green thumb. I have seen a surprising number that were done poorly, including some you have to spend your hard earned Lindens to buy. Look at the picture below. Can you tell the difference between these two roses?

Now, I didn't spend a tremendous amount of time on either of these, so neither looks all that impressive. But this is just a tutorial, and I wanted to illustrate a couple of common pitfalls. Both of these roses were made starting from the same image. The rose on the left has two problems. First, notice the whitish, translucent haze around the edges. These are the edges of the prims onto which I mapped the image of the rose. These hazy edges don't appear on the rose on the right. Second, and this is kind of hard to see here, but the is a fine white line outlining the leaves, stem, and petals of the rose on the left. Again, they don't appear on the rose on the right. This tutorial will explain what caused these problems and how to avoid them using the GIMP.

Here's the image I started with. This works best if you start with a picture of a plant on a white background. If a part of the plant has white in it, such as the flower petals,you're going to have to modify this technique a little. Try using the Magic Wand selection tool instead of the Color Selection tool as I'm about to do.

First, right click on the layer in the Layers window and select "Add Alpha Channel". Next, click on the "Select Regions by Color" button in the Gimp toolbox. For the image I used, I got the best result by setting the threshold at 20. Now, click anywhere on the white background part of the image. This will select every part of the image that has a color value within 20 percent of the color value of the pixel you clicked. Next, press Ctrl-k to clear (delete) the selection. Poof! All the white background disappears leaving only the rose against the checkerboard. Remember from the tattoo tutorial that the checkerboard is how the Gimp represents transparency.

However, we now have a problem. Again this is hard to see in the picture above, but look what we see if we zoom in.

See that white line around the rose petals? This is the white line I mentioned earlier that we could see in the final rose in Second Life. I'm not an expert on graphics, but I assume this is caused because the pixels right along the border between the rose and the white background aren't within 20 percent of the color value of the background. So they didn't get selected when we deleted the background. The good news is we can easily fix this! There are several ways to do this, but here's what has worked best for me. Undo every step back to the part where the white background is selected, but not yet deleted. Now, from the Select menu, click Grow Selection. Make sure it says 1 pixel in the window that pops up, and click on OK. This may be obvious, but this expands the selection by exactly one pixel.

Now, delete the selection as before by pressing Ctrl-k. Now zoom in and you should see this.

Yay! No white line. Save the image as a Targa file. If you don't remember how to do this, go back to the tattoo tutorial.

Start Second Life and upload the image. For the rest of this, I'm going to assume you know the basics of making prims and applying textures in Second Life. If you don't, go through the basic building tutorials at the Ivory Tower of Primitives, or check out the tutorials on Natalia Zelmanov's blog. Make sure you're somewhere you're allowed to build, and rez a cube. Apply the image of the rose (or whatever plant you uploaded) to the front and back faces of the cube.

Now, we want the other four faces of the cube (don't forget the bottom) to be transparent. You could just apply the blank texture to these faces, and then use the transparency slider in the texture tab. However, this will introduce the first problem I mentioned with the rose on the left way back at the start of the tutorial, the white hazy edge outlining the cube itself. The reason for this is that the transparency slider only goes up to 90%. You can't make it completely transparent. Thus, the white haze. This has to be the most common mistake I've seen with plants in Second Life. Again, this has an easy fix.

This doesn't apply just to making plants If you're going to build very much of anything in Second Life, sooner or later you're going to need to make the entire face of a prim 100% transparent. To do this, you need a fully transparent texture. You could make your own using the Gimp. In fact, you can probably figure that one out on your own, but it will cost you 10L to upload. Why pay that to upload nothing . . . literally. Go back over to Natalia's blog. She has a fully transparent texture as a freebie in her store in Second Life. Once you have the fully transparent texture, apply it just like you would any texture to the other four faces of your cube. Then edit the size of the cube to make it as thin as you can. Voila! You have made a plant. Oh, one other thing you should do is copy this cube, put it in the same X and Y location as the first cube, rotate it 90°, and link the two cubes together. This way, you can see the plant from any angle. Happy planting!


Anonymous said...

This was very helpful. Thank you!

Lelani Carver said...

This was STILL a huge help, nearly two years later. Using GIMP 2.6, not sure if that makes a difference. Managed to make something happen with a delphinium picture I had.

Anonymous said...

I am wondering how I can avoid prim flicker with plants I draw that have transparency. Any ideas? I have done a little research and all I found was to make them different amounts of transparency, but when the plant is on one prim this is not possible.

Anonymous said...

PS thanks for the awesome simple tutorial here! you should do more