Object fading

Started by
10 comments, last by EWClay 11 years, 2 months ago

Perhapse someone out there has a way to fade an object (terrain) from opaque at the camera to transparent at max distance. I tried fog, but it only works with the color of the object-- I want some kind of alpha difference.....

Any suggestions?

Advertisement
Alpha to coverage is a simple way to get this effect. You'll need at least 4x MSAA for it to look any good, and it still wont be perfect, but it's better than popping.

Alternatively you can use alpha blending, but then you have to worry about sorting and the extra GPU cost.

Both work much like fog, but you would set the alpha value according to distance in the shader instead of colour.

I tried looking up "Alpha to coverage" but couldn't find anything that helped me understand how to use it or even what it is..... Can you explain or give me a good source to read?

if it is for something like seeing the sky through the horizon, maybe an option is drawing the sky over the top of the scene, and using the depth value and a shader? (granted, assumes a depth-texture or similar).

otherwise, an option could be trying to draw over the top as multiple translucent layers at various distances from the camera (with depth-writes disabled). then, it seems like the geometry fades into the background, but rather it is simply failing to occlude the sky.

say, the skybox has an outer opaque layer, and some number of "sky fog" layers (for example, 8-16). possibly, the nearer sky-fog layers are drawn first (to fade distant geometry), and then the sky-box is drawn (so any non-occluded parts of the scene then have a direct view of the skybox).


variations on this trick can also be used to make "fog volumes" and partially opaque-looking water as well, though this gets more complicated (may involve using the stencil buffer).

dunno if any of this helps.

Alpha to coverage is a simple way to get this effect. You'll need at least 4x MSAA for it to look any good, and it still wont be perfect, but it's better than popping.

Alternatively you can use alpha blending, but then you have to worry about sorting and the extra GPU cost

I don't understand what does that even mean. Alpha-to-coverage does a very different thing from alpha blending. For a terrain, most of the time alpha=1 so how does that fixed OP's problem?

In a shader-driven world, the only "easy" solution is to provide a way for the shader to figure out the alpha to use. Possibilities include:

  • uniform for VS, set on a per-tile basis (not recommended)
  • VS outputting a per-vertex depth value, replicated in a dedicated interpolator (easy to go). PS always taking alpha in consideration lerping against a min and max range. Problem: mandates blending is always enabled.

In both cases at least the fragment shader will need to be properly authored.

Previously "Krohm"

@Krohm You say alpha=1, then you describe setting it in the shader, exactly as I recommended in the final paragraph (which you did not quote), and I said both techniques needed that.

Alpha to coverage and alpha blending do different things, but they both use alpha and they can both give a blending effect. They are just render states so it's easy to try both ways. Alpha to coverage doesn't require sorting, that's why it's simpler.

Actually, in this case, due to it being terrain it sounds as though fading to the sky colour is perhaps the way to go.

Maybe I'm just too close minded but I still don't understand how alpha-to-coverage fits the picture.

My apologies for not quoting the full post. I would have never figured out this was going to offend you in any way. I speculate however you're cutting a lot of corners to state I wrote the same thing as you.

Previously "Krohm"

No problem, my post was short on a lot of details.

Alpha to coverage means that some proportion of pixels is not written, according to the alpha value. Alpha = 1 means all pixels, alpha = 0.5 alternate pixels, or zero no pixels. If each fragment has four pixels that gives 5 levels of transparency. Depending on the graphics card it might use a dither pattern, giving many more apparent levels.

It's usually used to smooth the edges in screen door transparency, instead of using full alpha blending. But it can also used to fade out distant objects or blend transitions between LODs.

It's also something you can just drop in, unlike alpha blending which may require completely restructuring the rendering system. That's why I suggested it. If it doesn't look good enough, fine, it doesn't cost much to try.

Then, seeing we have the same understanding, I believe we only have a different standard of quality. Because I personally believe C2A does not give adeguate quality when filling big areas.

I mean, here are a few shots from Humus C2A demo (with a modified texture).

Close-up of the screen-door effect mentioned.

[attachment=13593:closup.png]

But let's leave that alone as OP is not interested.

From distance:

[attachment=13594:far.png]

Personally I believe the pattern on the middle window is quite apparent.

Nvidia thinks it's not sufficient, but they turbocharged the concept with Stochastic Transparency.

AMD also thinks it's not sufficient: OIT using per-pixel linked lists.

Now, I understand this is worth a try. But saying that C2A could replace blend... I don't think so. It looks fairly different from blend in my opinion. Therefore, I am not suggesting anyone to try it with the intention of replacing blend, not even for the easiness of implementation.

Previously "Krohm"

No, I think we are in complete agreement. It's not a replacement for alpha blend, it's a way to smooth transitions that would otherwise be abrupt.

Now, it may be that the OP is not trying to avoid popping but actually desires a blending effect on quite large areas. In that case, the technique would not look good enough and I said that right from the start.

My best guess right now is that this is for terrain with nothing but sky behind it, in which case blending to the sky texture is the way to go.

This topic is closed to new replies.

Advertisement