View Full Version : OpenGL- Shadow Mapping
12-13-2011, 09:19 PM
Hi guys, it's my first post here . I've try to implement shadow mapping in my game engine and i have some issue.
I really need someone to help me figure 2 or 3 thing. You can see a big part of my source code here: http://pastebin.com/sXTr2ets. (http://pastebin.com/sXTr2ets)
I have post on Gamedev too so if you want to see a screenshot that show where my work is going, click:
okay what i need help with is:
1- find a place and a way to squeeze my texture back in the code.
2- find a way to use multiple light (should i use 1 shadowMap for every light or 1 per light)
12-14-2011, 05:19 AM
I haven't read your code but what I can say from your questions is that you should use a shadow map for each light. Shadow maps are rendered in the light view space.
12-14-2011, 08:31 AM
Is it very bad to have many lights? Because i'm planning to use maybe 10-12 lights in my map.
And for the multiple shadowmap, do i have to repeat the 3 drawing pass for every light with a different shadow map and lightmatix? that sound excessive...
And i have another question: My shadow map try to apply to the whole map everytime. What i mean by that is: is that when it reach a certain distance from the light, it just stretch the limit to the map border. That create false lit area. Is there a way to shadow everything that go pass the limit of what he can generate?
12-14-2011, 10:10 AM
Generally, you only pick one or two lights for shadow-mapping. This is just for performance reasons. The rest don't cast shadows.
12-14-2011, 10:48 AM
Okay so basically i shadow map the nearest light that the camera can see? Because the way i have drawn the map, i would need a light for every room and outside too. + one on the player if he have a flashlight or whatever.
Is it better to use another technique if i want to cast shadow for that much light?
12-14-2011, 11:11 AM
Use the most influencing lights, ie the sun, the main light of each room and the player's light.
"Render" only the lights that have an influence on the scene. For example the light two rooms far away or far behind and that is hidden by walls does not have to be "rendered". Otherwise, it can have a bad influence on the scene (it can lit parts of the scene that it should not - because of walls).
12-14-2011, 12:23 PM
kk... so for example outside i render the sun light + mine. Inside main room i render the main room light + mine and the same for other room... That sound hard to implement considering the fact that it took me about 1 week to make shadow the way it's looking now :P But yeah i will give it a try.
I had another idea (not sure if that would work)
Say that every room have a light but one that doesn't cast shadow. and imagine the only light that cast shadow, is the player light (so basically, all the map is not in complete dark, the shadow isn't really what not being lit, but what the player don't see). Does that make sense?
12-14-2011, 01:14 PM
Using a simple forward shader you run out of varyings very quickly with multiple lights and shadow maps.
I switched to deferred and can pretty easily accomodate at least 5 or 6 shadow map lights with no problems. The next step is to implement lighting occlusion/level of detail (i.e. switch off the shadow map when far away)...
Oh yeah, another thought: I have shadow maps embedded in my quake levels and I intersect the light cone with the quake visibility clusters, which allows me to only draw a subset of the quake world in the shadow map depth buffer pass (the faces in the active visibility clusters).
Its a rabbit hold for sure, but fun stuff...
deferred plus shadow maps (http://www.youtube.com/watch?v=-k7_mzpVNUk&feature=player_detailpage)
12-14-2011, 01:36 PM
Okay cool thank you, but i don't think i'm ready to handle something as complex as defered... I'm not sure either if my game really need such a technique. The graphic i'm trying to get seem so less complicated than what is hsown in your video. Have you played Subvein? (http://www.youtube.com/watch?v=fwr2CxrbXA8)
That's about the same kind of shadow/graphic i'm trying to implement in my engine.
12-14-2011, 02:46 PM
Cool looking game. Lots of cool particle effects; never quite got that far with things.
A lot of the lights in that game might be precomputed as well (although I guess that doesn't really help with shadows....)
Its those darn dynamic objects that cause all the problems!!!
12-14-2011, 03:00 PM
What do you mean by precompute? because, in my engine, i don't have active object except the player.
Can i cast shadow and light on my map all before the map is launch and only use 1 shadow map for the line of sight of my player in real-time??? (so all the shadow are launch once and the player shadowMap is recalculate every game loop)
If yes, can you point me toward a way to generate shadow for my map in ''non real-time'' (precompute if that mean what i think it does).
EDIT: i have add 2 screenshot showing the entire scene so you guys understand the problem.
http://a1.sphotos.ak.fbcdn.net/hphotos-a...782881235_n.jpg (http://a1.sphotos.ak.fbcdn.net/hphotos-ak-ash4/s720x720/393675_107752096009911_100003253633339_32829_17828 81235_n.jpg)
http://a6.sphotos.ak.fbcdn.net/hphotos-a...283244847_n.jpg (http://a6.sphotos.ak.fbcdn.net/hphotos-ak-ash4/s720x720/381492_107752142676573_100003253633339_32830_12832 44847_n.jpg)
12-16-2011, 08:11 AM
I was just thinking maybe they precompute the lighting using lightmaps. But that wouldn't help with dynamic shadows, which these would conflict with. I have wondered, though, if it might be possible to save a copy of the static objects rendered into each light maps shadow buffer, then render only the dynamic objects into those buffers. I guess you would have to save a copy of the light position depth map as well...
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.