Wednesday, October 31, 2012

90 – Pipeline and churches

I was not in the mood for terrain streaming, so I worked on something different. There are tons of tings to implement, so I doubt I'll ever have a shortage of things to do. But I did implement a new global height interrogation API, but only with integer coordinates. When you have one single heightmap in memory, querying a height is easy. When the map is chunked into small pieces that can reside on disk or in memory, this becomes a lot harder.

I continued working on procedural buildings. The idea is to have a few randomly generated master parameters, like global shape, number of rooms, number of floors, etc. and then run a piece of code that  fully generates a new building. This works fine for simple buildings, but in order to get a really unique look for each building I need to work a lot on the generator, probably years.

So I am investigating two alternatives. One is just modeled buildings. How will a city look with traditional buildings modeled in some 3D program?

This is too easy. And I lack modelers to do the job. And all other resources. The other alternative, that I am actually investigating is taking these modeled building, breaking them into larger standalone building blocks and trying to see if I can assemble buildings like a form of LEGO.

So I started with a simple but full of personality church model I found free on the web. Here is the mesh rendered with a mix of spherical harmonics and Blinn-Phong shading, without textures: 

This is a single mesh that even has some not that great texture mapping. Her is the church rendered with a single wrapped brick texture:

It is not a very high-poly model, but I looks quite good and has a cartoony feel. Still, it has a lot of detail, so making it modular will be quite a challenge:

The first thing I did is to break the model into pieces, using Blender. I only did some elementary breaking in order to have different materials. The final breaking will have to take into account the way pieces are meant to go together. This is not done yet.

Then, in a process that took me hours, I upgraded my mesh importer/exporter to handle meshes with multiple sub-meshes. This was quite difficult  because the Model class from XNA, while apparently having a very simple and intuitive VertexBuffer layout, actually seems to be quite deceptivelly complex and counter-intuitive.

The final problem was how to make the game understand what piece what material should use. This is a pipeline issue. Pipeline is one of the most important parts of any 3D project, and my content pipeline sucks. So for now I assigned each part some random texture that is loaded:

And now from behind:

Parts of the church are under the terrain? Why is this? Remember the counter-intuitive VertexBuffer layout I mentioned? Well I am not the only one who fell into that trap. A small piece of code that I copied that only computed bounding boxes for an input mesh also had the "wrong" interpretation of the layout, generating faulty bounding boxes. This is a very weird issue. Need to investigate further.

Here is a shot after the fix:

Looks pretty good! Textures are stretched  but the general quality of the renderer is satisfactory, having all previous details. Her are two comparison shots of the side of the building with and without specular highlights:

So the next step is to break up optimally the building into parts, edit them to make sure they fit together good, and finally assign good textures, maybe even with some prebaked AO to each part and see how that looks.

After I need to test other configurations of mixing the blocks together to see if they look good.

And finally, see if the blocks can be included into gameplay. My cities won't only be procedural, but the player will be able to create though gameplay new buildings in the city.

No comments:

Post a Comment