Transparent voxels

Started by
14 comments, last by riuthamus 11 years, 1 month ago
Is there a way to properly render layered transparent objects when you can't do depth sorting? Since the terrain is all built up into 2 vertex buffers per region (1 for solid blocks, 1 for transparent blocks), we can't do the typical depth sorting. Are there any alternatives?

This is what its coming out like right now:

[attachment=13842:RuinValor 2013-02-23 21-42-37-02.png]
Advertisement

Keep in mind we are trying to get alphas on a model like this:

Death_Prophet.png

* Use alpha-testing instead of alpha-blending where possible.

* You can do depth-sorting by dynamically creating a new list of indices (in a dynamic index buffer) each frame.

* You can do order-independent transparency (I wouldn't recommend it, it's too expensive on most hardware).

* If you can't do depth-sorting, then what I'd recommend is the Alpha Compositing trick from 'Foliage Rendering in Pure', which results in your grass sprites having soft/blended areas when they overlap with opaque geometry, but hard edges anywhere where they overlap with other grass sprites.

This works by:

-- drawing your opaque scene to render target A.

-- clearing render target B to black.

-- Drawing your grass with additive blending and no depth testing, and a write mask of rgb=false, a=true (so that only the alpha channels are summed).

-- Drawing your grass with depth-testing and alpha-testing (no blending), and a write mask of rgb=true, a=false (so that only the colour channels are written).

-- Alpha blending the texture B over the top of render-target A.

Keep in mind we are trying to get alphas on a model like this

That model looks like it only needs alpha-testing, not alpha-blending, so it won't have any problems to begin with smile.png

Ah.. well i saw some things behind it, here let me give you a better example:

gallery_1_8_386976.jpg

gallery_1_8_808132.jpg

Added a video so you can see what it looks like more clearly. Should be in 1080p here shortly:

[media]

[/media]

It looks like simple "sample alpha to coverage". It will give you order independent transparency with antialiasing, but you will have just N levels of transparency, where N equals your (multi)samples count for your framebuffer. Nah I'm not a good teacher, rather see here:

Here is a demonstration with brief description - http://www.humus.name/index.php?page=3D&ID=61

My current blog on programming, linux and stuff - http://gameprogrammerdiary.blogspot.com

-- Drawing your grass with additive blending and no depth testing, and a write mask of rgb=false, a=true (so that only the alpha channels are summed).

-- Drawing your grass with depth-testing and alpha-testing (no blending), and a write mask of rgb=true, a=false (so that only the color channels are written).

First pass state:
descBlendAlphaOnly.RenderTarget[0].IsBlendEnabled = true;
descBlendAlphaOnly.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Alpha;
descBlendAlphaOnly.RenderTarget[0].SourceBlend = BlendOption.SourceAlpha;
descBlendAlphaOnly.RenderTarget[0].SourceAlphaBlend = BlendOption.SourceAlpha;
descBlendAlphaOnly.RenderTarget[0].DestinationBlend = BlendOption.One;
descBlendAlphaOnly.RenderTarget[0].DestinationAlphaBlend = BlendOption.One;
Second pass state:
descBlendColorOnly.RenderTarget[0].IsBlendEnabled = false;
descBlendColorOnly.RenderTarget[0].RenderTargetWriteMask = ColorWriteMaskFlags.Red | ColorWriteMaskFlags.Green | ColorWriteMaskFlags.Blue;
Are these correct?

This is the result I'm getting:
[attachment=13870:RuinValor 2013-02-24 00-33-06-95.png]

I have no alpha testing on the first pass and the 2nd pass uses this:

if(color.a == 0.0f)
	discard;
Not sure why they have light halos against the sky/ground... that might be a problem with the composition pass? Make sure you're using traditional alpha blending for that pass (src*srcAlpha+dst*invSrcAlpha).

But the dark outlines against other bits of grass are "correct", simply because your grass texture contains those dark colours in it (i.e. it's an art problem) wink.png

If you want smoother edges in the areas where multiple bits of grass overlap, you can use:
//in 1st pass, only use the top 50% of the alpha channel
return saturate(color.a*2-1).xxxx;
 
//2nd pass, discard at the 50% mark
if(color.a < 0.5f)
    discard;
or
//in 1st pass, only use the top 75% of the alpha channel
return saturate((color.a-0.25)/0.75).xxxx;
 
//2nd pass, discard at the 25% mark
if(color.a < 0.25f)
    discard;
etc

I added a dark bg for simple testing purposes. I know that when I am making the final one I need to have something near the color tone of the primary color.

Actually scratch that, he said he is using a PNG that i made... the png is here. It has no alpha.... so not sure why that would happen

gallery_1_8_19068.png

I had the wrong blend mode. Halos are fixed now. Can we use premultiplied alpha to get rid of the grass-on-grass darkness? Or does that not work?

Edit: Another question: will this work for glass and other transparent blocks without looking terrible?

This topic is closed to new replies.

Advertisement