PDA

View Full Version : Specular lighting with Lightmaps


starstutter
02-06-2008, 08:09 AM
Obviously, lightmaps are great way to get static, complex, highquality lighting. Of course, static also indicates that it can't move, meaning no specular.

This greatly reduces realism at times.

Is there some sort of cheap method where I can apply specular lighting (with no need for diffuse) with mutiple sources without dragging my framerates down? I know about gloss / environment maps, but I really don't think they look very good.

roel
02-06-2008, 08:52 AM
Of course, static also indicates that it can't move, meaning no specular.
Wrong, or I misunderstand you.

Reedbeta
02-06-2008, 11:27 AM
To do specular, you need the lightmap to store not just the color and brightness of the incoming light, but also the direction, so that the half-angle vector can be calculated at runtime. The trouble is, light often comes from many different directions, and has a different color from each direction.

A simple way to approximate it is to average the incoming light at each lightmap texel (or maybe just each vertex) to give both an average direction and an average color, then use that to compute the specular. Another way is to take environment maps at various locations, blur them and for each specular object, use the nearest environment map. I belive both of these methods are used by the Source engine, for one.

You might want to investigate spherical harmonic based lighting. Spherical harmonics are a way of representing the incoming light distribution that gives you more information than just the average direction and color. I've mostly seen these used to do diffuse lighting with soft shadows and indirect illumination, but if you use enough harmonics you could conceivably get some good specular out of it.

starstutter
02-06-2008, 03:02 PM
Wrong, or I misunderstand you.
umm, care to expand?


So Reed, the first method you described sounds a lot like just doing specular-only dynamic lights, except maybe the normals aren't calculated at run-time, which I guess would be nice... but is it worth all the extra memory to skip that one rather small step?

As for what the source engine uses, it is efficient, but I've never liked specular lighting in all the valve games. It looks good in team fortress, but I think that's just because of the stylized graphics. I think source does have some incredible capabilities, but everything that comes out of it looks flat for some reason, unlike Unreal which has a great specular system giving a lot of depth (I honestly don't know exactly what they use though).

Reedbeta
02-06-2008, 09:57 PM
So Reed, the first method you described sounds a lot like just doing specular-only dynamic lights, except maybe the normals aren't calculated at run-time

No, the idea is that you might have many different light sources, but at each surface point (vertex, texel, whatever) you calculate an average light direction and color. During rendering you treat that average version like it's the only light source. So where you had many lights before you now only have one. And during your precalculation you can even use radiosity to get some indirect illumination, so it's not even necessarily limited to the actual light sources.

But, of course the problem is that when you average all these things together you lose a lot of information, so it may not look that great. It's cheap though in scenes where you have a lot of static light sources.

starstutter
02-06-2008, 10:42 PM
OH OH... ok I see

that's a bit similar to what I'm doing right now. I was actually just playing TF and I noticed that the objects always seem to fade out their specular highlights before moving onto the next light source, so I guess it probably is something similar to that.

I was also thinking about the "local" specular reflections. As in, they are reflections close to a surface and don't have to effect much beyond that. For that I was also planning to use that sharp attenuation formula you gave me. It seems to work smoothly for things like that so I don't see why it wouldn't work for something like this.

Thanks again.

CheshireCat
02-07-2008, 09:34 PM
Source engine and UE3 use orthonormal basis to store incident light to lightmaps so you can use it for normalmapping and diffuse & specular lighting. This is pretty low-frequency incident lighting information though, which is ok for diffuse, but a bit too low-frequency for decent specular.

roel
02-08-2008, 02:52 AM
umm, care to expand?

Sure, my reply should have been less brief :) I meant that you only need to store a light direction for lightmapped speculars. Or say 4 references to actual (static) lights, like "this lightmaptexel is able to see light n", maybe even together with an rgb weight factor if you compute indirect lighting (but you can't use the indirect component for speculars). I never did it actually, and I don't know if anyone else did it. Maybe I forgot something and is it actually a bad idea...