Wednesday, 11 July 2012

Blender 2.57b & XNA 4.0 Part I


Next >>



I have been playing about with blender, I know Ed is a big fan of the XSI Soft Image tool, but I never really got on with it, mostly due to me not spending any quality with it. So, why Blender? Well, first off, it’s free! There are also loads of tutorials for it, loads on Youtube and the host site, Blender.org has a tonne. The latest draft of Blender, 2.57b is a great improvement on the later versions, but like all the other modeling tools I have looked at it still helps if you know the keyboard short cuts to help navigate around the UI.

With this set of short posts I am hoping to introduce you to Blender 2.57b and how you can then get those objects exported and rendered in your XNA projects.

Where can I get the goods!

Well, guess where? yep, the host site Blender.org as you will see there is a download tab and link off there main page where you can download the application. So pick the flavor you want I went with the 32 bit version even though I run a 64 bit OS, mainly because I when ever I have gone to use a 64 bit version of Blender it just didn’t play well. So I went safe and took the 32 bit version.

How do I use this crazy tool!

OK, first look at the UI and it’s quite busy, but it’s all pretty strait forward. What we have to start with are five windows, at first the windows in blender are not that easy to spot, but here are the five we get to start with.

At the very top, we have an info window, we can tell it’s and info window because it has this icon



Then, off to the top right we have a Outliner window denoted by this icon



Below this screen we have a Properties window, we can tell this thanks to this icon



Then, at the bottom of the screen we have a Timeline window, expressed with this icon


And finally, the big window in the middle will be the one we focus on for now, this is a 3D view window which has this icon




OK, so we have a lot of screens, but as I say, we only need to focus on the last screen for now, we will touch on the other screens and how to create and close more, but I think you have enough on your plate with these five and with what we can do with the 3D view window. As you can see Blender gives you a cube to start with, we will use this throughout the rest of the post, we will make some simple modifications to to and export it to an FBX file then use it in an XNA 4.0 project.

3D View

So, I guess this will be the work horse screen for this post. In this window we will do the majority of our modeling, the first thing we will do is look at how we can move around and view the 3D space. So, off the bat we can change the view with a hot key, so on your number pad hit 5, this switches the view between perspective and orthographic, as you hit the 5 key you can see the view change and also the little description in the top right corner of the window.





So, how do we translate and rotate our 3D view, well wheel have a mouse, so, I just use the roller to translate in the direction I am facing, but if you don’t have a mouse like that you can use the + and – keys. Again, with my mouse, to rotate around the scene I click my mouse wheel, hold it down and can rotate the scene, you can do the same with the number pad with the 8, 4, 6 and 2 keys.

Export to FBX

OK, we have this box model, how do we export it so we can use it in XNA? Well, this, for now is easy, simply click File in the Info window (remember, the one at the top) and you will get a drop down menu list like this:

Hover over the Export option, and you will get another drop town like this:



And pick the Autodesk FBX (.fbx) option and you will get a screen like this:




Now the handy thing about this screen is you can set up book marks to remember where you want to save your stuff to, we will create one now so we can copy the model directly into the content folder of our project.

In the top of the screen type in the path of your content folder for the model, then, under the Bookmarks panel, hit the Add button


So now, I can get to this folder each time I go to save a model. Now, under the address bar at the top, change the name of the model from untitled.fbx to cube1.fbx. Further down that left hand side of the screen are the Export FBX options, first thing we will do is scale down our cube, a blender unit is a big space, I am going to set the scale to .01. You can do this by either clicking on the arrows either side of the value or simply clicking on the value in the center and typing what you want in there.



You can also see that Blender by default sets other export options, I will disable X 90, this rotates the exported mesh along the X axis 90 degrees, in blender Z is up so this can be useful if you forget to model using Y as up, but for this export it really does not matter, I am doing here as I try to model with the Y axis as up, Ill come to that later. I am also switching off the Empty, Camera, Lamp and Armature and switching off smoothing and as there is not animation, switch off Enable animation and Key frame optimization, you should have a Export FBX panel like this:



