Question about blending

I have a question about blending, maybe I’m incorrect about this but as far as I can tell if I want a texture to blend I need to draw it AFTER the textures I want blended with. For example if I have a water texture I want blended with the land beneath it, I need to draw the land first, then the water.

My question is if it is possible to have a texture blend with everything irregardless of when it is drawn. It will still need to pass the depth test of course so it isn’t drawn if something is in front of it.

Reason I ask is because I am drawing skyscraper buildings with some blended lights. When I draw the building I draw the walls, windows, and a few other things first, then draw the blended lights last, works just fine. However if I want to draw multiple buildings the lights don’t blend with later drawn objects.

I know I can work around this, but I’m hoping I don’t have to. For example I can do something like this:

for (int i=0; i<AllBuildings.size(); i++) {
for (int i=0; i<AllBuildings.size(); i++) {

But I would rather do this:

for (int i=0; i<AllBuildings.size(); i++) {

Hopefully this makes sense…

If you don’t have any translucency in your light textures or don’t need to do any partial blends, you might be able to use alpha testing.

Hey pjyelton,

What you’re asking is a fundamental limitation with the OpenGL pipeline. As you said, you have to draw the land first then the water in your example because the water needs the land there to compute the blending. It also writes to the depth buffer, so if it were rendered first, the land wouldn’t ever get written. There are many papers on single-pass transparency, but most aren’t used very often as they add several other issues like performance hits.

One method that’s moderate useful is depth peeling. Since you’re doing a city, which is somewhat orderly, you can probably get away with an easier solution, but I’d need to see a screenshot of your “blended lights” in action first.