Sunteți pe pagina 1din 13

In this tutorial you will see how to produce a nice-looking grass using blender and

indigo (though the technique is the same with any other modelling software).
See a good example of what you can produce here.
Nothing really fancy here, but as a blender user it's been a long time I was waiting for a
blender-compatible renderer to work with alpha maps, as it's the best way to produce
good-looking vegetation.
Also for the moment you'll have to hand-edit the XML file produced by the exporter at
some point, as I didn't get it to export blended materials correctly (it's still in beta
stage).

One last word : this tutorial is written to be understood by beginners, so I tend to


explain every single step. It may seems long, but it's fast and simple, really.

1. UV-map a plane with an image of grass.


2. Duplicate it several times, add some randomness.
3. Edit the XML to create the blend material
4. render !

So you need :
indigo 0.7 t3
blender exporter 0.7 t3 beta 1
blender 2.40+
and if you've got a blender version prior to 2.43 RC, download this script : randomize
(unzip it and copy the python file in ../blender/.blender/scripts)
0. How it works

An alpha-maped material is a mix of two images :

You apply the alpha map to the original image : only the black part of the alpha-map
appears in the final blended material.

Here are the two images I used for this tutorial (I got them from this tutorial)

You can find some royalty-free images at www.sxc.h, but I suggest you take your
camera and make pictures of your own to get real fine looking images.
1. Create the basic uv-mapped plane in blender
ADVANCED USERS :

Create 2 planes with diffuse material like the picture above, put a
UV texture on the grass-mesh, and go directly to the step 2!

a) First, create the ground under the grass leafes.


We want a 1m x 1m plane, with a green diffuse material.

• In top view, add a plane. Keep the original 1x1 size (as I understood, 1 unit in
blender is equal to 1 meter in indigo, so this is fine for this tutorial).
• Create a new material, call it like you want (here : ground) Put spec=0, and
hard=300.
• Choose a color close to the grass image you're going to use.
b) Then create the basic grass mesh.
It will be a white diffuse material with a UV-mapped texture.

• In front view, add a plane.


• In edit mode, change its size so it fits the image you're going to use (this is very
important, always change the size in EDIT mode, otherwise you will get an
« orthogonal matrix » error message when you will render. In fact, the size in
object mode must always be the same for X, Z and Y. I hope next exporters will
get ride of this annoyance).
• Put the center to the bottom of the mesh, like in the screenshot below (in edit
mode : select the two bottom vertices, press ALT + S choose cursor -->
selection, object mode, editing (F9), choose center at cursor).
• Back to object mode, create a new material called « grass », with a white color,
spec=0 and hard=50.
• Go to texture tab (F6), add a new texture (its name doesn't matter), chose
type=image and pick up the image you want.
• Back to materials, change the texture position from local to UV.
c) Now we just have to UV-map the plane, and our basic material will be
ready.

• You must have at least two windows : one in 3d-view (front view), the other in
UV/image editor mode. In that last one, choose image --> open and pick up the
grass image.
• Switch to UV select mode, in front view, press U, select Project from view
(Bounds).

That's it, your plane is now UV-mapped. You can see the result by pressing ALT + Z
2. Duplicate the base mesh and add some randomness

a) Duplicate the mesh all over the ground.

You could be tented to use the array modifier, but I advice you not to do so.
Instead duplicate it using ALT + D, this will activate instancing in indigo, and speed up
render times. Put the ground-mesh in another layer, and in top view duplicate the
grass-mesh the way below.

b)Now it's time to add some randomness

For that we'll use a very usefull script : « randomize Size Loc Rot ».

• Select all the grass-meshes, press object --> scripts --> randomize Size Loc Rot
First, we'll change each mesh location a little : (after pressing ok, you'll notice that the Z
position has changed, even if you didn't select « Z axis » in the script... well it doesn't
matter, we'll fix that afterward)

Then run the script again, and change each mesh rotation like this :
And to finish, we'll change each mesh size : (don't forget to press « link axis », each
axis must have the same dimension).

Play with this script a while, this can drasticallly change the aspect of the final grass.
And of course you can change the three values at the same time, you don't need to run
the script three times.

Now if you take a look in front view, you'll notice the meshes are not on the ground
anymore.
Let's fix this.
Go in front view.
Put your cursor at the ground level (select the ground-plane, SHIFT + S and
cursor -- > selection, choose cursor as the pivot point, and press move object center
only just next to it)

Now press S for scale, and 0 (zero on the keyboard). That's it, the grass is back in
place.

Add a sunlamp to your scene, a camera, and make a render to see what it looks like so
far. Don't forget to press separate materials
And you should get something like this :
3. Hand-edit the XML file to get a blended material

As for the moment there isn't any official indigo 0.7 version nor 0.7 official exporter,
you cannot get a blended material directly from blender. This will change in the near
future, but for the moment, you'll haveto hand edit the materials XML file
It should be located in the same folder as your .blend file. Its name is something like
xxx-materials.xml
You can edit it with the notepad, or any text editor, provided it's a very small file. (I
recommand XML-marker to edit bigger files, it's free and fast).

You'll have to make changes like in the pictures below, wich I hope speaks by itself :
(some explanations under)
If you're familiar with HTML and XML files, you should not have any problem.
If you've never edited any XML file before, this is a good occasion to see how indigo
« reads » material. It's quite simple.
To be quick, you can read it this way :

<material> this is a material


<name>grass</name> its name is « grass »
<diffuse> it is a diffuse material
<colour>1.000 1.000 1.000</colour> its colour is xxx (here pure white)
<albedo_texture> it has a uv-mapped texture
<uv_set>uv</uv_set> etc...
<path>herbe0.jpg</path>
<exponent>2.300000</exponent>
</albedo_texture>
</diffuse>
</material>

1. Find your grass material.


Change its name to whatever suits you, keep it simple (here, « grass » has became
« grassnoalpha »)

<material>
<name>grassnoalpha</name>
<diffuse>
<colour>1.000 1.000 1.000</colour>
<albedo_texture>
<uv_set>uv</uv_set>
<path>herbe0.jpg</path>
<exponent>2.300000</exponent>
</albedo_texture>
</diffuse>
</material>

2. Add a new « null » material


It's a totally transparent material, wich will be used by every blended material (you can
use one null material for several different blended materials)

<material>
<name>null</name>
<null_material>
</material>

3. Add a blended grass material


This is the final material, that will blend our older grass material « grassnoalpha » with
the transparent material « null », according to the alpha-map (defined between the
<blend-map> tag).
So you must give it the old name of the material you renamed in step 1 (grass).

<material>
<name>grass</name>
<blend>
<a_name>grassnoalpha</a_name>
<b_name>null</b_name>
<blend_factor>uv</blend_factor>
<blend_map>
<uv_set>uv</uv_set>
<path>herbe0a.jpg</path>
<exponent>1.000000</exponent>
</blend_map>
</blend>
</material>
4. Render !
That's it ! Save your file and render

here is another example :

5. Further words
Hopefully with the release of the final indigo 0.7, we will have an official exporter for
blender, that will manage blended material correctly, and the whole process will be
faster and easier.
I'll update that tutorial at the moment.

Now make some grass, and post your tests here !


These are just the basis, there are several way to enhance your grass. Try playing with
the randomize script, use different textures, etc...
This example is just for a quick test,

I hope that helped, and if you have any suggestions to improve it, just tell it on the
forum and I'll update it.

S-ar putea să vă placă și