Sign in to follow this  
Parsnip Head

Blending and Vertex Buffers

Recommended Posts

Parsnip Head    100
Hello, I'm trying to work through the problem of being able to order my textured quads by their z depth, but also enable alpha blending. After reading lots on the internet, the approach I'm going to try is to turn the depth buffer off and order the quads in a vertex buffer by hand according to their z depth. In other words, say I add a quad to the vertex buffer, then subsequently add another quad that has a greater z depth, I'm going to shift the data for the 1st quad and add the data for the 2nd quad before it in the vertex buffer. My first question is... is this the usual / most efficient way to do it? My second question is, if I do it this way and have 1 big vertex buffer, is there a way I can change blending modes on certain quads within that buffer? I'd like to make a few of them additive. Cheers

Share this post


Link to post
Share on other sites
Geometrian    1810
The usual way to do this is to sort via the CPU (i.e., you draw them in back to front order). You can just change the blending modes for certain polygons as you see fit. It's not elegant or very nice--blending transparent polygons correctly sans sorting is one of the most devious problems in graphics.

One thing I've tried is to do the blending "manually", with a shader and FBO. You can store a fragment's color/depth in a multi-rendertarget FBO, and then "push back" the relevant fragments to other rendertargets when you write a fragment in front of the current value. This effectively is a depth peel, storing color. From there, you can just blend the rendertarget textures together back to front as you see fit.

'Course, if your quads blend additively, you can just draw them in any order . . .

-G

Share this post


Link to post
Share on other sites
Parsnip Head    100
Right I see. That sounds like a great solution, because the other question I had was is there a way to bind multiple textures to a single vertex buffer. I'm already using texture atlases, but you sometimes still have to use more than one texture if there are size limits and you have a lot of textures.

But it sounds like your solution would deal with that as well, if I understand it correctly. Thanks man! That was a really useful answer. I'll look into shaders and FBOs next. :)

Cheers!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this