• Create Account

# Spherical Harmonics help?

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1gchewood  Members   -  Reputation: 212

Like
0Likes
Like

Posted 04 October 2013 - 10:53 AM

Ok so I've just about got my head around the theory. So can someone correct me if I'm wrong in thinking that Spherical Harmonics are an efficient means for storing the lighting contributions of the nearby environment for any given point in space.

Assuming I'm roughly correct so far, I need a bit of help in understanding how this is/can be applied in real time.

So I get that for a largely static environment, you can pre-compute a set of low resolution cubemaps and then reduce them to sets of spherical harmonic coefficients for the sake of memory efficiency. The questions I have so far are:

1) Where do you set the light probes? At the locations of each individual model? What about larger models that will need to deal with a possibly changing set of light values? Assuming you'd need more than one set, how do you blend between them?

2) How do you handle moving objects (just a few, obviously). Do you have to constantly render an environment map or is there a direct way of getting the right coefficients? I assume if you're going to be constantly rendering it, you'd only take into account objects within a certain distance?

Edited by gchewood, 04 October 2013 - 10:54 AM.

### #2Paradigm Shifter  Crossbones+   -  Reputation: 3995

Like
0Likes
Like

Posted 04 October 2013 - 11:46 AM

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

### #3gchewood  Members   -  Reputation: 212

Like
0Likes
Like

Posted 04 October 2013 - 10:08 PM

Thanks,

But man, was that long! I've looked into a few other approaches and given that my scene is relatively simple, I'm considering just pre-baking

it all in 3ds max and then just using SH for the main character.

### #4MJP  Moderators   -  Reputation: 7521

Like
0Likes
Like

Posted 05 October 2013 - 01:01 AM

Spherical harmonics are generally good for storing any low-frequency function that's located on the surface of a sphere. Diffuse lighting at a single point is a good fit for SH, since you can store the diffuse lighting for any direction from that point and then "look up" the lighting based on the surface normal.

If you have large static models, you'll want to place sample points along the surface of the mesh (not inside the mesh, since there will probably be no lighting in there). An easy way to do is to calculate lighting at vertex positions, or you can use a lightmap and store SH coefficients at each texel. With either vertex or lightmap SH samples you can interpolate between the nearby sample points in the pixel shader, and compute lighting for the normal of that surface.

For dynamic objects, you generally place probes throughout the scene and bake lighting without the dynamic objects. Then when you render the dynamics, you sample nearby probes. This lets the dynamic objects receive lighting, but no lighting will bounce off of the objects. Usually this is a pretty good approximation, since dynamic objects are typically small relative to static meshes. If you do need dynamic objects to reflect lighting, then you would need to generate the probes at runtime. There's a good blog post here that describes a few methods of placing probes for dynamic objects, and interpolating between them.

### #5gchewood  Members   -  Reputation: 212

Like
0Likes
Like

Posted 07 October 2013 - 08:58 AM

Thanks MJP.

I'm a bit overwhelmed by it. I understand the theory, just not the implementation. That link seems to at least suggest the interpolating between probes

is quite easy.

My main issue at the moment is how do you get the coefficients in the first place? The only method I've seen was based on rendering a set of environment maps. But I don't see that being mentioned very often....?

Thanks

### #6TiagoCosta  Crossbones+   -  Reputation: 1527

Like
2Likes
Like

Posted 07 October 2013 - 02:14 PM

My main issue at the moment is how do you get the coefficients in the first place? The only method I've seen was based on rendering a set of environment maps. But I don't see that being mentioned very often....?

The most common methods are probably projecting a cube map into spherical harmonics or evaluating the light direction and scaling, both methods are explained in this paper (starting at page 9) and there are functions to do it in the D3DX Math.

Edited by TiagoCosta, 07 October 2013 - 02:15 PM.

Tiago Costa
Aqua Engine - my DirectX 11 game "engine" - In development

### #7MJP  Moderators   -  Reputation: 7521

Like
0Likes
Like

Posted 07 October 2013 - 02:45 PM

You compute SH coefficients by integrating the function against the SH basis functions. If you have an environment map already rendered, then you can perform a spherical integral using the method that Peter-Pike Sloan suggests. Or you can use monte carlo integration if you'd like, which works well with a ray-tracer. For each sample point you can cast rays and project using the SH basis functions, which allows you to directly integrate without having to render a cubemap first.

### #8gchewood  Members   -  Reputation: 212

Like
0Likes
Like

Posted 07 October 2013 - 11:39 PM

Thanks people. That Stupid SH paper is pretty much what I was looking for!

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS