PDA

View Full Version : OT: Spherical Harmonics Coefficients from light-probe HDR file

flamz
08-30-2007, 09:49 AM
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?

ZbuffeR
08-30-2007, 12:07 PM
this paper looks promising :
http://qhxb.lib.tsinghua.edu.cn/myweb/english/2007/2007e1/44-50.pdf

lodder
08-31-2007, 01:59 AM
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 &amp;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 :)

ZbuffeR
08-31-2007, 07:35 AM
lodder, what PRT stands for ? How is it related to Spherical Harmonics ?

Lord crc
08-31-2007, 01:08 PM