generate-spherical-harmonicsdeprecated

Generate spherical harmonics and octahedral environment maps for HDR image based lighting.

Usage no npm install needed!

<script type="module">
  import generateSphericalHarmonics from 'https://cdn.skypack.dev/generate-spherical-harmonics';
</script>

README

generate-spherical-harmonics

npm version dependencies devDependencies

Generate spherical harmonics and octahedral environment maps for HDR image based lighting.

Russel 16 | Jeff Russel: HDR Image-Based Lighting on the Web. WebGL Insights Chapter 16, https://webglinsights.github.io/downloads/WebGL-Insights-Chapter-16.pdf

The library ships two binaries: cmft by Dario Manesku (a CLI cubemap filtering tool) and hdr2png by Pierre Lepers (conversion tool for radiance .hdr to png). It requires montage (toolkit for assembling images into custom mosaics) to be installed. generate-spherical-harmonics is almost a direct copy of the bash script shipped along nanogl-pbr/bin/nanoglibl by Pierre Lepers but implemented in Node.js.

The tool outputs multiple files though only 3 files are relevant for the end user: env_hi.png, env.png and sh.bin. env_hi.png is a high quality octant texture that serves as the main octahedral environment map. The tool generates several versions of octant textures (level0.hdr to level7.hdr) with different gloss intensity and assembles them in one single strip texture env.png using montage. sh.bin is constructed from the outputted spherical harmonics coefficients in sh.c and exports as a UInt8Array in order to be quickly decoded in the browser.

For details regarding the implementation of spherical harmonics for ambient lighting and interpreting the octant textures in env.png as a cubemap please refer to the shaders in nanogl-pbr/glsl/includes, octahedral.shader and pex-gl/pex-renderer.

Demo

Decoding sh.bin

In the docs folder one can find an implementation of a parser for sh.bin that is constructed from the IBL.convert implementation in ibl.js of nanogl-pbr.

Spherical harmonics visualized

Visualizing spherical harmonics

Support

Currently the tool only works out-of-the-box on MacOS but there is no reason why it wouldn't be able to be extended to work on Linux and Windows.

Installation

Make sure you have Node.js installed.

  npm install
  node ./bin/generate-spherical-harmonics.js -i ./input/studio022-1024x512.hdr -o ./output

Development

  npm start

  npm run lint

  npm run deploy

Flags

Required

-i, --input [example: ./input/studio022-1024x512.hdr] [required]
-o, --output [example: ./output] [required]

Resources

A very good resource to find free HDRI's is https://hdrihaven.com/.

Licence

My work is released under the GPL-2.0 licence in order to be in line with the licence agreement of nanogl-pbr.

This repository distributes multiple binary tools for Mac.