Jump to content
  • Advertisement
Sign in to follow this  
mikeman

Lightmaps & Moving Objects

This topic is 4947 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

This is a question I had for a long time, but just yesterday when I was playing the new Halflife, I realized I never really answered it. How exactly do lightmaps affect moving object, in order to implement some kind of (primitive I guess) shadowing? Long story short: Let's say for example that there is a bright light, and a platform below it. Now, the ground just below the platform is shadowed, due to precalculated lightmaps. If I place myself below the platform, my gun is also in shadow, although I'm sure the platform doesn't cast shadows. It's not even a proper shadow, it doesn't have a shape, the gun just seem to get "darker" when I step in a shadowed area. My guess is that the object is being projected into the floor and we get the lightmap value of that point, which we modulate the gun with, or something like that, but I'm not really sure. What exactly happens, how games achieve that effect? Does anyone have any useful links on that?

Share this post


Link to post
Share on other sites
Advertisement
It can be several things.

You could use the OpenGL lights to emulate the nearest lights to you, and enable them only if their position can be raytraced from the center position of the gun model. You could also code light entities, and query the nearest ones of they are visible. You could also play with the lightmaps like you said, but I don't think that would be so practical.

Doom 3 simply does dynamic lighting for every polygon, including the gun, using pixel shaders. Thats the way future games (should) do it.

Share this post


Link to post
Share on other sites
it's not exactly what you want, but i think it's quite a clever way
http://www.gamasutra.com/features/20030813/hargreaves_01.shtml

basically you have a lookup texture of the world. you sample this lookup texture and decide the light color in that point.

as you can see in the pics, the bike seems in shadows when it passes under the bridge. it can be not so simple if you have a world with many levels

hth



Share this post


Link to post
Share on other sites
Here's what I'm doing. Now, I have relatively small characters, so I can get away with it.

I do 9 CPU raycasts from each character's head to each of the nearby lights, and count how many raycasts hit the light and how many did not. This gives me a brightness value to scale each light color by.

Now, for larger objects, like boulders, this breaks down. One trick is to sample the lightmap itself, but this is wrong for tall objects.

Another approach I may do is do 4 raycasts to each light from 4 places on the character's bounding sphere, in a tetrahedral or pyramidal shape. Then in the vertex shader, each vertex figures out how close it is to each of the 4 lighting spots, picks the 3 closest, and then does a barycentric interpolation between the 3 brightness-adjusted colors.

Share this post


Link to post
Share on other sites
Thanks for the suggestion guys, I'll look into them.

I've also thought another way, which should be pretty fast, but I haven't implement it yet, so I don't know. Since each light has a finite range, I can assign a 3D grid of sample points to each light, say 16x16x16, and determine offline whether a sample point is in shadow or not. Then, for any object that is inside the light range, pick the closest point, and if it's flagged "shadowed", then make the object shadowed too for that light. Maybe I could even do an interpolation between the closest points. The good thing about this is I don't have to do any raytracing in realtime, but I don't know how much memory it will need, although I really need just 1 bit for each sample point. At this point, I don't really care for realistic static shadows, I just don't want a character to look weird when it's inside a shadowed area and it looks bright.

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
Thanks for the suggestion guys, I'll look into them.

I've also thought another way, which should be pretty fast, but I haven't implement it yet, so I don't know. Since each light has a finite range, I can assign a 3D grid of sample points to each light, say 16x16x16, and determine offline whether a sample point is in shadow or not. Then, for any object that is inside the light range, pick the closest point, and if it's flagged "shadowed", then make the object shadowed too for that light. Maybe I could even do an interpolation between the closest points. The good thing about this is I don't have to do any raytracing in realtime, but I don't know how much memory it will need, although I really need just 1 bit for each sample point. At this point, I don't really care for realistic static shadows, I just don't want a character to look weird when it's inside a shadowed area and it looks bright.



Hmmm, what you said sounds like 3D lightmapping, you can find it on Humus website IIRC, while the lightmap he used is a lot more dense, and he used the actual lighting value ratherthan un/shadowed.

Share this post


Link to post
Share on other sites
this sounds like the Q3 lightgrid, where the whole level is included in a 3D voxel field (128*64*128, something more or less like it, it's fixed..), each cell containing the ambient light, and a directional light (color + 2bytes for theta/phi light orientation), and this is all precomputed during the radiosity pass during level compile. (actually, there is a lightgrid pass, then the lightmap pass).
all you have to do later on is to find what are the 8 nearest voxels (very fast, as the lightgrid has a fixed size), and trilerp their ambient and directional lights.
of course this isn't dynamic for moving lights/world geometry, but it gives a nice radiosity lighting to dynamic objects (although it's very low frequency lighting only, you won't get sharp shadows, unless your level is very very small, or unless you have a high number of voxels, and the fixed grid size breaks down for larger levels, where light "leaks" through walls (it doesn't leak all the way, but if you've got a bright red light behind a wall in a large level, and if the wall is thinner than a voxel, when you go close to the wall, you'll receive bright red light, as the voxels behind the wall and lit by the red light are taken into account in the trilerp))

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You might want to check out :-

http://www2.ati.com/developer/gdc/D3DTutorial10_Half-Life2_Shading.pdf

As people have said basically it's a sampling of lighting at various 3d points, of course this is fairly rough and wouldn't pick up on thin shadows unless sampling points were placed to catch them. I believe in Halflife 2 artists placed the sampling points, an alternative would be to kind of do discontinuity placement of the sampling points (similar to Discontinuity Meshing in a way) so in areas of large differences in light / shadow more sampling points were used.

Share this post


Link to post
Share on other sites
I'm going to do a modified light grid approach next. The problem with my current approach is that it's not super cheap cpu wise, and things like blended smoke & fog look to bright when in a dark area, b/c they are not taking shadowing into account.

There may be a fair # of smoke & dust particles, so I need a cheaper approach that makes them darker in shadowed areas.

So, instead of storing just light values at each grid point, I will store an ambient value, as well as occluded light vectors to each light that could hit this point.

For each light, tag each light grid cell with the light #, and a vector towards the light. For each light grid cell in the frustum, or for each light grid touched by a dynamic object this frame, do a raycast towards the light. If it hits the light, add in the light's current color ( allows the light to turn off or change color ), otherwise, set the light color to zero. If you don't care about dynamic objects blocking lights ( and I probably don't ), you can skip the dynamic raycast at runtime, and do it at level lighting time...

Then interpolate the nearest 4 or 8 grid points to blend the occlusion-adjusted colors.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!