It’s another technical post kind of day. If you’ve ever struggled with making trees for a game, I have walked through the valley of shadow and ugly normals so you won’t have to. This is the forbidden knowledge I have been given by the nyrns of Blender.
Chapter 1: The Branches
What does it mean to be a tree? For starters, you’re going to need a trunk and some branches. Obviously we don’t want to waste any time, so modelling it all by hand is out of the question. Instead, start with a curve. A bezier curve, in fact. Before you start positioning the points of the curve to start your tree, you’ll want to match these settings in the curve data panel:
The important parts here are setting the fill of your curve to full to make sure your trunk wraps all the way around your curve. The bevel depth decides how thick the trunk is displayed, the bevel resolution will make your trunk smoother at cost of more triangles. I’d recommend keeping it as low as possible while you’re building the tree and then fine tuning it later before you convert it all to mesh. The same goes for the the Preview U panel under the shape resolution. Less is more as it gives you more control while building.
Now is the time to grab the control points, move them around (G) and extrude (E) to shape them into a base shape for the tree¹.
Now that we have this jumping off point, you can just duplicate (Shift+D) the curve in object mode², jump back into edit mode and do the same to make a few branches. You don’t have to go overboard with making a realistic amount of branches with sub branches since we’ll be faking the way the leaves grow anyway, but feel free to go into as much detail as your poly budget can afford.
Now that we have a barebone skeleton for the tree, it’s time to adjust the resolution settings to get as much fidelity out of the curves as needed. It’s a good idea to jump into wireframe (Z) to see how the actual geometry is turning out.
Once you’re happy with the number of edge loops, select one of the curves in object mode and press Alt+C to open up the Convert To dialog. Select Mesh from Curve and repeat for any other curves you’ve made.
Unfortunately, you’re still stuck with an alien looking mess of tubes, so let’s remedy that. Select one of the new meshes and go into edit mode. Now before we start pushing vertices around, make sure proportional editing is set to connected like this: . I like to use a sharp falloff, but just use whatever works best for you. Now you can go around the branches and select an edge ring with Alt+Right Click. Make sure you’re in vertex selection mode and hit Alt+S to expand the vertices out or in, increasing or decreasing your proportional editing range with the mouse wheel.
You might need to move some of the branches’ end points around to hide the ends inside the trunk. You’ll still be left with hollow caps where the branches point outwards, so just select the vertices around the ends, extrude them out a little bit and merge them with Alt+M in their center. Now is also a good time to merge all the meshes into one.
Finally, you’ll probably want to UV the base of the tree before we continue. I’m just going to cut one seam along each branch, making sure it faces in a direction that won’t easibly be seen by the player. The quickest way to do that is to make sure Live Unwrap is enabled in the Tools Window (T in the 3D View to display that), then select one of the starting vertices on a branch and while holding control, select the end point and marking a seam along the now selected edges³.
¹I’ve decided I’m making a shrub here, but it all applies to trees as well, it’s all about the shape.
²You could theoretically do it all in edit mode, but making a separate curve for different elements allows you to adjust the resolutions for them later.
³Results may vary on complex branches. Always make sure to check what the algorithm actually selected before committing.
Chapter 2: The Leaves
Before we can make the tree magically grow leaves, the tree needs somewhere to grow the leaves from. You could grow them directly off the branches, but that would result in a very strange, fuzzy looking tree. Instead, we’ll make a few spheres that the leaves can grow off which gives a whole lot more control over the final look. Start by creating an Icosphere, going into edit mode and moving a few duplicates of the mesh into place. They don’t need to be very high resolution, so make sure to set the subdivisions of the sphere to 1 when you create it. Also, make sure create UVs is off.
Set the shading to smooth and open up the UV editor with all the faces of the spheres selected. Load in a leaf texture and you’ll see these terrible UVs:
Conveniently, that’s exactly what I want in this case¹. That orange triangle is every face on the spheres UVd individually. Now it’s just a matter of select all of these, scaling them up a little and you have yourself something that looks somewhat like leaves from a distance.
Of course, it still looks atrocious close up. If you’re aiming to make LODs for this tree, I recommend you create a duplicate of these spheres before continuing, since they work great for seeing the tree from a distance and are really cheap to render. You’ll also need a backup of the object again at a later point, anyway.
Moving on, it’s time to give the tree its foliage. In order to that, you’ll need a leaf plane. Create a plane, name it LeafPlane and enable Generate UVs and assign the leaf texture to it. Jump into edit mode, select all the vertices of the plane and move them so that the pivot of the plane matches up with the stalk of the leaf².
Now we make the magic happen. Select the spheres surrounding the tree, navigate to the Particles panel and press the big New button to create a new particle system.
The aim here is to create a hair simulation that uses the LeafPlane we’ve just made to give the tree its fluffy leaves. To do that, change the particle system type from Emitter to Hair. There’s quite a few settings we need to tweak here, so I’m just going to list them down with a screenshot on the right. I’d encourage you to play with the settings as much as you can to see what works for you. Once you’re happy with the result, create a backup of the object and move it on a different layer by pressing M and then selecting a layer in object mode, just in case you want to go back and make adjustments later.
After that, go into the modifier tab with the original particle object selected and press the convert button. Blender is now going to create an object for every particle, so make sure you don’t lose your selection now. Press Alt+C again and convert the selection to a mesh and then press Ctrl+J in order to merge them back into one.
I just quickly assigned a material with the leaf texture to the resulting leaves object and created a hemi lamp to preview the tree. It looks something like this:
It’s a nice start, but still not very good. All the leaves normals are pointing all over the place, making the tree look very early 2000s CG. But we can fix that! First, select all the leaves in edit mode, create a new Vertex Group and assign everything to it. Tab back into object mode and merge the leaves with the base tree (don’t forget to assign material slots).
Now bring in the earlier backup of the spheres you used to create the particle system. Go into edit mode, select all (A) and use Alt+S to expand the spheres until they completely cover the leaves.
For even better results, add a Subsurf modifier and make sure the spheres are perfectly round, polycount here doesn’t matter since the object will just be used to bake the vertex normal direction for the leaves. Apply the subsurf modifier before you move on.
Back in object mode, select the tree and add a normal edit modifier.
It may throw up a warning to turn on Auto Smooth. You can do that in the mesh tab next to the modifiers. Make sure you set the angle to 180 degrees so that everything on the tree is shaded smooth.
With that out of the way, it’s time to set up the settings for the Normal Edit modifier. Set it to Radial with the enlarged sphere as a target object. Select the Leaves vertex group as the mix target and, (this one is up to personal preference – experiment!) set the mix factor to 0.9 to keep a small amount of the original normal direction.
The leaves still won’t look perfect though! This is because the back of the leaf is always facing the opposite way to the front³. We’ll be fixing this in engine, so don’t worry about it.
Now the tree is ready to go into the engine of your choice. I’ll be moving on with Unity, but the principles are the same. All that’s left now is to export the tree as an FBX file. To do that, feel free to copy my export settings for Unity.
¹Because I’m lazy. There’s nothing stopping you from making a unique texture for the bubbles. I’d suggest a tiling version of the leaf texture with leaves thrown over each other to wrap around the sphere.
²If you want to, you can now add subdivisions to the plane and bend them around a little bit to give the leaf more volume, but it will exponentially affect your poly count.
³Duh. Seems obvious, but it took me days to realize this.
Chapter(-ish) 3: The Magic
Here is the part I was struggling with for a long time. How does one make leaves look leafy? The answer lies in the shadows. Standard shaders don’t work particularly well due to the way light works on leaves in real life. They tend to be somewhat translucent, so the back of a leaf will be lit up by the sun hitting it from the front, most shaders don’t accommodate for that. The solution: use a translucent shader or, alternatively, a shader that gives you full control over shadow colour. I found a great translucency shader for Unity by Farfarer that could serve as a good starting point for a custom one, although you will need to add your own transparency function. For Buto, we’re using the Unity Chan 2.0 shader, which means we get full control over the colour and grading of the shadow. The main thing is to keep the contrast between light and shadow on the leaves as low as possible. Ambient lights or global illumination help immensely, too.
All in all, once the right shader is in place, it all comes down to fiddling with colours and intensities and there’s your tree.