- RIT Grad Project, Spring 2012
- Source: TerrainGen
- This program was written in C++ with OpenGL 3.3+.
- The generation uses a Diamond-Square algorithm borrowed from another student
- The algorithm generates a low-res height map and this program renders it in voxels.
This program was inspired by Minecraft and exploring the idea of a possible rendering optimization using voxel terrain generation, as opposed to filling the vertex buffer with each cube’s mesh information (assuming the code at didn’t batch render). The idea at the time was to take the position information supplied by a generic terrain generation algorithm and expand those points into cubes through a pass in the geometry shader, generating the necessary vertices for each cube on the hardware. The program was able to smoothly on upwards of 4500 cubes / 54000 triangles using a naive viewport implementation that doesn’t cull objects or take into account occlusion. In the end it didn’t really seem like much of an optimization, but it was a fun experiment in utilizing 3D programming techniques I had recently learned, as well as exploring the use of a geometry shader.
layout(points) in; layout(triangle_strip, max_vertices = 36) out; float hsize = size / 2.0; vec4 vert = gl_in.gl_Position; //Front vec4 a = ... //( +, +, + );vec4 b = ... //( -, +, + ); vec4 c = ... //( +, -, + ); vec4 d = ... //( -, -, + ); //Back vec4 w =... //( -, +, - ); vec4 x = ... //( +, +, - ); vec4 y = ...//( -, -, - ); vec4 z ... //( +, -, - );
vec3 pos = (model * a).xyz; gl_Position = persp * view * model * a; EmitVertex(); pos = (model * b).xyz; gl_Position = persp * view * model * b; EmitVertex(); pos = (model * c).xyz; gl_Position = persp * view * model * c; EmitVertex(); EndPrimitive();