Skip to content

OpenGL GPU accelerated marching cubes terrain generation with boids using compute shaders.

License

Notifications You must be signed in to change notification settings

Krafpy/Boids-and-Marching-Cubes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boids-and-Marching-Cubes

Boids simulation inside a procedural terrain generated with marching cubes algorithm. The terrain generation and boids are run on the GPU with compute shaders. It's an improved remake of my previous marching cubes attempt that run on CPU.

Screenshot

This project is inspired from Sebastian Lague's videos on marching cubes and boids.

Dependencies

This program uses GLFW3 and GLEW libraries, and runs on OpengGL 4.6, though it only requires OpenGL 4.3 (don't forget to change the #version in shader sources if needed). This project was developed on the CodeBlocks IDE using the 32bit GNU GCC compiler. It should work successfully using a 64bit compiler with the right libraries/DLLs versions, but no garantee. Once compiled, the compute shaders source files and the config.txt file must be in the same location as the executable.

Features

Configuration

The configuration file config.txt is written in a simple custom markup format. It allows to customize various settings used by the program, even at runtime :

  • Terrain noise field generation settings: seed, octaves, lacunarity etc, and more precise features for hard floor and terracing;
  • Marching cubes specific settings: grid dimensions, cube size;
  • Boids settings: number of boids, view settings, forces coefficients, etc;
  • Basic program options;
  • Camera settings.

Controls

  • Drag the mouse with left button pressed to rotate around the center;
  • Drag with scroll pressed to translate;
  • Scroll to zoom in/out;
  • A: toggle axes display (x in red, y in green, z in blue);
  • B: toggle bounding box display;
  • C: reset camera's center of view;
  • R: reload configuration settings from the configuration file and apply the changes;
  • D: toggle mesh display and collision detection with it;
  • P: pause (boids);
  • space: generate a new terrain and new boids.

Terrain

The marching cubes algorithm is implemented with the ability to share vertices between triangles to reduce the memory cost. A smooth rendering is added by calculating interpolated normals for each vertices, used then for the default Gouraud shading performed by the GPU. A CPU floodfill is also performed on the density field to remove regions with a number of points less than minRegionSize. This avoids generating random small floating shapes.

Boids

The boids follow the rules described by Craig Reynolds in his original paper : cohesion, alignment and separation, as well as obstacle avoidance by steer to avoid method. The terrain detection is done by checking for a cube that intersects the surface (configuration different from 0) along a ray, in a distance range of predictionLength. No triangle intersection is performed. The bounding box is also interpreted as an obstacle. Boids colors are simply a mix of the main boidColor defined in the configuration, and some random offset scaled by boidColorDeviation for each boid.

Screenshot

About

OpenGL GPU accelerated marching cubes terrain generation with boids using compute shaders.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published