Jump to content
  • Advertisement
Sign in to follow this  
Parsnip Head

Blending and Vertex Buffers

This topic is 3093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
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
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!