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

Author Topic: Blending Mode "Intersection"?  (Read 3905 times)

0 Members and 1 Guest are viewing this topic.

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Blending Mode "Intersection"?
« on: February 21, 2015, 06:47:57 pm »
Hi, I'm not quite sure whether there is already such a blend mode or not. I also don't know how to build my own sf::BlendMode.

Here's what I want to do: I draw shadows using a vertex array of black triangles onto a white rendering buffer. Each vertex array contains all shadow triangles referring to one light source. When drawing the array via default blend mode, both shadows are united. When applying sf::BlendMultiply, they are also united, but the intersection part is made darker by the multiplication.

Because I'm going to build a coop-game, I want the shadows to intersect only. I added two screenshots (default blend, multiplicative blend) and a gimp-made example of what I tried to describe ^^
The example contains black lines, which indicate the lines of sight from each light source / player to each visible edge.

Is there already such an "BlendIntersect" or "BlendAnd" mode? I haven't found it, yet :-[

About the multiplicative one: I know it's not working correctly, because I'm using not only the visible edges (I use all for simplicity). So I'd like to draw the entire array (which triangles might overlap, but those overlaps should be done by default blending) to the buffer using an intersection/and mode.

Kind regards
Glocke
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

thomas9459

  • Newbie
  • *
  • Posts: 49
    • View Profile
    • Email
Re: Blending Mode "Intersection"?
« Reply #1 on: February 21, 2015, 11:32:30 pm »
I don't think it is possible to do that using just a sf::BlendMode, even if you create a custom one. It might just be easier to draw the light/visible areas, as those would overlap correctly with the default blend mode. Using a shader when drawing the final buffer could also work, although a little advanced.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11038
    • View Profile
    • development blog
    • Email
Re: Blending Mode "Intersection"?
« Reply #2 on: February 22, 2015, 12:22:00 am »
You are aware that "blending" can only happen when two things overlap right? As such you can change how light source one should blend with light source two, but whatever light source one does outside of light source two's view has nothing to do with blending.

What I mean is, that the blending process doesn't have the information needed to remove the non-intersecting part, this is something that you'll have to implement in your lighting system.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: Blending Mode "Intersection"?
« Reply #3 on: February 22, 2015, 10:00:08 am »
What I mean is, that the blending process doesn't have the information needed to remove the non-intersecting part, this is something that you'll have to implement in your lighting system.

Well, I just found a way to do so. Here's the idea:
  • Draw all shadows (which belong to one light source) to a render texture. The texture is cleared white, filled with grey or black triangles without specifying a blending mode. So we get single shadow textures per light source.
  • Then drawing all those shadow textures to another render texture. The texture was cleared in the color of the shadow (grey or black) and is filled via sf::BlendAdd.
This works because white and white stays white under sf::BlendAdd. So all light (white pixels) "survive" blending. The shadow colors are added as well, so the shadow isn't as dark as defined. But shifting the shadow color to pure black will darken the final shadow.
Finally I could use a simple fragment shader to colorize the entire shadow texture to make it darker. Seems easy (not tested, yet): If the pixel is white, it stays white. If it is not white (some kind of shadow), it is colored in the given way.

Example screenshots / saved textures are attached. What do you think about this solution? Maybe my explanation wasn't suitable :-\

Kind regards
Glocke
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11038
    • View Profile
    • development blog
    • Email
AW: Blending Mode "Intersection"?
« Reply #4 on: February 22, 2015, 11:36:47 am »
Besides me not having enough experience there's enough material about lighting on the internet that brewing your own possibly broken ideas might not be the best/efficient way to approach it. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Glocke

  • Sr. Member
  • ****
  • Posts: 289
  • Hobby Dev/GameDev
    • View Profile
Re: AW: Blending Mode "Intersection"?
« Reply #5 on: February 22, 2015, 11:51:59 am »
I finally realized, that those intersections aren't what I what to achieve. My problem was what the casted shadows aren't limited to the light's range, so other light sources might stand inside the darkness unless they are light sources xD Now, I limited the shadow casting to the light sources and the problem is gone  :)
Current project: Racod's Lair - Rogue-inspired Coop Action RPG

 

anything