Skip to main content

What does this do?


With Deferred Shading, you don't need to compute lighting in the terrain material itself, but you need to be compliant with a few important points:

  • The normals must be computed in the eye-space and not in object-space
  • The output COLOR must match what's defined by the GBuffer compositor (oColor0 = diffuse/specular, oColor1 = normal/depth)
  • Which means you must output depth to oColor1 alpha channel


This Terrain Material Generator complies with the above points, while still providing proper texture blending to the diffuse and normal RGB channels. As a result, the terrain rendering is much faster and supports a virtually unlimited number of lights affecting it, plus real-time shadowing and self-shadowing.

Are there any flaws?


There is one flaw: When shadowing is enabled , you can see visible seams caused by shadow texture resolution at the sub-pages edges, as well as visible seams at peaks with low LOD. There should be a way to enhance this, but I'm not experienced enough with shaders and with the Terrain system to do it. If you do however, please notice me ๐Ÿ˜Š

I didn't extensively test composite map, so it might look bad, and LightMap isn't supported.

How does it look ?


Like this:

Preview
Preview


IMPORTANT NOTE

In this material, you can see that there is oColor0, oColor1, and oColor2 in the Fragment Program. This is due to the fact I added another texture to my deferred shading shader to support colored specular maps. I don't think it should cause much troubles, but if it does just remove oColor2 declaration and value assignment in
Copy to clipboard
generateFpHeader
function.

Discussion thread

http://ogre3d.org/forums/viewtopic.php?f=11&t=71311

The Code


The generator's class name is TerrainMaterialGeneratorD. To use it, do this:

Copy to clipboard
Ogre::TerrainGlobalOptions::getSingleton().setDefaultMaterialGenerator(Ogre::TerrainMaterialGeneratorPtr(new Ogre::TerrainMaterialGeneratorD));


To enable shadows:

Copy to clipboard
Ogre::TerrainGlobalOptions::getSingleton().setCastsDynamicShadows(true);

[+] TerrainMaterialGeneratorD.h

[+] TerrainMaterialGeneratorD.cpp