Jump to content
  • Advertisement
Sign in to follow this  

Projective FlashLight

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

Hi, I've added a flashlight effect with projective texturing. The level itself is using a lightMap, so I couldn't add a real light that easily. So I did it like this:
- Just render the scene like normal

If the flaslight is on:
- Render a second pass
  Use a shader that does projective texturing so you can see the lightSpot on the   walls
- Blend the 2 passes together (additive)
It works pretty cool, and I could even add normalMapping to it since I know where the flashLight position is. But there are 2 problems. First of all, the second pass is added. When a room is very dark, the litten spots will just become gray-ish, instead you suddenly see its colors from the decalMap. This is because: color = lightMap * decal * <other stuff> + spotLightTexture; If the lightMap is nearly black, you basically only see the spotLight texture. Is there a better way to blend? I could also use the decalMap in the second "flashLight" pass. But it makes the pass heavier, and it leads to conflicts with some materials. For example, some surfaces are using parallax mapping. When "pasting" a second pass on it that uses a decalMap but no parallax mapping, the pixels are placed wrong. Second problem is that it's not very fast. Rendering the whole thing twice is not a problem if it comes to polyCount, but the blending is pretty slow I guess. It would be smarter if only the litten polygons use a second pass, but how the heck do I know on which polygons my flashLight is shining? So... any good "flashlight" tips? Greetings, Rick

Share this post

Link to post
Share on other sites
Try adding your flashlight to the lightmap value before modulating with the decal texture.

To speed things up, create a frustum from the flashlight beam and pass that through your octree, bsp, etc. to get a list of chunks to render. You don't want to go to the individual triangle level here, but if you could get 150-1000 polygon chunks that partly hit the flashlight frustum, that would probably work...

Share this post

Link to post
Share on other sites
That would indeed be better, but the lightMap isn't just a texture that is multiplied with the decal texture (like I wrote in that code line). I'm using lightMapping & normalMapping (like Halflife2 does). There can be 0/1 flashLights, but also more projective textures / flashLights.

So I was thinking about this:
Pass1: Render the lightMap with normalMapping, eventually with parallax mapping
Pass2..n: Render x projective textures/dynamic lights/flashLights. Add them to pass 1
Pass3: Render the decalMap, eventually with parallaxMapping and some other stuff.

But that leads to several problems. First of all, I'm afraid this will be (much) slower. Dynamic lights or not, now there have to be 2 passes always. And things like parallax mapping must be done in both shaders.

And how to add specular lighting? The specular term (or cubeMap reflection) should not be multiplied with the lightMap pass.

The fastest way would be writing everything in 2 shaders. 1 with flashLigh, and 1 without. But making a variant for each shader sucks, and it's still a problem when I want >1 flashLights...

Thanks for helping,

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!