Board index FlightGear Development Scenery

Rembrandt and alpha / transparency. Any better solution?

Questions and discussion about enhancing and populating the FlightGear world.

Rembrandt and alpha / transparency. Any better solution?

Postby bigstones » Tue Apr 15, 2014 12:36 pm

As you might have read here I'm noob and I'm converting a scenery from FS. I want to make it Rembrandt-compliant and I'm having problems with alpha. I might have found a nice solution actually, but if there's anything better, I'd like to know. I'm also posting the whole experience as a reference for future noobs. Please let me know if anything is wrong.

The problem is that textures that have transparent (alpha) parts are rendered with a black border on the boundaries between alpha and non-alpha parts. This is due to Rembrandt knowing only 100% and 0% alpha, where anything between becomes 100%. Even if the alpha part is sharp in the texture, it seems to get stretched and partial alpha borders show up anyway. It looks bad expecially from far, because the black gets predominant in some structures.
Image Image

I downloaded LOWI and I've seen that its gratings at the airport boundaries are affected by this problem, only they're using a white border and from far the net looks like a white wall.

As pointed out by Gijs in the LIPY thread, I tried disabling the Rembrandt rendering with the model-transparent effect. Sadly, besides losing the shadows, it also shows up some problems with the order of drawings. I've read about fixing the order of objects by hand in the .ac, but frankly I'll avoid that if possible. Note that all the textures are alpha in this model.
Image
Image

From far, though, it actually looks better than Rembrandt, because there's no black borders predominance.
Image

Things turn out bad also when disabling Rembrandt: the model with model-transparent effect now has the alpha drawing order problem, while the other without effect now has transparency where in Rembrandt was the black border. That means that from far it's transparency that gets predominant!!! (note: this one happens only from certain angles, but when it does it's ugly!)
The fix to adding/removing model-transparent effect should be enabling/disabling it based on conditions (i.e. is Rembrandt enabled?)
Image

The second issue, that is the excess of transparency, can be fixed with alpha testing. Note: I'm not totally sure, but I think that this alpha test thing is ignored when in Rembrandt, so it can't be used to fix the black borders.
Image

Note how an alpha test between 0.5 and 0.99 would look fine. Yet losing the shadows is a bad hit. So searching again I've found in a thread about trees that the fact that the borders are black isn't causal, but because also 100% alpha has a color. In my case, it was black indeed. I changed it to match the main color of the structure and here are the results. Definitely better!
Image


Now, to sum it up:
- Rembrandt: adjust the color of alpha based on surroundings.
- non-Rembrandt: use alpha test.

Is this all I can do?
My concern is that gratings, with the Rembrandt solution, will just look like grey walls instead of black walls from far. Do I have to make the mesh larger? Increase the resolution? What do I do?

(a side question: when registering transparent objects I need to pass the names of real objects. If many objects have the same name, will they all get the effect?)
bigstones
 
Posts: 95
Joined: Sat Apr 05, 2014 11:09 pm
Location: Italy
Callsign: I-NOOB
OS: Debian testing

Re: Rembrandt and alpha / transparency. Any better solution?

Postby ludomotico » Tue Apr 15, 2014 2:53 pm

Thank you very much for a post like this! I preferred to not use transparent textures because of the issues you noticed, but you did your research and you have fixed all of them!

Thank you for this post!
User avatar
ludomotico
 
Posts: 1018
Joined: Tue Apr 24, 2012 1:01 pm
Version: git
OS: Debian GNU/Linux

Re: Rembrandt and alpha / transparency. Any better solution?

Postby Thorsten » Tue Apr 15, 2014 5:31 pm

The basic problem here is mipmapping - even if your original texture has only pixels with alpha=0 and alpha=1, once the texture gets mipmapped and pixels averaged out, you get pixels with intermediate alpha values which also inherit the color which originally was 'below' the alpha=0. Which is what you are seeing.

I believe the proper solution is really not to automatically mipmap such textures, but to create the lower resolution levels manually such that all pixels would again have either alpha=0 or alpha=1 in each of the lower levels. However, within FG to my knowledge that is only possible if you use dds textures, which are problematic for people with OpenSource graphics drivers. I think it would also be possible to not use mipmapping at all (which would make rendering unreasonably slow) but I have to check this.

The methods you have discovered are rather damage containment (which work reasonably well though). The color should be adjusted in any case, and alpha test works as it enforces a threshold behaviour from below. A possible solution could be to enforce a threshold inside the shader both from above and from below (i.e. to write a dedicated effect).

In the case of the gratings, I believe the alpha to coverage technique which we also use for trees if multisampling (antialiasing) is enabled would improve the appearance - not sure if that is available for Rembrandt (alpha to coverage interprets an alpha value pixel by pixel as either full or zero and just adjusts the relative fraction of full and zero to the alpha value).

Transparent stuff in general might have to be pushed into the right render bin to avoid wrong depth ordering - it doesn't come automatically since one can't use depth buffering for transparent textures. We have the same issue with clouds, and they need to go to a depth-sorted bin and are rendered outside-in.

All in all, rendering things like the tower support structure based on a semi-texture invites some trouble (pretty much all transparency does need some extra love, it's never easy to render), and explicitly modeling it might be easier...
Thorsten
 
Posts: 11106
Joined: Mon Nov 02, 2009 8:33 am

Re: Rembrandt and alpha / transparency. Any better solution?

Postby bigstones » Wed Apr 16, 2014 10:18 am

@Thorsten: well, I've been told that converting a scenery wouldn't be the click of a button.

@ludomotico: if I was the only one to benefit from this "research" (as much as with the scenery conversion) I wouldn't consider it worth the hassle. So, glad it was!
bigstones
 
Posts: 95
Joined: Sat Apr 05, 2014 11:09 pm
Location: Italy
Callsign: I-NOOB
OS: Debian testing


Return to Scenery

Who is online

Users browsing this forum: No registered users and 3 guests