Jump to content
  • Advertisement
Sign in to follow this  
gnomer

would i use shader/postprocessing for this?

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

I'm still trying to get my head around shaders. Would it be able to achieve the effect I'm looking for. What I want is this:

Imagine a game level, lit by various light sources. You have a device similar to a flashlight that whatever it "see's" will be the only areas that light up. Everything else is blackness. I don't know if this makes sense, I'm not trying to make a flashlight but that is closest example I could think of. This "flashlight" devices doesn't actually cast light it only allows the areas it sees to be able to receive light from the other light sources, if that makes sense.

Is this crazy idea something I would do with shaders and/or postprocessing? I just want to focus my study in the right area.

Thanks for any feedback.

Share this post


Link to post
Share on other sites
Advertisement
What you are describing is very similar to casting shadows. When you are computing shadows, either via render to texture or via the stencil buffer, you are just marking some areas of the scene as 'in' and some as 'out'.

What you do after something is marked 'in' or 'out' is up to you. For instance, you could use one of several shadow map techniques ( with the 'flashlight' standing in for a spotlight or point light ) to mark areas of the scene where things will show up.

Then you can do the lighting effect on just those areas of the scene.

Alternately, you could light the whole scene first, then darken or remove the effect everywhere that's NOT marked, but this usually breaks down if you ever have > 1 'flashlight volume' on screen at a time.

Share this post


Link to post
Share on other sites
Quote:
Original post by SimmerD
What you are describing is very similar to casting shadows. When you are computing shadows, either via render to texture or via the stencil buffer, you are just marking some areas of the scene as 'in' and some as 'out'.

What you do after something is marked 'in' or 'out' is up to you. For instance, you could use one of several shadow map techniques ( with the 'flashlight' standing in for a spotlight or point light ) to mark areas of the scene where things will show up.

Then you can do the lighting effect on just those areas of the scene.

Alternately, you could light the whole scene first, then darken or remove the effect everywhere that's NOT marked, but this usually breaks down if you ever have > 1 'flashlight volume' on screen at a time.


Your second solution sounds like what I'm after. There should only ever be one of these "visibility lights". I'd like to black out anything not in it's line of sight. So I guess there would be a standard lighting pass for all lights in the scene and then a second pass that omits whatever isn't in this visibility light?

Is there an easy way to determine if something is being lit by a specific light source?

Share this post


Link to post
Share on other sites
Quote:
Original post by Emergent
Is this first-person? Top-down? Over-the-shoulder?


Top down.

Share this post


Link to post
Share on other sites
Don't know if it's sufficient, but you could try:
- render the scene as usual
- finally render a screen filling quad on top that "lits" by multiply blending

This quad is sort of a post effect. It's shader would draw a circle(?) of white pixels whereever the "flashlight" is, all other pixels are left black (or any other color).

For example, you could draw a spotlight texture (just a bright white spot on a black background, but any other shape is also possible) and move it over that quad like this:

<multiply quad shader>
// get spot texture. Adjust the texcoords so that the spot doesn't fill the entire
// screen, and shift them to a XY position (going from 0 to 1)

// Texture coordinates are originally 0..1, each quad corner vertex is
texcoords.x *= scale.x; // If the spot is 25% of the screenwidth, it would be '4'
texcoords.y *= scale.y;

// Shift. For example, use the mouse. If the mouse is topleft, it would be 0,0
// when it's bottomright, it would be 1,1
texcoords.x += mouse.x;
texcoords.y += mouse.y;

// Black pixels will darken the background, pure white pixels will keep the
// original color.
out.rgb = tex2D( spotTexture, texcoords );

Eventually you can have more than 1 spot. Ow, and disable tiling on the texture, otherwise you'll see that spot all over the screen. By the way, you don't even need shaders to do this, as you can also shift/scale texcoords inteh default pipeline of course.

Clearly this only works if you have 2D lighting from top. It get's a whole lot different if 3D volumes such as cones are used.

Rick

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!