Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: dynamic shadows  (Read 7415 times)

0 Members and 2 Guests are viewing this topic.

Jarwulf

  • Newbie
  • *
  • Posts: 37
    • View Profile
dynamic shadows
« on: April 09, 2010, 08:50:32 pm »
does SFML have any built in resources to ease dynamic shadow and light generation or do I have to jump directly into OpenGL?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
dynamic shadows
« Reply #1 on: April 10, 2010, 10:33:57 am »
It depends what you want exactly. You can fake some lighting effects using alpha-blended sprites (with additive or multiplicative blending mode).

In SFML 2 you can do much better with render-images.

You can also use a fragment shaders (sf::PostFx in SFML 1, sf::Shader in SFML 2).
Laurent Gomila - SFML developer

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
dynamic shadows
« Reply #2 on: April 10, 2010, 10:18:48 pm »
For 2d lighting, you can just draw a lightmap every frame.

1. Create an image equal to the size of the backbuffer (create only once during initialization)
2. Clear the screen with black
3. Use additive blending to draw on light sprites (stretch to increase size, increase color closer to 255/255/255 to increase intensity)
4. Draw all the lights
5. Copy the backbuffer to your lightmap image
6. Clear the screen, draw as normal
7. After you finish drawing, draw your lightmap on top of the screen using Multiply blending

Very simple but versatile 2d lighting using just SFML. :)

Jarwulf

  • Newbie
  • *
  • Posts: 37
    • View Profile
dynamic shadows
« Reply #3 on: April 11, 2010, 04:14:16 am »
Quote from: "Spodi"
For 2d lighting, you can just draw a lightmap every frame.

1. Create an image equal to the size of the backbuffer (create only once during initialization)
2. Clear the screen with black
3. Use additive blending to draw on light sprites (stretch to increase size, increase color closer to 255/255/255 to increase intensity)
4. Draw all the lights
5. Copy the backbuffer to your lightmap image
6. Clear the screen, draw as normal
7. After you finish drawing, draw your lightmap on top of the screen using Multiply blending

Very simple but versatile 2d lighting using just SFML. :)



That sounds like it'd be enough for static lighting,but I'm interested in workable dynamic lighting. I know that this sort of thing would have probably been dicey just a short time before but I was hoping somebody had come up with a solution for it.

I have some ideas such as checking each pixel to see whether or not an object intersects the line between it and a light source but I'm not sure if they'll be fast enough to be workable for a game.

Spodi

  • Full Member
  • ***
  • Posts: 150
    • View Profile
    • http://www.netgore.com/
dynamic shadows
« Reply #4 on: April 11, 2010, 06:12:42 am »
Oh, so you mean something more like this? The approach given there, even though it is for XNA, can easily be translated to SFML since it uses something similar to what I mentioned. Though it will start to be slow VERY quickly as you increase the number of light sources and objects.