Friday, 13 July 2012

Blender 2.57b & XNA 4.0 Part III

<< Prev | Next >>
OK, so still not much in the way of XNA, I guess I should have just called this set of posts Blender 2.57b, but all this stuff I am using form my own XNA projects, so I guess if you are using XNA and want to use Blender, then this shows what can be done, well if nothing else, what I am doing…
In this post I am going to look at creating normal maps for our cube mesh, we will UV map it as before, and this time I am going to create a six sided dice, but before we paint our texture onto our dice we are going to create a high poly (really detailed) version of our cube and add the number markers to it. We can then use this high poly mesh to generate a normal map that we can then use to render against our low poly model and give the impression that there are dips on the surface of the dice.
So, we are going to start off with a UV mapped cube, like we had in the previous post, like this

We have a 3D view window and a UV/Image Editor window in our Blender session. We now need to create a high poly version of our mesh, to do this go into Object mode in the 3D view and hit Shift-D to duplicate our mesh, the mesh’s edges will turn white, this is our copy of the mesh, hit enter to keep the mesh where it is. Now we want to move this duplicated mesh to another layer. Layers in blender are handy for separating your scene, for this we are going to use it as a holding bay for our high poly mesh. With the mesh selected in Object mode, hit the M key, this tells blender we want to move the selected item to another layer and we will get the layer selection box pop up like this

You can see the box at the top left is in dark grey, this is the layer we are in now, click the box next to it (does not have to be that one, you can pick any layer you like really) and the new mesh will be moved to that layer. You can see what layer you are in and if you have anything in a layer and indeed if you have a selected object in that layer by looking at the bottom of the 3D view window, there is the layers icon(s)

As can be seen in the image above, we now have 2 layers with objects in, the second layer has our active object in it. You can quickly move from layer to layer by simply clicking the layer icon you want to switch to, or while the mouse is over the 3D view, with the 3D view in Object Mode you can key the layers number (not from the number pad though.)
So we want to be in the second layer with the new duplicated mesh selected. We are now going to make our high poly mesh, go into edit mode, as we have in the previous posts, and now, on the panel to the left in the 3D view, find the Add panel

In here is an option called Subdivide, this will take all the selected elements and, well divide them in two, so, with all our vertices selected click the subdivide button about five or six times, this will give us a fair few faces to play with, you should have something like this

Now we have a high poly version of our cube, we ca now start to add a bit of detail, to do this I am going to use the Sculpt mode, so, select sculpt mode in the 3D view

We now need to set up out sculpt brush on the left of the 3D view window, I am going to set my radius to 40, strength to 1 and to subtract like this

I am now going to put the number dimples on the mesh, remember the opposite sides of a six sided dice add up to seven, ill start with four dots on the first face I do, then using the * key on the number pad, rotate over the top to the other side to mark another three dots. Now, as you do this, check out and if you like use the Symmetry tools on the brush panel, it will save you doing ALL the dots your self :D Oh, and be aware of the axis you are in when using it :P

So now we have a high poly mesh with lots of detail in it, how do we now create a normal map from it? First thing we need to do is create a texture so we can write the normal data to it. In the UV/Image Editor create a new image by clicking the +New option at the bottom

Now name the texture NormalMap and keep the defaults and click OK. Now, in Object Mode, select the high poly mesh, hit 1 to go to our low poly mesh and with Shift held down select our low poly mesh, we now have both mesh’s selected, with Shift still held down, select the high poly mesh layer from the layer icons, we now have both our mesh’s and both our layers selected and your screen should look something like this (I have circles in red what the layer icon should look like at this point)

We now have our mesh’s and layers selected and a texture set up ready to accept our normal data. To now write the high poly normal data to the texture we will need to use the Properties window

At the very bottom of this window is the Bake panel and this is what we will use to generate the normal data in the NormalMap texture, configure your Bake panel so that it looks like this

So you have the Bake Mode set to Normals and Selected to Act is selected. Now, hit the Bake button, the one at the top of the Bake panel with the camera on it. After a moment or two you should have a screen that looks like this

Now we have a normal map we can save the texture, exactly like we did in the last post with our color map.
How can I see what my normal map will look like on the mesh?
In the Properties panel select the texture option as we did in the post before, name the first texture NormalMap, type to Image or Movie, then in the preview panel below, select Both, and below that, in the Image panel select the image icon next to +New and choose the NormalMap texture we just generated and saved.

We now need to tell blender to use this texture as a normal map. In the Image Sampling panel set the Normal Map option, under the Mapping panel set the Coordinates to UV so it uses the UV map we have for the mesh. In the Influence panel below un select the color option and select the Normal option under Geometry. Now hit F12 to render the cube in blender and you will see the cube rendered with the normal map we have just created.

I am now going to texture my cube just as we did in the last post. So here is my dice rendered in Blender (I know, not the best dice ever, but you can see the effect, also on the face with 2 dots, think I have a modeling error there :P)

So to do this we need to let blender know to use our color map in the render. Just as we did with the Normal map, we have to set the texture up in the Properties window, create a new texture, call it ColorMap under the Image panel, select your color map image, under Mapping panel, set to Coordinates to UV, hit F12 and see it render :D
Here is the mesh, it’s color map and normal map rendered in my deferred lighting engine.

As ever, comments are welcome :)
<< Prev | Next >>

1 comment:

  1. Thnx for this helpful tutorial :)!