|OpenGL 2.0 Shading Language Terrain Texturing Demo.
This demo implements procedural terrain texturing on the GPU using a series of OpenGL Shading Language (GLSL) shader programs. The demo renders a terrain generated from a height map texture. The terrain is lit using a per fragment Lambert shader. The terrain texture is generated in the fragment shader using the terrain height map and 4 tileable terrain textures. The fragment shader mixes and blends these tileable terrain textures together to paint the terrain to give it the appearance of a very high resolution terrain texture map draped over the terrain mesh. The benefit of this approach is that a conventional terrain texture is limited by the maximum texture size supported by OpenGL. This is typically around 4096 x 4096 for most mid to high end video cards. Generating the terrain texture on the GPU overcomes this limit.
The demo allows the player to walk along the terrain using typical first person style controls. The terrain is randomly generated using a diamond square (mid point displacement) fractal algorithm. The terrain texture is created from 4 tileable textures: dirt, grass, rock, and snow.
1. This is an OpenGL 2.0 demo. This demo will not run on OpenGL 1.x hardware.
2. This demo requires the Visual C++ 2010 Library Runtimes. Download instructions can be found here.
Download executable, source, and Visual C++ 2010 solution files.
10 July 2010.
Added missing .vcxproj.filters file to the project.
13 June 2010.
Updated solution to Microsoft Visual Studio 2010.
27 July 2008.
This major update removes the need to sample the height map texture in the fragment shader. The interpolated vertex terrain height is used instead.
terrain.glsl: Updated documentation. Updated shader version to 1.20. Renamed terrainTilingFactor to tilingFactor. Changed 'normal' varying variable in the vertex shader to vec4 type. The 'w' component stores the terrain vertex height. No longer passes on the height map texture coordinate to fragment shader. Renamed TerrainRegion uniform variables to region1, region2, region3, and region4. Renamed sampler2D variables to region1ColorMap, region2ColorMap, region3ColorMap, and region4ColorMap. GenerateTerrainColor() now uses the interpolated vertex terrain height passed on from the vertex shader rather than reading it from the height map texture.
main.cpp: Updated shader uniform variable references to match the new terrain.glsl uniform variable names. The terrain height map texture is no longer generated and bound to the shader. Updated to use CSAA where available.
terrain.h, terrain.cpp: Changed internal height data format in the HeightMap class from byte to float. The HeightMap class no longer creates and stores an OpenGL texture for the height map.
WGL_ARB_multisample.h, WGL_ARB_multisample.cpp: Updated with latest version from the OpenGL Multisample Anti-Aliasing Demo. The latest version supports CSAA.
1 April 2008.
gl_font.cpp: Fixed bug in drawTextEnd() method where the vertex buffer was not being unmapped when there's no text to draw. Thanks goes to Ari Ohvo for spotting this bug.
2 February 2008.
Updated solution to Microsoft Visual Studio 2008.
11 January 2008.
terrain.h: Removed TerrainRegion class.
terrain.cpp: Removed implementation of the TerrainRegion class. In the Terrain::terrainDraw() method removed call to submit the second set of texture coordinates. These are now calculated in the terrain.glsl shader. In the Terrain::generateIndices() method fixed a bug where the triangle strip's winding order was reversed.
terrain.glsl: Updated documentation. In the fragment shader's GenerateTerrainColor() function replaced the existing if test to check for negative regionWeight values with max(0.0, regionWeight). These existing if tests were also preventing the shader from running correctly on AMD ATI cards.
main.cpp: Major rewrite to use the same format and structure as the more recent OpenGL demos. Added text rendering support. Added TerrainRegion structure. Updated with the latest camera logic from the OpenGL Camera Demo - Part 3.
14 April 2007.
Removed the cvs directories that were accidentally included in the contents directory.
11 April 2007.
The vertex shader now calculates the second set of texture coordinates. The terrain vertices submitted by the application now only contains a single set of texture coordinates for the height map texture that is stretched across the terrain mesh.