Friday, November 25, 2011

Material World

I often get questions about the texturing in the screenshots and videos I have posted so far. There is nothing really new in what I do, still it may help to discuss it.

The material system I devised shares the same core philosophy as the voxel system. It is all based on my hope that if you put enough layers into something it will eventually look good. I know this is an awfully technocratic approach to art and design, it is just the way I found to compensate my lacking skills. I also hope this system is flexible enough for true artists when the time comes.

The volumetric world definition is a set of layers. Each new layer adds or subtracts to the layers before. If you look at a cliff formation, there is one base layer for the main volume of the cliff, then other layers on top of it, each one adding a different type of rock.

Each volumetric layer has a different material assigned to it. The material system defines the look of each layer, and very important, how transitions between different materials are rendered.

Let's look first at how material boundaries work.

Once voxels are converted into a triangle mesh, each triangle ends up having a material assigned to it. A change of material happens because the predominant voxel layer changes too. Very often the material boundaries align perfectly with sharp features in the geometry.

This is what you want in some cases. Imagine where the foundation of a building goes under the rock. You don't want the rock and the wall materials to blend, it would look weird. In other cases you do want different materials to blend. For instance where snow ends and bare rock starts. A clean line would not be right.

This behavior had to be controlled by a material setting. The engine then looks at all the triangles contributing to each vertex and compiles a list of materials for the vertex. Material boundaries form based on these blend settings.

At some point I was alpha-blending materials at the boundaries and baking the resulting image into a texture. I would later use this texture for rendering. This alpha-blending turned to be a problem when I moved all material rendering to realtime shaders. As you will see next, each material is a also collection of layers. Rendering a single material means all these layers must be evaluated and blended together. Now, imagine a point where three different materials overlap: I would need to evaluate all the layers for all materials there. It was often worse than that, in some spots I could find up to seven or eight different materials.

I knew rendering a single set of layers was fast enough, so what I did was pick one of the materials and render just that one. Materials already have an alpha value. Picking the one with the highest alpha does the trick. This still creates sharp transition lines, but they can be fixed by offsetting the alpha by a noise function. The transitions become more natural that way.

The following screenshot shows several transition areas as produced by the shader:



Then there is the other half of the material system: how each material is defined. As I mentioned before, it is just a set of layers. Each layer has defines several properties that control how it looks and how and where it is applied. Here are some of them:
  • Diffuse map: A texture with the color information for the layer
  • Normal map: A texture that describes additional orientation changes in the surface of the layer
  • Start and Bottom angles: These angles determine where the texture appears based on the orientation of the geometry. They are based on the world's up vector. This is what you would use to put moss on the top of rocks for instance
  • Mask noise: A noise definition that determines the intensity of the layer at any point in world space.
I have some other properties, but the ones listed above do most of the work.

I leave you with a screenshot of Buddha, where you can see the angle properties used to place some grass in the horizontal areas. It does not make sense in this case, this is just so you can see it in action:





5 comments:

  1. hi there! i have been reading your posts for a while now, and the whole proceedural generation thing is super interesting! seeing the construction of said mechanics is great to follow! i have a question though, and as far as i can tell you haven't written about it (?) - what kind of game are you thinking to implement with all this tech? what role will the player have in this world? and with the systems you are building, are players able to interact with the environment? (i am thinking like minecraft, where you could dig away an entire mountain if you were so inclined) anyway, thanks for writing such interesting things - it makes me want to attempt to learn algorithmic things!

    ReplyDelete
  2. @mr trout: I'm considering some game ideas at this point. I will wait a bit more to see if the technology itself can suggest the best game, also to be sure of what will be the hardware and network requirements. I may start with something simple, I don't want to wait for too long. Many have asked about a Minecraft type of game before. Please make sure you vote on the poll at the top. Thanks!

    ReplyDelete
  3. I am finding your work truly inspirational!

    About the texturing. Are you using some kind of tri-planar projection or do you get UV coordinates earlier in the process?
    Based on the fact that you are using various maps, I take it you are not using procedural texture shaders?

    ReplyDelete
  4. Thank you for your blog. I'm am working on using dual contouring for my next game and I found your site while doing research. It is so nice to read ahead about pitfalls and have somewhere to look when I run into issues. I did have one question on the materials an I appogize if this is explained somewhere else on your blog. How do you calculate the uvs for the terrain. Are the materials cubic or are doing some kind of projection? I know for terrain I have ended up with stretching in the pas which I am hoping to avoid. Did you find anyway to solve this. Thanks so much for your time I really enjoy and appreciate your blogs.

    ReplyDelete