Game Development Community

Flat Shading Terrain

by Chris Haigler · in Torque 3D Professional · 05/31/2011 (9:17 pm) · 2 replies

For my project I'm looking to change the way T3D renders terrain. I want the terrain to have a very faceted, flat-shaded look, similar to what you might find in a game like Darwinia. What would be the best way to go about this?

I see in terrCell.cpp each terrain 'cell' calls TerrainBlock::getSmoothNormal() which appears to set each vertex normal based on a sampling of heights around that point. This seemed like a good starting point but in my case each vertex in a triangle needs to have the same normal (the face or surface normal, specifically). Calculating the surface normal isn't difficult but actually getting at the necessary data (two edges of each triangle) is where I'm stuck.

I'm also not sure how (if?) all of the shader voodoo fits into this. Perhaps it'd be possible (or even preferable?) to do something like this via a vertex or pixel shader?

#1
06/04/2011 (11:03 am)
Bit of an update on this.

I spent a couple of days tinkering with getSmoothNormal() but couldn't get the results I wanted so I decided to take a different approach. I created a test 'terrain' model in Blender (complete with the necessary smoothing group info needed for that faceted, flat-shaded look I'm after) and wrote a custom class that's responsible for loading and rendering the mesh (along with some other, game-specific things).

The end result is I have a 'terrain' rendering in the style I want. This route also has some interesting advantages:
* it makes use of the built-in material system so the 'terrain' can have all of the graphical spiffiness of regular meshes
* the new 'terrain' is (in some cases significantly) lower poly than the default terrain
* things like overhangs, tunnels, etc. are possible without the extra effort normally required

There are some disadvantages, however. For one, the workflow is a little more complicated. Adjustments to the 'terrain' have to happen in the modeler rather than in the editor. T3D's automatic asset updater is very handy in this case. There's also the issue of collision. Generating collision meshes for the terrain is difficult and the number of polys in the mesh might stress the polysoup system. Luckily my game doesn't require proper collision so this isn't a concern for me.

Switched into full-on blog mode, it seems. :]
#2
06/06/2011 (6:36 am)
You can export opcode terrains directly, using an appropriate smoothing groups.This will produce flat shading.