edit : I'm afraid that tutorial is totally oudated now (as of june 2008), you'd rather use an instanced grass patch to get more accurate results.
(note : you can download this whole tutorial in pdf)
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 only four simple steps, 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+
* if you're using a blender version prior to 2.43 RC, you need that script : randomize (unzip it and copy the python file in ../blender/.blender/scripts)
0. How it works
(note : I got the two images below from this tutorial)
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.
You can find some royalty-free images at http://www.sxc.h, but I suggest you take your camera and make pictures of your own to get real fine looking images.
Here are the two images I used for this tutorial (right-click --> save link as)
1. Create the basic uv-mapped plane in blender
FOR 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 SHIFT + S choose cursor --> selection, back to object mode, editing tab(F9), choose center at cursor).
* 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).
Once the plane is 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) Add some randomness.
For that we'll use a very usefull script wich can randomize the size, location and rotation of the objects you selected.
(Make sure it is properly installed, see at the beginning of this tutorial)
* Select all the grass-meshes, press object --> scripts --> randomize Size Loc Rot
* First, we'll change each mesh location a little : select X and Y axis, use loc: 0.300 (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 use rot: 0.400 on the Z axis
* 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 really change the aspect of your grass. And of course you can change the three values at the same time.
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 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 :
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.
1. Find your grass material.
Change its name to whatever suits you, keep it simple (here, « grass » has became « grassnoalpha »)
Code: Select all
<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>
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)
Code: Select all
<material> <name>null</name> <null_material> </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).
Code: Select all
<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.
edit : another example after some tweaking.
5. Further words
You can download a zip file containing the .blend file + xml + textures.
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...
The example provided in this tutorial is just ok 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.