And now we hit the Export FBX button up at the top next to the address bar. After a second or two, we should now have a Cube1.fbx file in the model folder of our content project. In our XNA project we can now just add the existing item:



So we can now render this mesh in XNA, just like we can any other FBX mesh.



Now, this is all pretty simple stuff I know, but this is just a start. In the next post I will show you how to UV map and texture your cube, and here is what I hope to cover in future posts:
  • Creation of normal maps.
  • Creation of specula maps.
  • Creation of dual textures.
  • Skinned animation.
All the above and how you can then use them in your XNA 4.0 projects. Any questions on this post, then please add a comment and I’ll do my best to answer you.

Next >>

Instanced Skinned Animation with Deferred Lighting



So, got some more time on the engine tonight and managed to instance the skinned animations.

Also forgo to mention in the clip the particles are also instanced, so pretty much everything in the scene is instanced :D And again a 1440x900 resolution. Also, and I never mention this, there is no culling, I am throwing everything at the card every time, oh and the terrain is HUGE!! lol

What to do next? Duno, maybe scene management, or may start on a game, not sure if XBox of PC would be the preferred platform, any ideas?

Deferred & Skinned Animation



OK, so another post without code, but I am super busy, I don't even have time to work on my own engine these days, well, tonight I did :)

My mission tonight was to get a skinned mesh rendered in my deferred lighting engine, and then instance it, I got almost there, but now it's time for bed, Ill do the instancing next time I get to work on the engine.

Rendered this at 1440x900, and there are some post processing effects in there too, and it still rendered at a nice pace :D

Deferred GPU Terrain And Instanced Particles



So,I thought it would be nice if I got my instanced particle system and put it in with my deferred render engine, turned out quite well I think..

I could really do with some new free music to use in my clips, anyone out there fancy donating some?

As ever, comments are welcome :)

1,000,000 Particles in XNA



If you have seen my other clips, you know I have been playing with instancing, well, here is a bit more but this time particles.

I am getting about 20fps with a million particles, all the rotation and animation is done in the shader, with any luck, this might make for a XNA-UK UG talk.

Monday, 9 July 2012

March 2011 Talk – Post Processing Framework


So, for those of you that aren't part of the meetings group here at the XNA-UK UG, I gave a talk at the start of this month on a post processing framework for XNA 4.0. Here are a few pics of the talk and some screen shots of the post processing framework in action.

The Talk





Post Processing Effects in the Sample

Depth Of Field
A modification of the DoF effect from Kyle Haywards sample.




Bloom
I don’t recall where I got this effect from, may have been off Rocket Commander.



Haze
Taken from Kyle Hawards sample.



Radial Blur
Taken from Rocket Commander :D



Ripple
Think this was a MS pixel shader I found somewhere..



Fog
After making modifications to the DoF shader, I thought it would be dead easy to use similar calculations to do fog, here it is :D



Sun
On the 21st of April 2010 I posted up an article on Sgt Conker, this is the same code put to use in the framework, as in this sample we have access to the depth buffer I am able to show the sun working with occlusion. BUT I have still not implemented the occlusion of the flare, but I am sure you would love to have a play and fix that :D



At the last moment before I went to give the talk I ran it on my 360, tried the bloom, DoF and Radial blur effects, all worked fine with the exception of the radial blur, so if you wan those effects in a 360 project, then they may need work.

My inspiration for post processing first started when I got into XNA playing with the Hazymind Engine and Micheal Quandt use to post there regularly and put up a post processing sample for the engine, then I came across Kyle Haywards post processing framework, and have continued with a similar framework of my own. I would like to thank both these guys for the inspiration there contributions have given me. As I think I said during the talk, “We all stand on the shoulders of giants”

You can get the power point presentation here and the solution code here.

Hope it helps :D

March 2011 XBLIGUK & XNA-UK UG Talk



For those of you that follow my blog but are not members of XNA-UK UG meetings group, here is a heads up on a talk I will be giving in March on post processing, you can see the group post here.
See you there :D