Lighting effects

Discussion in 'Game Development (Technical)' started by GolfHacker, Dec 21, 2009.

  1. GolfHacker

    GolfHacker Member

    Joined:
    Oct 4, 2006
    Messages:
    1,073
    Likes Received:
    0
    These two scenes from the New Super Mario Bros Wii got me thinking again about doing some lighting puzzles in Dirk Dashing 2.

    [​IMG] [​IMG]

    I think it's pretty cool how the jellyfish and the spotlight reveal portions of the level while leaving other parts obscured. But I'm trying to figure out how I can do something this in my game. There must be a trick to this effect, but I can't figure it out. Anyone know the secret?
     
  2. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Depending on the hardware it's either a stencil effect, or a render to texture off-screen buffer you subtract from the main buffer/alpha blend an image you subtract alpha from.
     
  3. Acord

    Acord New Member

    Joined:
    Jul 26, 2008
    Messages:
    1,217
    Likes Received:
    0
    Man, I HATE those levels!
     
  4. Bad Sector

    Original Member

    Joined:
    May 28, 2005
    Messages:
    2,742
    Likes Received:
    5
    What i would try to do is to merge (blend) all "light" areas in a single texture which would initially be black (or very dark gray) and light areas would be a gradient going from white to dark gray. Then i would do a multiply blend to the full screen after everything has been rendered. The hardware requirements are the same as those needed to run GLQuake 1 :p (well, plus bigger textures of course).

    [​IMG]

    Basically, since its blending you can also add some color in there (like the second shot seems to do with the edges of the light cone).
     
  5. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Oh wow! A far better idea than the subtractive thing I was suggesting.
     
  6. jcottier

    jcottier New Member

    Joined:
    Jul 12, 2006
    Messages:
    1,385
    Likes Received:
    0
    I'll do it the same way as BadSector: add light.

    Also, you don't need to use 'grey' light source, you can use any color. You don't need to create a massive texture for that, no needs to have the same resolution as your rendertarget. You could create a small texture and use bilinear filtering when you render it on your whole screen. Finally, I'll do the rendering of the light in software (unless you want to enter complex pixel shading stuff).
    In software, you could make a more complex lighting system where you can 'mix' colors properly. and apply a full blur on your final texture to remove the edges. Don't think it will cost much CPU, if you use a small 256x256 texture in 32 bits it won't take that much time to process it.

    JC
     
  7. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Or just render at low res and get free blurring from the bilinear filtering.
     
  8. jcottier

    jcottier New Member

    Joined:
    Jul 12, 2006
    Messages:
    1,385
    Likes Received:
    0
    If your shadow or light texture for this example is very small, then bilinear filtering is not enough to hide the low res from my experience. With today's cpu, you can take the time to apply a complex blur (or few times a simple one) and the end result is way better.

    From my experience, it's better to do it that way. If you use a bigger texture with more res, the end result is less interesting as your shadow/light edge are very sharp. It's much more natural to have smooth edges for lighting and using low res texture + blur give you this result.

    JC
     
  9. PoV

    PoV
    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    2,132
    Likes Received:
    0
    Alright. If you don't like that, then use some extra geometry along the edge of your shadow volume with vertex colors to give it a softer look. One thing to try, increase the distance from the original geometry as you get further away from the light source. No CPU needed (short of generating the geometry, but could be precomputed and transformed).
     
  10. Asvarduil

    Asvarduil New Member

    Joined:
    Sep 6, 2009
    Messages:
    76
    Likes Received:
    0
    I think Bad Sector's technique would be the least expensive way of achieving this - just an alpha mask, and some space for the mask file...and with the advent or terabyte hard drives, a few kilobytes one direction or another will not make or break your game.

    Besides, it passes the three primary checks: is it a)simple, b)elegant, c)effective? I'm drawing a "oui" on all three.
     
  11. vjvj

    Indie Author

    Joined:
    Sep 25, 2004
    Messages:
    1,732
    Likes Received:
    0
    Yeah, the "trick" to this is just alpha. Bad Sector's implementation is exactly what I would do.

    Use alpha ADD (clamping to 1.0) when compositing the light texture, so that overlapping light volumes accumulate "correctly". Then use alpha BLEND when overlaying the light texture on top of your scene. Done!
     
  12. GolfHacker

    GolfHacker Member

    Joined:
    Oct 4, 2006
    Messages:
    1,073
    Likes Received:
    0
    Alpha-blending! Duh! Why didn't I think of that??

    Thanks, guys! That is indeed a simple and elegant solution.
     
  13. lakibuk

    Indie Author

    Joined:
    Jul 27, 2004
    Messages:
    961
    Likes Received:
    0
    Yes, something like this should be used with caution in a game.
    Not seeing stuff is usually not very funny.
    I don't know how it's used in the Wii Super Mario, probably in a good way. Nintendo's got the best game designers.
     

Share This Page

  • About Indie Gamer

    When the original Dexterity Forums closed in 2004, Indie Gamer was born and a diverse community has grown out of a passion for creating great games. Here you will find over 10 years of in-depth discussion on game design, the business of game development, and marketing/sales. Indie Gamer also provides a friendly place to meet up with other Developers, Artists, Composers and Writers.
  • Buy us a beer!

    Indie Gamer is delicately held together by a single poor bastard who thankfully gets help from various community volunteers. If you frequent this site or have found value in something you've learned here, help keep the site running by donating a few dollars (for beer of course)!

    Sure, I'll Buy You a Beer