Lighting and AO¶
All functions with the
heman_lighting_ prefix are meant for doing things that are useful for lighting, like generating normals or ambient occlusion.
Normal maps are generated using a simple forward differencing algorithm.
Ambient occlusion is computed by doing 16 sweeps across the height map to find horizon points, as described by Sean Barrett here.
heman_lighting_apply(heman_image* heightmap, heman_image* colorbuffer, float occlusion, float diffuse, float diffuse_softening, float* light_position)¶
High-level utility that generates normals and occlusion behind the scenes, then applies simple diffuse lighting.
- heightmap (heman_image*) – The source height map, must have exactly one band.
- colorbuffer (heman_image*) – RGB values used for albedo; must have 3 bands, and the same dimensions as heightmap.
- occlusion (float) – Desired strength of ambient occlusion in [0, 1].
- diffuse (float) – Desired strength of diffuse lighting in [0, 1].
- diffuse_softening (float) – Used to flatten the normals by lerping them with +Z. Set to 0 to use unaltered normal vectors.
- light_position (float*) – Pointer to three floats representing the light direction.
Heman automatically un-applies gamma to the albedo, then re-applies gamma after lighting. This behavior can be configured using