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

Author Topic: Changing the BlendEquation  (Read 2878 times)

0 Members and 1 Guest are viewing this topic.

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Changing the BlendEquation
« on: April 12, 2012, 11:10:20 am »
If I want to draw something drawable onto the screen/a RenderTexture and want to temporarily set the blending equation of OpenGL to something different, how would I go about doing it in SFML2?
« Last Edit: April 12, 2012, 11:12:00 am by heishe »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Changing the BlendEquation
« Reply #1 on: April 12, 2012, 11:18:53 am »
You can't. Which blending equation would you like to use?
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Changing the BlendEquation
« Reply #2 on: April 12, 2012, 11:48:12 am »
GL_MIN.

edit: if this is not possible at all, I wouldn't mind making some custom changes to SFML. do you know which parts I'd need to change (optimally to encompass all drawables, not just specific ones like sprite or shapes)?
« Last Edit: April 12, 2012, 11:54:10 am by heishe »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Changing the BlendEquation
« Reply #3 on: April 12, 2012, 11:58:40 am »
Everything that is drawn in SFML ends up in the RenderTarget::draw(const Vertex*, unsigned int, PrimitiveType, const RenderStates&) function. You can add OpenGL calls here.

If you want to handle it as a new blending mode, you can add an item to the BlendMode enum and handle it in RenderTarget::applyBlendMode(BlendMode).

Out of curiosity, why do you need a GL_MIN blending equation?
Laurent Gomila - SFML developer

heishe

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Changing the BlendEquation
« Reply #4 on: April 12, 2012, 12:25:18 pm »
I need them for a step in a 2D shadow generation algorithm (which is on the CPU). I can do that step without min blending, but that step is currently by far the largest bottleneck in the algorithm, and with min blending the algorithm I'm using will handle hundreds of lights at high framerates, because it's largely independent of light numbers, where the algorithm used in "let there be light" depends on the number of lights on the screen. Also, it's on the GPU and practically doesn't use up anything on the CPU at all, which is good since most 2D games are very simple graphically and the performance bottlenecks are usually in CPU algorithms.

I will probably also need it for blending together signed distance fields sometime in the future. A signed distance field is just an image where every pixel of the image contains the distance to the closest obstacle. These are very expensive to create, but you can pre-calculate the large ones for static objects in  your world and then only compute small ones for your dynamic objects and blend them together using min blending, too.


« Last Edit: April 12, 2012, 12:29:28 pm by heishe »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Changing the BlendEquation
« Reply #5 on: April 12, 2012, 12:36:15 pm »
I see, thank you for the details.
Laurent Gomila - SFML developer

Vovosunt

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Changing the BlendEquation
« Reply #6 on: April 14, 2012, 01:28:18 pm »
I see what you're trying to do. I think.
I've just finished a 2D-pixel-perfect lighting system using only shaders, but it is not fast enough (for my laptop graphics card =_=", my older laptop could probably handle it much better lol)
I'm also using basically GL_MIN, but as a custom shader and it's also the bottleneck of my system.

I am quite intrigued by the fact that yours will be light-number independent.
My system can't do that unfortunately. Yet. :)

Do elaborate on your method, if you'd be so kind and if don't plan on keeping it a secret.