Spherical Harmonics is a method for efficiently representing values that vary based on angle – often, lighting. It’s been in use for a long time in computer graphics, and with a google search you can find plenty of interesting information explaining the subject, in particular this (now a bit old) paper by Robin Green of SCEA – Spherical Harmonic Lighting: The Gritty Details. The common use case for spherical harmonics is caching a slow-to-calculate value that varies by angle, storing it as SH coefficient data, then reproducing an approximated version of that original value later on. What makes spherical harmonics useful is that for certain types of things (like diffuse lighting) the amount of data you have to store is quite small, and the value can be reproduced later quite quickly.

I’d previously tinkered with SH a bit in blender, but this time decided to port the code in the above paper to VEX in Houdini, implemented as a couple of VOPs, used to generate and evaluate spherical harmonics as part of a VOP network. I started playing with this idea last year at Dr. D, and still haven’t implemented my original ideas yet after getting sidetracked with these fun examples of things you can do with SH. Maybe soon.

You can download this example file, and the OTL here: houdini_sh_otl_hipnc.v001.zip.

The OTL includes three VOPs:

*SH Generate*Stores a single float sample along with its corresponding angle in a set of spherical harmonics coefficients. It’s currently using a 4×4 Matrix type as storage for this because it’s convenient to work with in VOPs/attributes, and because 16 floats will allow you to store up to 4 bands of spherical harmonics, which is enough for many situations involving smooth/diffuse values.

*SH Evaluate*Evaluates the value of the input spherical harmonics coefficients at a given lookup angle, as a single float.

*Cartesian to Spherical*The

*SH Generate*/*SH Evaluate*VOPs take input angles in spherical coordinates (Phi/Theta),. This VOP can be used to convert a cartesian vector direction, to spherical coordinates.

The OTL was made in Houdini Apprentice, but probably isn’t difficult to convert to a commercial version. If you find any use for this, or any mistakes, please let me know!

Hey Matt,

very cool & informative example. Shows the infinite power of Houdini.

Paolo

cheers, paolo!

Very interesting, thanks for sharing Matt.