项目作者: prideout

项目描述 :
C99 heightmap utilities.
高级语言: C
项目地址: git://github.com/prideout/heman.git
创建时间: 2015-08-09T23:12:29Z
项目社区:https://github.com/prideout/heman

开源协议:MIT License

下载


This toy project is a tiny MIT-licensed C library of image utilities for dealing with height
maps, normal maps, distance fields, and the like. It has a very low-level API, where an
“image” is simply a flat array of floats. There are no dependencies and only one header
file
.

Heman can do stuff like this:

  • Create a random height field using simplex noise and FBM.
  • Generate a normal map from a height map.
  • Compute ambient occlusion from a height map.
  • Generate a signed distance field (SDF).
  • Export a 3D mesh in PLY format.
  • Apply a color gradient to a heightmap.
  • Generate a color gradient, given a list of control points.
  • Compute diffuse lighting with an infinite light source.
  • Generate a nicely-distributed list of points according to a density field.

Heman implements some really nice 21st-century algorithms:

  • Ambient occlusion is generated using Sean Barrett’s efficient method that makes 16 sweeps over the
    height field.
  • Distance field computation uses the beautiful algorithm from Distance Transforms of Sampled
    Functions
    (Felzenszwalb and Huttenlocher).
  • Density field samples are generated using Robert Bridson’s Fast Poisson Disk Sampling in
    Arbitrary Dimensions
    .

Example

The images at the top were generated from code that looks like this:

  1. // Generate an island shape using simplex noise and a distance field.
  2. heman_image* elevation = heman_generate_island_heightmap(1024, 1024, rand());
  3. // Compute ambient occlusion from the height map.
  4. heman_image* occ = heman_lighting_compute_occlusion(elevation);
  5. // Visualize the normal vectors.
  6. heman_image* normals = heman_lighting_compute_normals(elevation);
  7. // Apply a color gradient.
  8. heman_image* gradient = heman_color_create_gradient(...);
  9. heman_image* albedo = heman_color_apply_gradient(elevation, -0.5, 0.5, grad);
  10. // Apply diffuse lighting.
  11. heman_image* final = heman_lighting_apply(elevation, albedo, ...);

For the unabridged version, see test_lighting() in
test/test_heman.c.

Building OpenMP

  1. curl -L -O https://github.com/llvm/llvm-project/releases/download/llvmorg-12.0.0/openmp-12.0.0.src.tar.xz
  2. tar -xvf openmp-12.0.0.src.tar.xz ; rm openmp-12.0.0.src.tar.xz
  3. cd openmp-12.0.0.src
  4. cmake . -DLIBOMP_ENABLE_SHARED=OFF -DLIBOMP_INSTALL_ALIASES=OFF -DCMAKE_OSX_ARCHITECTURES=x86_64
  5. sudo make install