Jump to content
  • Advertisement
Sign in to follow this  
trs79

DirectX SDK PRT tools, light probes

This topic is 1898 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all,

I'm trying to see if it's possible to use the PRT DirectX tools to setup light probes similar to this from Unity:

http://blogs.unity3d.com/2011/03/09/light-probes/

I notice there is a spherical light, as well as functionality to convert cubemaps to spherical harmonics coefficients. Any tips on how to be able to place light probes and create spherical harmonics coefficients from them? Thanks

Share this post


Link to post
Share on other sites
Advertisement
They're not using PRT in Unity, nor is PRT particularly popular for light probes in general.

If you're just starting out with light probes, then you can implement them like this:

1. Pick your probe locations throughout the scene. Easiest way is a 3D grid.
2. For each probe location render an cubemap by rendering in all 6 directions
3. Convert the cubemap to SH (you can use the D3DX utility functions for this if you'd like, but it's not too hard to do on your own)

Then at runtime you just lookup and interpolate the probes, and look up the irradiance in the direction of the normal by performing an SH dot product (just make sure that you include the cosine kernel). This will give you indirect lighting, and you can add in direct lighting on top of this.

Share this post


Link to post
Share on other sites

They're not using PRT in Unity, nor is PRT particularly popular for light probes in general.

If you're just starting out with light probes, then you can implement them like this:

1. Pick your probe locations throughout the scene. Easiest way is a 3D grid.
2. For each probe location render an cubemap by rendering in all 6 directions
3. Convert the cubemap to SH (you can use the D3DX utility functions for this if you'd like, but it's not too hard to do on your own)

Then at runtime you just lookup and interpolate the probes, and look up the irradiance in the direction of the normal by performing an SH dot product (just make sure that you include the cosine kernel). This will give you indirect lighting, and you can add in direct lighting on top of this.


Thanks so much for the reply. As I suspected, I must be confusing PRT with SH in general. So are light probes with SH like in Unity known as an "irradiance map"? (sorry I'm trying to wrap my head around the terminology). If this is the case, then as far as I can tell the main difference between PRT and an irrandiance map is PRT computes self shadowing whereas an irradiance map does not? Thanks for any clarifications.

Basically, I'm just try to set my game up such that I can have nice indirect lighting mixed with lightmaps and direct lighting. It seems like light probes are how the commercial engines do it (UDK, Source, Unity, etc.)

Share this post


Link to post
Share on other sites
SH = (roughly/sometimes) Light probes = environment maps = cube maps
- Storage
- Maps a direction to a color (or any value)
- Light probes can mean SH, which is an approximation and can store blurry stuff. It cannot store sharp (high frequency) details.
- Light probes can also mean environment maps / cube maps. They can handle sharp details.

PRT = Precomputed Global Illumination
- Method
- Need to read paper...
- Can store its results in some format... (paper mentions SH)

Irradiance map = filtered map of incoming radiance.
- http://codeflow.org/...map/#irradiance
- Time saver.
- For diffuse stuff in image based lighting, you usually sum incoming light for a given direction, with each light 'beam' weighted by its angle. That's your irradiance.
- The summation is expensive, so we precompute a direction -> irradiance map.
- Usually looks like a blurred light probe.
- Stored in environment map, SH, etc...

Also I feel like that unless you're reading a paper, the terms 'SH', 'light probe', 'environment map', 'irradiance map' usually are used interchangeably.

Share this post


Link to post
Share on other sites
Spherical harmonics refers solely to the math/concepts behind storage, PRT is just the idea of calculating how light bounces around ahead of time. Technically speaking, boring old Quake 2 lightmaps are just as much PRT as are the fancypants spherical harmonics stuff that's in vogue today.


tl;dr you can have spherical harmonics without PRT, and have PRT without spherical harmonics. SH just happens to work really, really well for PRT.




Also I feel like that unless you're reading a paper, the terms 'SH', 'light probe', 'environment map', 'irradiance map' usually are used interchangeably.

While I hate to come off like a smug tool, I don't think any of those are really 'interchangeable' even outside of academic fantasyland. If you're just starting out I can understand the confusion, but if they're all one big haze then it sounds like your initial source(s) need some work. Reading the last few pages of the seminal paper on SH for environment capture was an epiphany for me-- I was making most of this out to be vastly more complex than it really was on account of technique explanations written by seasoned mathematicians for seasoned mathematicians.

There are a few other annoyances I have, like how irradiance convolutions are described as 'not a blur' though it mechanically works out to the same thing, though the underlying reasoning made more sense once you become familiar with all the terms slung about. There is a consistent internal scheme to it all, though, I promise :)

Share this post


Link to post
Share on other sites

SH = (roughly/sometimes) Light probes = environment maps = cube maps
- Storage
- Maps a direction to a color (or any value)
- Light probes can mean SH, which is an approximation and can store blurry stuff. It cannot store sharp (high frequency) details.
- Light probes can also mean environment maps / cube maps. They can handle sharp details.

