Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Ordering draw calls for alpha blending  (Read 1264 times)
0 Members and 1 Guest are viewing this topic.
Offline ipe369
« Posted 2014-07-05 12:01:02 »


I recently ran into a problem where having multiple calls to opengl to draw translucent geometry produced some funky results. I googled it, and I believe the problem has something to do with having to order the draw calls from back to front.

I was curious; how should I go about doing this?

My game features an infinite world, split into chunks. Each chunk is 1 VBO. I can order the VBOs from back to front no problem. But will this fix the problem,? Or do I need to order the draw calls within the VBO too? Wouldn't that be quite awkward to do, especially if you have a face that has 2 vertices behind another face, but 2 vertices in front of that same face?

I'm a little puzzled if I have to be honest. The only thing I know is that the weird alpha drawing only happens between chunks. This leads me to believe I only need to order the separate VBOs rather than the inner calls to openGL to draw the faces...

Anyway, thanks:P
Offline Hermasetas

Senior Duke

Medals: 6
Projects: 2
Exp: 3 years

I do gamez, yes!

« Reply #1 - Posted 2014-07-05 13:10:46 »

I can order the VBOs from back to front no problem. But will this fix the problem,?

Try it Tongue

Also some pictures might help Smiley
Offline ipe369
« Reply #2 - Posted 2014-07-05 13:32:01 »

Just wondering if anyone had any experience with it, before I jump in and do something:P
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline orange451

JGO Coder

Medals: 11
Projects: 2
Exp: 4 years

Your face. Your ass. What's the difference?

« Reply #3 - Posted 2014-07-05 17:06:42 »

You can order everything based on distance to the camera.

Working on a nice FPS in lwjgl Smiley
Feel free to message me if you're interested!
Offline ipe369
« Reply #4 - Posted 2014-07-05 17:17:33 »

But the point is, do i need to order every draw call, or just the order in which the VBOs are drawn?
Offline Longarmx
« Reply #5 - Posted 2014-07-05 17:25:44 »

I experienced this problem with my 3d world. Instead of sorting everything back to front, I just discarded the pixel with a custom shader.

varying vec2 texCoords
out vec4 color;
uniform sampler2D sampler

void main()
     vec4 textureColor = texture2D(sampler, texCoords.xy);

     if(textureColor.w <= 0.01) // If the pixel is basically transparent
          discard; // Throw this fragment away;

     color = textureColor; // Else assign this fragment to the pixel's color

Unfortunately, this method only works for completely transparent textures. If you want translucency, then you will have to sort back to front instead of using this method.

Offline ipe369
« Reply #6 - Posted 2014-07-05 17:29:45 »

But how could you sort it back to front if half the vertices of 1 poly are behind, and the other half are in front?
Offline theagentd
« Reply #7 - Posted 2014-07-05 20:16:48 »

Most games don't have anything transparent except for particle effects, e.g. smoke, fire, sparks etc, which are easier to sort as they are flat quads facing the camera (so no impossible scenarios can occur). Games generally completely avoid having semi-transparent geometry due to the complexity of handling that. The closest thing available is alpha testing, which isn't really transparency. It's exactly what Longarmx wrote about, where you discard pixels that are "too transparent", effectively achieving binary transparency (either fully opaque or fully transparent).

Offline basil_
« Reply #8 - Posted 2014-07-06 13:34:01 »

order independent blending is really hard to do right.

sorting triangles will only approximate correct results; there are too many special cases when simple sorting fails ... like overlapping triangles.

state of the art of dealing with transparency is using per-pixel-linked-lists afaik, using a so called "a-buffer". a list of values per pixel, sorted per pixel and drawn blended back to front. too bad it requires rather recent hardware, i think gl 4.3+.

some random google results :
Offline Roquen
« Reply #9 - Posted 2014-07-06 14:28:29 »

It'd be interesting to think about a hybrid of the weighted OIT with fixed number of layers and no sorting per say.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ipe369
« Reply #10 - Posted 2014-07-06 15:06:56 »

Hm, okay. I guess I should abandon this then - I was going to have all of the terrain above a certain height translucent, so that you could not only see a 'cross section' of the terrain but also the full shape of the terrain.
Offline Roquen
« Reply #11 - Posted 2014-07-06 19:10:26 »

 Skip on the a-buffer:

further out:

Possible today on low-end:
Offline basil_
« Reply #12 - Posted 2014-07-06 20:59:52 »

aah cool, thanks! Smiley I'd love to skip a-buffers. they cannot be speedy or easy on memory usage.

stochastic blending is about abusing msaa buffers to do order independent "dither" type blending ?
Offline Roquen
« Reply #13 - Posted 2014-07-06 21:32:16 »

stochastic is pretty far out.  yeah: the high view is many samples of some fencing/dither pattern per pixel (a la old software rendering trick).
Offline Roquen
« Reply #14 - Posted 2014-07-06 21:47:29 »

Other random thoughts are the volumetric stuff: fourier opacity mapping, extinction transmittance maps, half-angle slicing. 
Offline basil_
« Reply #15 - Posted 2014-07-11 11:19:58 »

reads really good :
Offline Roquen
« Reply #16 - Posted 2014-08-18 10:07:19 »

Efficient Rendering with Tile Local Storage:
Pages: [1]
  ignore  |  Print  


Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (35 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (55 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!