Our team is trying to develop a stealth system with the UDK. Part of this will involve lighting.

The idea being that if you're hiding in a dark corner of the room, the armed goons will not start attacking you.

I've been looking for a few hours now. And while I can't say I have no leads it seems that now is a good time to start asking for help.

At the simplest level, I'm looking for a way to determine how brightly lit an actor is (primarily the player right now).

A bit beyond that, what they are wearing might also be a factor. Someone wearing solid dark clothing is going to be harder to spot than someone in a loud Hawaiin t-shirt covered in (given the stealth context probably stolen) diamonds.

The lighting will be dynamic, so the solution needs to be dynamic. As an example, a guard might get rather upset, grab a torch on the wall and throw it in your direction.


I'm not 100% sure if these are possible with the UDK, someone please correct me if they cannot.

Assuming that you're using point light sources you could trace one ray from all light sources to the character's location and see how many, if any, collide.

Then you can elaborate on the basic idea and check collision with multiple parts of the body, like torso+head+feet and decide on how many lights need to be hitting to trigger the reaction.

Or even more complex, using those same body parts first run a collision ray from the NPC's eyes and see what parts he could see if they were lit... and then run light collisions on only those body parts.

Idea number two, which will be more accurate and maybe slower, is to render to a small offscreen buffer the scene from the NPC's eyes location to the character's. Use shaders that make everything black except the character's lighting equations. Average that small buffer to see how much lit character the NPC can see and decide on a value to say that the player is detected.

Without all that, many stealth games use pre-calculated dark areas and only one mobile light source like a guard's flashlight to dodge with just one collision check which may make game and level design easier to tune too.

| improve this answer | |
  • \$\begingroup\$ Thank you for answering, I'll consider this while I'm experimenting. I have since managed to find a bit more detail on the subject. It does appear that our team will have to get creative. I was hoping there would be a simple solution I just wasn't seeing. I do have a few ideas on how to go about this now. I'll probably be able to figure out something. \$\endgroup\$ – xuincherguixe Jul 13 '12 at 5:09
  • 3
    \$\begingroup\$ +1. I think rendering to an offscreen buffer would give the most realistic results. Rendering with low resolution and using histogram based calculations to determine how lit the scenery is should be fast and accurate. If performance becomes an issue, the calculations could even be split over several frames... if there's updated information every 3 or 4 frames, it would still be decent. \$\endgroup\$ – bummzack Jul 13 '12 at 7:15
  • \$\begingroup\$ That sounds like it's pretty reasonable. I'm not sure if we'll be able to use this or not, because there could be a lot of enemies at certain points. But it's not a bad idea. Then again, maybe it's fast enough. We're early in the development process so there's still a lot of things we don't know. \$\endgroup\$ – xuincherguixe Jul 13 '12 at 7:51
  • 2
    \$\begingroup\$ The rendering thing is a technique that used to be used for PVR (potentially visible regions) in engines, each light would render all around itself and each predefined region would render in its own color. The screen would then be parsed to find and store all regions this light touched to use as a runtime optimization. If you make the little offscreen buffer shaders additive then you can render all the enemies using only this one buffer and get a global response to "is the player significantly lit by anyone?" question. \$\endgroup\$ – Patrick Hughes Jul 13 '12 at 20:20
  • \$\begingroup\$ Marking this as an answer as it's been awhile and I don't think anyone else will be adding anything. I've done more research, but I'm still having trouble mostly because of my own lack of experience. \$\endgroup\$ – xuincherguixe Aug 1 '12 at 1:20

For the sake of gameplay itself, it would be valuable to modify how visible the character needs to be in order to be spotted based on the attentiveness of the goons. IF they're distracted, or bored, or working on something else, the character will have to be much more visible than if they're on patrol or even actively looking for him.

| improve this answer | |
  • \$\begingroup\$ Thank you for the suggestion, but we are not currently looking for game feature suggestions. \$\endgroup\$ – xuincherguixe Jul 15 '12 at 1:33
  • \$\begingroup\$ Haha, no sweat, I just figured you mentioned they might throw a torch and if that's a consideration then attentiveness certainly should be. \$\endgroup\$ – Rorrik Jul 15 '12 at 14:38
  • \$\begingroup\$ Attentiveness as it were is already consideration, but that's just it. It's a consideration. It has important gameplay ramifications that we need to think about amongst ourselves. What is a distraction, and how should they behave? This is a very broad, important, and off topic discussion. \$\endgroup\$ – xuincherguixe Jul 16 '12 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.