How to fix blending?

So I’ve got this shader:
http://pastebin.com/5iax5iX6

And I render it through a for loop like this:

for(Light light : lights)
[bind shader]
[enable blend: blend function (GL_SRC_ALPHA, GL_ONE)]
[shader uniforms based on light]
[render large quad the size of the display]

for(Entity e : entity)
[enable blend: blend function (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)]
[render entity]
[disable blend]

[bind shader]

I’ve tried other blending methods, and most of them don’t let more than one light… light it.

Image:

MP4 format: http://gyazo.com/ea3b8611e0d746a1f8783db22320a198

I’m sorry, but what is the problem exactly and what behavior are you attempting to achieve?

I’m trying to make the squares not transparent, but also allot multiple shader passes to show.

Is there anyone who can help? I kinda need this to work for my game engine.

What is the behavior you want exactly though? In your GIF, the lights seem to be working fine, however the squares are semi-transparent and show through. You want one square to be completely opaque and on top of the other?

Maybe it’s a Z-ordering problem. Try clearing the depth buffer as well so you can have control over your z positions. This way you won’t have to do any weird render order stuff.

Yes…

I tried clearing the depth buffer, no difference. Is that all you meant, or do I have to do something else?

Perhaps I’m completely wrong, but I still try…

In the algorithm you give, the entities are never completely opaque when rendered.
When the background is black, the blending isn’t a problem. But for the second entity, the background isn’t black into the crossing section and the problem occurs.
This certainly also occurs when the background color isn’t black.
I think the problem is the fact that all rendering (entities and lights) are done in the same loop.

If I would try to achieve this :

  • Fisrt pass : render all the entities with zbuffer + diffuse texture only (no shader, no blending)
  • Second pass : for each entity, loop thru lights and for each light, render entity with light’s informations (shader, no diffuse texture, blending enabled)
  • Third pass : render the lights squares (shader, blending enabled)

The goal of this algorithm is to avoid overdraws and blending between entities.

Hope this will help a little.