• Stars
    star
    470
  • Rank 93,399 (Top 2 %)
  • Language
    C
  • License
    MIT License
  • Created over 9 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C99 heightmap utilities.

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:

// Generate an island shape using simplex noise and a distance field.
heman_image* elevation = heman_generate_island_heightmap(1024, 1024, rand());

// Compute ambient occlusion from the height map.
heman_image* occ = heman_lighting_compute_occlusion(elevation);

// Visualize the normal vectors.
heman_image* normals = heman_lighting_compute_normals(elevation);

// Apply a color gradient.
heman_image* gradient = heman_color_create_gradient(...);
heman_image* albedo = heman_color_apply_gradient(elevation, -0.5, 0.5, grad);

// Apply diffuse lighting.
heman_image* final = heman_lighting_apply(elevation, albedo, ...);

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

Building OpenMP

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

More Repositories

1

par

single-file C libraries from Philip Allan Rideout
C
861
star
2

snowy

Small Image Library for Python 3
Python
417
star
3

svg3d

generate 3D wireframes as vector art
Python
351
star
4

aobaker

ambient occlusion baking tool
C++
234
star
5

fluidsim

GPU fluid simulation
C
165
star
6

recipes

collection of tiny OpenGL demos
C
63
star
7

parg

tiny C library of various graphics utilities and GL demos
C++
56
star
8

lava

toy C++ Vulkan library
C++
49
star
9

clumpy

create or transform numpy images from the command line
C++
47
star
10

parm

minimal macOS Metal application
Objective-C++
41
star
11

iphone-3d-programming

sample code from my O'Reilly book
C
40
star
12

polygon.js

tessellation of concave polygons with holes in Javascript
JavaScript
39
star
13

distortion

Fisheye Distortion in OpenGL
C
36
star
14

knotgl

Mathematical Knots in WebGL
JavaScript
34
star
15

streamlines_demo

sample app for par_streamlines
C
31
star
16

pez

teeny tiny platform layer for simple OpenGL demos
C
26
star
17

quadmesh

Animated quad meshes and smooth normal computation with Modern OpenGL.
C
22
star
18

opengl-insights

source code for "An Introduction to Tessellation Shaders"
C
22
star
19

hexgl

HexGL clone using Filament and TypeScript
TypeScript
19
star
20

sympy-fun

use SymPy to generate equations for parametric surfaces
C
17
star
21

giza

low-level utility layer for WebGL
JavaScript
16
star
22

nile

fractal terrain generator in Nim
Nim
16
star
23

coregl-python

simple example of using the OpenGL Core Profile with PyQt, numpy, and PyOpenGL
Python
15
star
24

gltumble

spin a 3D object with a bit of inertia
JavaScript
14
star
25

knotess

prime knot tessellation
JavaScript
13
star
26

rwt

Recursive Wang tiles dataset for blue noise
C
13
star
27

euler

scrollytelling and Filament
TypeScript
11
star
28

effects-salad

C++
10
star
29

camera_demo

demo for par_camera_control.h
C
10
star
30

flatbin

Tiny JavaScript utility for parsing simple binary files.
JavaScript
9
star
31

govmath

vector math in go for 3D graphics
Go
9
star
32

reba-island

generate simple island shapes
C++
8
star
33

monarchy

demonstrates high-performance 2D graphics with giza
JavaScript
8
star
34

pageturn

TypeScript
8
star
35

lsystem

lsystem evaluation in C++, Go, and Python
C++
7
star
36

modern-opengl-prezo

HTML Slideshow on Modern OpenGL
C
7
star
37

skia

fork of skia that is CMake-buildable
C++
6
star
38

ribarchive

random renderman stuff
Slash
5
star
39

sfpaths

Download and visualize Strava paths with D3 and Google Maps.
Python
5
star
40

blog-source

my old graphics blog
C
3
star
41

d3cpp

sweep and prune demo
JavaScript
3
star
42

gorman

renderman bindings for the go language
Go
3
star
43

heman-python

work in progress
C
2
star
44

book-webgl

JavaScript
2
star
45

reba

dev machine for building server-side renderers
Shell
1
star
46

filasize

HTML
1
star
47

shaderhud

quick shader editor overlay for debugging
JavaScript
1
star
48

knot-data

Data for Mathematical Knots
CoffeeScript
1
star