Transparency Blocks

Started by
20 comments, last by dpadam450 13 years, 2 months ago
I am making a game simular to Minecraft.
It will not be a clone! It just has the Voxel Texture block look.

Anyway,
I want to add Glass blocks to the game.
I have the transparency and textures working and it's able to add the new blocks.
However when you look threw the Glass from the West it looks fine, when you look from the east however the world disappears.
The cause of this is that OpenGL only draws what was drawn before it in transparent objects.

So how can I make this work?

I have thought of ordering them in distance from the player each draw, but that will take waaay too long and kill meny optimazations I have in place.

Anyone have any ideas? Tacked this problem before?


Mine-craft: Player looking down threw Glass blocks at their "green house"
MinecraftGreenhouse2.jpg
If this post was helpful please +1 or like it !

Webstrand
Advertisement
Enable alpha testing?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Sorry, but I believe depth sorting to be the only solution to get visually correct transparency.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
I tried enableing it, not sure if I'm doing this correct. Alot easier to explain with a picure.
The problem is I cant draw back to front due to the fact that the player rotates.
If I was to sort by distance that could take minutes to sort all the blocks for 1 frame.

GL Init Code:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glAlphaFunc ( GL_GREATER, 0.1f) ;
glEnable ( GL_ALPHA_TEST ) ;


Problem:
bug1.png
If this post was helpful please +1 or like it !

Webstrand
You cannot do blending without sorting back to front. However from what I see of your glass blocks you do not actually need to blend anything, you just want them to have some blue pixels and some transparent pixels. You can achieve this result with just alpha-testing instead of blending. You won't need to do any sorting to do just alpha testing.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
There has to be a solution, this is what I am trying to obtain:
5294190minecraft-classic-1.png
This is what I have:
http://webstrand.com...m/pics/bug2.pngbug2.png

I don't even have to have variable alpha.
If the block can be like 1/2 clear all over that would be fine.

Anyone have a solution for the water blocks?
If this post was helpful please +1 or like it !

Webstrand
Also try disabling depth writing for the alpha blending. glDepthMask(GL_FALSE);//i think its false
it will still depth test, but not depth write, this way you can still draw them order independent and get somewhat satisfaction.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal


Also try disabling depth writing for the alpha blending. glDepthMask(GL_FALSE);//i think its false
it will still depth test, but not depth write, this way you can still draw them order independent and get somewhat satisfaction.


Won't work.

If you disable depth write for the water block, and draw blocks in arbitrary order, than the blocks behind the water will be drawn on top of the water if they are drawn after (because the water blocks are not in the depth buffer).


You've only got two options:

1) Do depth sorting
2) Don't use blending

I'm sorry if this doesn't work with your engine. If you want to do blending, than what's behind your object must be in the color buffer when you draw the object, that's just how it works.

http://www.opengl.org/resources/faq/technical/transparency.htm

If you can sort blocks such that all the transparent blocks are rendered last (even if they are out of order), than maybe you can use additive blending which is order independent. But you can't use alpha/1-alpha blending out of order.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game

If you can sort blocks such that all the transparent blocks are rendered last (even if they are out of order), than maybe you can use additive blending which is order independent. But you can't use alpha/1-alpha blending out of order.
[/quote]
Yea this is what I meant.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Oh man, I was afraid of this

You've only got two options:

1) Do depth sorting <--would take to long with the default 5x5x5x16x16x16 blocks on screen
aka 512,000
2) Don't use blending

Additive blending?
If its order independent I guess this is what I will have to use.
Could I use this with the water blocks so that their say, 50% transparent?

Could you elaborate a little about how I can use additive blending with water blocks?

Thanks for all the info so far!
If this post was helpful please +1 or like it !

Webstrand

This topic is closed to new replies.

Advertisement