PRT = Precomputed Global Illumination
- Method
- Need to read paper...
- Can store its results in some format... (paper mentions SH)

Irradiance map = filtered map of incoming radiance.
- http://codeflow.org/...map/#irradiance
- Time saver.
- For diffuse stuff in image based lighting, you usually sum incoming light for a given direction, with each light 'beam' weighted by its angle. That's your irradiance.
- The summation is expensive, so we precompute a direction -> irradiance map.
- Usually looks like a blurred light probe.
- Stored in environment map, SH, etc...

Also I feel like that unless you're reading a paper, the terms 'SH', 'light probe', 'environment map', 'irradiance map' usually are used interchangeably.


Thanks for the information, I'm beginning to get a better grasp of the terminology. It sounds like I probably just need SH for now, and I'll use standard shadow mapping for my characters on top of that.


Spherical harmonics refers solely to the math/concepts behind storage, PRT is just the idea of calculating how light bounces around ahead of time. Technically speaking, boring old Quake 2 lightmaps are just as much PRT as are the fancypants spherical harmonics stuff that's in vogue today.


Thank you, that clears up a lot for me. So, to summarize, it sounds like to get the basic ambient indirect lighting I just need to do the steps by MJP. Just to make sure I'm understanding things now, it seems like both Unity and UDK are doing this, i.e. see this link http://udn.epicgames....html#Character lighting

there it looks like they are just doing an irradiance map as well? The DirectX SDK has an Irradiance volume sample from ATI that looks similar.

Share this post


Link to post
Share on other sites
From the UDK wiki it sounds like they're storing SH irradiance maps (containing indirectly lighting only) at probe locations in a 3D grid, which is conceptually pretty similar to the process that I outlined earlier.

Share this post


Link to post
Share on other sites
Unreal may not be the best example for a newcomer as there's a *lot* of cheating/cleverness going on. Based on my understanding, things work like so:

Static lighting for static objects, both direct and indirect, is all baked into an SH lightmap. I think older versions of the engine actually use the HL2 basis and didn't capture specular, though with Lightmass that's obsolete.

Static object shadows from static light sources on dynamic objects are handled using their proprietary distance field shadows technique. I *think* this involves a sort of 'shadow edge detect' filter and then using some blending to create nice smooth shadows, but I don't know how it works for certain. Sorry! :(

Static lighting for dynamic objects is done mostly through LightEnvironments, which in non-Tim Sweeney-speak translates out to diffuse environment probes. Lightmass will generate these and the actual runtime will probably look very much like the IrradianceVolumes sample in the DXSDK. There's some interesting cleverness here with the modulated shadow system-- the game engine will extract the dominant light from the interpolated SH coefficients and then use this as a modulative shadow projection direction. While not perfect, this is actually a really clever way to handle that problem.

Dynamic lighting on static objects and dynamic lighting on dynamic objects is just your average forward renderer, though I believe that LightEnvironments will futz around with the contributions from unshadowed lights and try to bake them into the SH coefficients for shading.

Share this post


Link to post
Share on other sites

If you're just starting out with light probes, then you can implement them like this:

1. Pick your probe locations throughout the scene. Easiest way is a 3D grid.
2. For each probe location render an cubemap by rendering in all 6 directions
3. Convert the cubemap to SH (you can use the D3DX utility functions for this if you'd like, but it's not too hard to do on your own)

Then at runtime you just lookup and interpolate the probes, and look up the irradiance in the direction of the normal by performing an SH dot product (just make sure that you include the cosine kernel). This will give you indirect lighting, and you can add in direct lighting on top of this.
[/quote]

This idea sounds interesting to me. Is there a good paper/tutorial on this idea?

What world space resolution would the light probe grid be? Every meter, every 10 meters? What resolution cube maps?

Do you pass your grid of SH to your pixel shaders for adding the indirect lighting?

Share this post


Link to post
Share on other sites

This idea sounds interesting to me. Is there a good paper/tutorial on this idea?


If you search for "irradiance volumes" you should be able to find some papers. This presentation gives a pretty good overview. As for converting to SH, the paper that InvalidPointer linked to has all of the details.


What world space resolution would the light probe grid be? Every meter, every 10 meters? What resolution cube maps?


It depends on how much memory you have, and how quickly the lighting changes throughout the environment. For slow changes in lighting you really don't too many sample points, but if you want to capture higher-frequency shadowing then you need a more dense grid. If you're only storing indirect lighting then you probably won't your grid to be very dense, since it tends to be low-frequency

You can get a way with a fairly low-res cubemap for irradiance, since it's so low-frequency. 32x32 or 64x64 should be plenty.


Do you pass your grid of SH to your pixel shaders for adding the indirect lighting?


You can do that if you want, in fact you can even use a volume texture so that the GPU will do the interpolation for you. Or you can do the interpolation on the CPU once per dynamic object, and just pass that result to the pixel shader.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!