Showing posts with label alpha to coverage. Show all posts
Showing posts with label alpha to coverage. Show all posts

Sunday, 2 November 2008

Expensive state changes

Everytime you want a primitive to be multi-sampled - in order to convert its alpha values into coverage patterns - you are supposed to explicitly ask for it by enabling GL_SAMPLE_ALPHA_TO_COVERAGE.

I thought that keeping this feature enabled for non-translucent primitives was a waste. I was wrong! It's continuosly changing this state that cuts down performances!

Therefore, you're going to prefer to let alpha2coverage enabled whereas supported, and enjoy the terrific boost of performances.

Thursday, 16 October 2008

Covert alpha operations

The screenshot on the left shows my shadow mapping engine rendering two translucent textured surfaces. The first one occludes the spotlight and casts a shadow on the second one which, in turn, casts on the floor and the wall.

Through the eye of the needle

The thumbnail looks fine, but a closer look (click it!) reveils many subtle aliasing problems. Fact is that the "alpha to coverage" is just a workaround to achieve a nice effect (transparency) without adding too much complexity (sorting/splicing/etc). Its trick consists in converting the alpha informations into coverage micropatterns. When the surface is analyzed badly - eg.: shadow map generation from big distance - "non-covert" subfragments reveal themselves. This issue can be partially solved by linear filtering the shadow map, but could also create an awful moiré effect.


Images from the other side

Finally, there remains the open issue of correctly projecting the colors when lights runs through translucent surfaces. The solution I'm trying to develop is the following:
  • render the scene without translucent objects
  • take the depth map of this partial scene (this will block projection beyond dull surfaces)
  • do render anything stays above (using the depth map for depth comparison)
  • take the color map of this scene and blend it over the shadow map
Thoretically it's a working algorythm, but there are surely plenty of complex cases that I'm ignoring.

Wednesday, 15 October 2008

Order indipendency

Translucency and transparency are not trivial in realtime CG.

Peaceful ray tracers take their time to throw lines inside and outside objects, while rasterizers have no peace quickly collecting incoming fragments. In order to alpha blend them, they must arrive in a precise order: the farthest, the earliest.

This limitation has a deep impact when rendering a scene: you have to sort your objects in order to obtain a correct blending. Moreover, there are pathological cases which cannot be solved by using standard techniques (such as object1 covered by object2 covered by object3, which is covered by object1 again).

I googled a bit and found out that several different solutions has been offered to obtain the "order indipendent transparency", but just two are really cool and do not make use of external shaders: depth peeling and multisampled alpha coverage. The first one is brilliant: subdivide the scene by peeling away closest depths, and blending everything at the end. Naturally, many renders are required and performances fall.

The second one is less sophisticated, but interesting. It uses the additional samples taken by multisampling (for anti-aliasing and similar) and use the alpha information to create a coverage mask of these samples.


The final composition is stunning, but a correct irradiance on the shadowed object is still missing.