Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Object fading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 10 February 2013 - 09:04 AM

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?



Sponsor:

#2 EWClay   Members   -  Reputation: 659

Like
2Likes
Like

Posted 10 February 2013 - 09:40 AM

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.

#3 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 11 February 2013 - 12:30 AM

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?



#4 BGB   Crossbones+   -  Reputation: 1554

Like
1Likes
Like

Posted 11 February 2013 - 01:50 AM

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.

#5 Krohm   Crossbones+   -  Reputation: 3245

Like
1Likes
Like

Posted 11 February 2013 - 02:22 AM

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.



#6 EWClay   Members   -  Reputation: 659

Like
1Likes
Like

Posted 11 February 2013 - 04:46 AM

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

#7 Krohm   Crossbones+   -  Reputation: 3245

Like
1Likes
Like

Posted 11 February 2013 - 09:46 AM

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.



#8 EWClay   Members   -  Reputation: 659

Like
1Likes
Like

Posted 11 February 2013 - 10:33 AM

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.

#9 Krohm   Crossbones+   -  Reputation: 3245

Like
1Likes
Like

Posted 11 February 2013 - 01:03 PM

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.

closup.png

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

From distance:

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.


Edited by Krohm, 11 February 2013 - 01:04 PM.


#10 EWClay   Members   -  Reputation: 659

Like
1Likes
Like

Posted 11 February 2013 - 01:45 PM

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.

#11 Hawkblood   Members   -  Reputation: 725

Like
0Likes
Like

Posted 13 February 2013 - 08:24 AM

The "blend" (or whatever it is called) is for transition between terrain and a "skirt" terrain below it.



#12 EWClay   Members   -  Reputation: 659

Like
0Likes
Like

Posted 13 February 2013 - 10:34 AM

Then I would

1. Output a suitable alpha value from the shader. Whatever calculation you use for fog should do, just change the alpha instead.

2. Turn on alpha blending and see how it looks.

3. If you get sorting errors, swap alpha blend for alpha to coverage. See how it looks.

4. If the dithering is obvious, you will have to work out a sorting strategy and switch back to alpha blend.

And maybe post some screenshots. It's hard to visualise the scene without them.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS