This is what its coming out like right now:
Transparent voxels
#1 Members - Reputation: 646
Posted 23 February 2013 - 08:48 PM
This is what its coming out like right now:
#2 Crossbones+ - Reputation: 2475
Posted 23 February 2013 - 08:50 PM
Keep in mind we are trying to get alphas on a model like this:

My game project blog.
#3 Moderators - Reputation: 13599
Posted 23 February 2013 - 08:56 PM
* 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.
That model looks like it only needs alpha-testing, not alpha-blending, so it won't have any problems to begin withKeep in mind we are trying to get alphas on a model like this
Edited by Hodgman, 23 February 2013 - 08:58 PM.
#4 Crossbones+ - Reputation: 2475
Posted 23 February 2013 - 09:07 PM
Ah.. well i saw some things behind it, here let me give you a better example:


Added a video so you can see what it looks like more clearly. Should be in 1080p here shortly:
Edited by riuthamus, 23 February 2013 - 09:17 PM.
My game project blog.
#5 Crossbones+ - Reputation: 746
Posted 23 February 2013 - 10:02 PM
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
#6 Members - Reputation: 646
Posted 23 February 2013 - 11:34 PM
First pass state:-- 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).
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:
I have no alpha testing on the first pass and the 2nd pass uses this:
if(color.a == 0.0f) discard;
Edited by Telanor, 23 February 2013 - 11:35 PM.
#7 Moderators - Reputation: 13599
Posted 24 February 2013 - 12:37 AM
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)
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
Edited by Hodgman, 24 February 2013 - 12:45 AM.
#8 Crossbones+ - Reputation: 2475
Posted 24 February 2013 - 12:41 AM
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.

Edited by riuthamus, 24 February 2013 - 12:45 AM.
My game project blog.
#9 Crossbones+ - Reputation: 2475
Posted 24 February 2013 - 12:50 AM
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

My game project blog.
#10 Members - Reputation: 646
Posted 24 February 2013 - 01:08 AM
Edit: Another question: will this work for glass and other transparent blocks without looking terrible?
Edited by Telanor, 24 February 2013 - 02:39 AM.
#12 Members - Reputation: 637
Posted 24 February 2013 - 02:47 PM
admittedly, I am not really sure if premultiplied alpha really makes much of a difference. usually what seems to cause this sort of effect IME is the color values within the fully transparent pixels, which some graphics programs I use (such as Paint.NET) seem to automatically replace fully transparent pixels with black.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?
a trick I have used which mostly fixes the issue in my case, was to have a blurred version of the image in the background with a very low (but not quite zero) opacity, which causes the colors near the edges to "bleed over" into the transparent pixels.
another related trick is to use weighted blending when generating mipmaps.
say, rather than:
r=(r0+r1+r2+r3)>>2;
g=...
a person can use something like:
ta=a0+a1+a2+a3;
af0=(4096*a0)/ta;
...
r=(af0*r0+af1*r1+af2*r2+af3*r3)>>12;
g=(af0*g0+af1*g1+af2*g2+af3*g3)>>12;
...
which is slightly more costly, but oh well...
another thing:
I draw my terrain in front-to-back order for opaque geometry, and back-to-front for alpha blended geometry.
granted, in my case, I render the terrain per-chunk. though not perfect, the use of per-chunk sorting usually draws things in "about the right order". rendering per-chunk also allows omitting chunks which are not visible.
this gives the correct draw order "in general", but by itself may still result in transparent geometry clipping within the same chunk, but this isn't usually as big of an issue IME.
for better sorting, a BSP + index-array or similar can be used. say, a BSP walk is done and used to fill out the contents of an index array. another simpler (but more costly) solution, could be using a variant of QuickSort, and sorting alpha-blended geometry per distance (probably only for chunks near the camera).
likely, if a BSP were used, this could be a small (per-chunk) BSP, probably using a quick-and-dirty algo whenever the geometry for the chunk is rebuilt.
the BSP is probably only needed for blended geometry, whereas for opaque geometry, the exact draw order is less important, and it is much more useful to have everything sorted out by texture/material.
Current Status / Downloads: http://cr88192.dyndns.org:8080/wiki/index.php/BGB_Current_Status
YouTube Channel: http://www.youtube.com/user/BGBTech
Main Page: http://cr88192.dyndns.org:8080/wiki/index.php/Main_Page
Forums: http://cr88192.dyndns.org:8080/phpBB3
#13 Moderators - Reputation: 2959
Posted 24 February 2013 - 04:36 PM
admittedly, I am not really sure if premultiplied alpha really makes much of a difference. usually what seems to cause this sort of effect IME is the color values within the fully transparent pixels, which some graphics programs I use (such as Paint.NET) seem to automatically replace fully transparent pixels with black.
That's the point of using premultiplied alpha - the premultiplication step changes those colour values to zero and because you then use additive blending instead of interpolative blending they contribute nothing to the final image.
(The name is misleading - you premultiply the RGB based on the alpha, as well as alter the alpha itself.)
Edited by Kylotan, 24 February 2013 - 04:36 PM.
#14 Members - Reputation: 637
Posted 24 February 2013 - 06:19 PM
fair enough. I wasn't entirely sure what premultiplied alpha did exactly (when used for rendering).
admittedly, I am not really sure if premultiplied alpha really makes much of a difference. usually what seems to cause this sort of effect IME is the color values within the fully transparent pixels, which some graphics programs I use (such as Paint.NET) seem to automatically replace fully transparent pixels with black.
That's the point of using premultiplied alpha - the premultiplication step changes those colour values to zero and because you then use additive blending instead of interpolative blending they contribute nothing to the final image.
(The name is misleading - you premultiply the RGB based on the alpha, as well as alter the alpha itself.)
as-noted, where relevant, I had generally preconditioned the images.
Current Status / Downloads: http://cr88192.dyndns.org:8080/wiki/index.php/BGB_Current_Status
YouTube Channel: http://www.youtube.com/user/BGBTech
Main Page: http://cr88192.dyndns.org:8080/wiki/index.php/Main_Page
Forums: http://cr88192.dyndns.org:8080/phpBB3
#15 Moderators - Reputation: 13599
Posted 24 February 2013 - 07:05 PM
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?
The RGB value of the dark outlines in your screenshot is the same value as the background in riuthamus' picture, so are you first sure that these outlines aren't from the art file?
It will kinda-sorta-maybe-not somewhat work for glass, depending on what you're after.
It will work fine for the first layer of transparency, but if you have multiple layers of glass, then you'll only be able to see the color of the first layer.
To illustrate, if you had a glass statue, and you put a pane of red glass over some it, you'd see something like this -- Only the colour of the first layer of transparent objects can be seen, but the silhouette of the other layers can be seen by the increased opacity.

#16 Crossbones+ - Reputation: 2475
Posted 24 February 2013 - 08:57 PM
Thanks again hodge. Really you have been more than helpful.
My game project blog.






