OT: Spherical Harmonics Coefficients from light-probe HDR file

Sorry about posting something a little Off-topic.

I am looking for documentation, or code or an example of how to extract spherical harmonics coefficients from a light-probe HDR file.
I currently use a HDR cube-map as a skybox in my game, but would like the SH coefficient to do some relighting.

can anyone help?

this paper looks promising :
http://qhxb.lib.tsinghua.edu.cn/myweb/english/2007/2007e1/44-50.pdf

You treat each pixel in the skybox as a single directional light. For a HDR-cubemap you need an additional scale value.

/// Calculate the sh coefficients for the given HDR image
CoefficientType *ProjectHDRImage(const Sirenia::HDRImage &image, Real HDRFactor)
	{
		Real dWeight = 4.0 * PI;
		Real factor = dWeight / _nSamples;

		CoefficientType *result = new CoefficientType[_nCoefficients];
		memset(result, 0, sizeof(CoefficientType) * _nCoefficients);
		
		for(Uint32 i=0; i < _nSamples; i++)
		{
			Color color = image.GetColor(_Samples[i].vec, HDRFactor);
			for(Uint32 c=0; c < _nCoefficients; c++)
			{
				result[c] += color * _Samples[i].coefficients[c];
			}
		}
		// Scale the PRT coefficients
		for(Uint32 i = 0; i < _nCoefficients; i++)
		{
			result[i] = result[i] * factor;
		}
		return result;
	}

“CoefficientType” is a RGB-tupel. Fetching color values from an HDR-Skybox is done by a routine from Paul Debevec (see his page).

I have a lot more PRT-code if needed :slight_smile:

lodder, what PRT stands for ? How is it related to Spherical Harmonics ?

Precomputed Radiance Transfer, see http://en.wikipedia.org/wiki/Precomputed_Radiance_Transfer

PRT is “Precomputed Radiance Transfer”. It uses Spherical Harmonic Lighting. Do you know the paper from Robin Green?

ZbuffeR:
Spherical harmonics is a way of storing/compressing data/functions that are defined on the surface of a sphere, by storing them as being made up of a sum of spherical harmonic functions. It’s simply a mathematical object and it is not directly related to any kind of lighting.

PRT is the actual à la mode lighting system using SH to store light information in all direction around an object.