Transparent voxels

Started by
14 comments, last by riuthamus 11 years, 1 month ago

Thanks Hodgman

Advertisement

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?

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.

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.

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.)


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.)


fair enough. I wasn't entirely sure what premultiplied alpha did exactly (when used for rendering).

as-noted, where relevant, I had generally preconditioned the images.

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.

RxTKaXO.png

Thanks again hodge. Really you have been more than helpful.

This topic is closed to new replies.

Advertisement