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

Author Topic: C# Shader Lighting Example?  (Read 3451 times)

0 Members and 1 Guest are viewing this topic.

jcsnider

  • Newbie
  • *
  • Posts: 4
    • View Profile
C# Shader Lighting Example?
« on: January 30, 2015, 11:27:57 pm »
Hello everyone!

I am working on a small 2D game engine, right now I am specifically focused on map lighting. My current code makes use of a dark render texture, adds each light to it with BlendMode.Add and then renders that over the gamescreen with BlendMode.Multiply. It works well.



How I am aware that there are alternative and possibly more optimized methods to accomplishing a similar effect. Possibly with shaders? (Which I have almost no understanding of.) One thing I really don't care for is the overlapping of lights creating the venn diagram effect.

Anyone here have any tips or possible examples of better methods to achieve this effect?

Thanks,
JC

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: C# Shader Lighting Example?
« Reply #1 on: January 31, 2015, 09:57:56 am »
Why would you search alternatives to a solution which works well, is simple to implement and gives more than good performances?
Laurent Gomila - SFML developer

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: C# Shader Lighting Example?
« Reply #2 on: January 31, 2015, 04:25:54 pm »
Because he doesn't like the "Venn diagram" effect, I guess ;-)

Hapax

  • Hero Member
  • *****
  • Posts: 3351
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: C# Shader Lighting Example?
« Reply #3 on: January 31, 2015, 04:43:16 pm »
This is how real lights works, though. Two lights lighting the same area by the same amount cause it to be twice as bright.
Adding greater fall-off to the lights could help.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: C# Shader Lighting Example?
« Reply #4 on: January 31, 2015, 07:42:24 pm »
Quote
Because he doesn't like the "Venn diagram" effect, I guess ;-)
He said "I really don't care" about it.
Laurent Gomila - SFML developer

jcsnider

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: C# Shader Lighting Example?
« Reply #5 on: January 31, 2015, 10:45:37 pm »
"I really don't care for" as in I don't really like.

This works and will be fine for its purpose but if there are other popular methods I would love to compare/contrast.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: C# Shader Lighting Example?
« Reply #6 on: January 31, 2015, 11:10:57 pm »
Quote
"I really don't care for" as in I don't really like.
Sorry, I didn't now about this meaning in english.

Quote
This works and will be fine for its purpose but if there are other popular methods I would love to compare/contrast.
This is by far the best method for what you want to achieve. As I already said, it's simple and efficient.

The "venn diagram effect" is not an issue. If you have lights that overlap, you really want their contributions to be added. This may not be obvious here, but think about a red light and a green light: what would you expect the overlapping region to look like, if not yellow?
Laurent Gomila - SFML developer

 

anything