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

Author Topic: Dynamic light(shadow), as create?  (Read 2545 times)

0 Members and 1 Guest are viewing this topic.

GalakTozawr

  • Newbie
  • *
  • Posts: 17
  • You must create more game that oneself.
    • View Profile
    • My SFML lesson for russian language
    • Email
Dynamic light(shadow), as create?
« on: May 07, 2014, 09:32:53 pm »



Light should move.
what tools are needed for this?
An example of what I want to get:

Only moving light areas must be many.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Dynamic light(shadow), as create?
« Reply #1 on: May 07, 2014, 09:45:50 pm »
There are different possibilites. The simplest one would be a texture that acts as a stencil/mask and that is drawn on top of the colored image. Use the latest master revision on GitHub to benefit from the new sf::BlendMode class.

An alternative is a GLSL fragment shader.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

GalakTozawr

  • Newbie
  • *
  • Posts: 17
  • You must create more game that oneself.
    • View Profile
    • My SFML lesson for russian language
    • Email
Re: Dynamic light(shadow), as create?
« Reply #2 on: May 07, 2014, 09:57:08 pm »
Sorry to bother you, you can give sample?

Or how to implement lighting as there:


Or some simple lighting system. And my happiness will unlimited!
I use sfml 2.1

« Last Edit: May 07, 2014, 10:07:34 pm by GalakTozawr »

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Dynamic light(shadow), as create?
« Reply #3 on: May 07, 2014, 10:21:46 pm »
Basically:
sf::BlendMode customBlendMode = ...;

window.draw(background);
window.draw(mask, customBlendMode);
This approach is of course limited, but it is able to lighten/darken a constant area. You may not even need custom blend modes if you simply want to darken an existing image.

More is explained in the tutorials and documentation about rendering sprites and blend modes, please read them.

Lighting systems have already been provided as an SFML extension, search for "Let There Be Light" and "GLLight2D" in the project forum.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development: