Color Alpha - error?

Started by Corris, October 24, 2017, 09:11:49 am

Previous topic - Next topic



I have a question about tgAlpha.exr recieved in Render Layers.

We try to use it as "standard" alpha channel for composing Planet with Atmosphere over different backgrounds.
But terragen gives us color alpha layer, that is confusing.

We use Node: Enviro light, Ambient Occlusion to lighten scene. Creating sort of ambient texture with transparent atmosphere.

I can imagine we may use this color alpha to recieve unpremultiplied RGB in 32 bit.
But strange thing is that if you render same planet with different light - Alpha will be different as well.
Not much difference, but it is. (Difference Intencity -9 stops  (in 32 bit). Low light was 0.1, High light was 2.5)
Or this is just an small error in calculations?

I thought Alpha usualy mean Opacity level, so it should not depend of RGB color.
For example, if I have nebulae background seen through atmosphere I will see same % of nebula color no matter of atmosphere color or it's lightning.

If Terragen use it's Alpha for composing layers, is there a way we can get "standard" opacity alpha?

Or may you explain please why Alpha is Colored?
And how to use it correctly?

In fact we need 8 bit format after all.
Currently we make it greyscale. Not sure is it correct or not?


The way render layers is set up, is that you should multiply alpha and then add the other passes on top in a linear light composition. The alpha channel, should be multiplied over the base image, then the alpha'd subjects colours are then added into the new dark spaces from the other passes. The reason it is like this is to allow for coloured transparencies, ie stained glass.

Your work around, converting the alpha to greyscale and probably using levels to flatten out the white and black will cause some fringing, halos around the edges, which you'll have to use a matte choke to bring back in.


October 26, 2017, 11:31:31 am #2 Last Edit: October 26, 2017, 11:47:00 am by Matt
There is a way to composite the atmosphere over a background, but not with a greyscale alpha. Rayleigh scattering causes the opacity to be different at different wavelengths, and this means the opacity is different in each of the R, G and B channels. Greyscale alpha assumes that the opacity is the same in each channel, which is not true.

For example, when the moon is low in the sky it looks yellow or sometimes red. This is because the atmosphere is more opaque at the blue end of the spectrum and therefore allows less blue light to reach your eye. If you try to achieve this with a greyscale alpha the moon would be grey, unless you tint the moon image beforehand. The same is true of stars, of course, but the effect is harder to notice. While it might sound OK for the moon to remain grey behind the atmosphere, it ends up looking too blue when the blue atmosphere is added on top, so the yellow tint is important.

What we need is "chromatic alpha", where the alpha for each channel is allowed to be different. Unfortunately most software doesn't support this concept natively, but we can output an RGB image of the opacity of the atmosphere and there is a way to use it. This is the tgAtmoAlpha element. The same is true of the tgAlpha element which includes surfaces and clouds as well as atmosphere.

The way to composite an atmosphere over a background is as follows:

1) Multiply the background by the inverse of the atmosphere alpha
2) Add the atmosphere RGB (which is already premultiplied)

This is exactly the same math as a normal alpha composite (where the foreground is premultiplied), except the alpha is different for each channel so you can't do this with RGBA images.

Ideally this should be done in a linear colour space, and with 16-bit or 32-bit images. If you do this you should be able to get almost exactly the same result as rendering the background behind the atmosphere in Terragen. If you really have to use 8-bit images in an sRGB colour space it might still look OK, but I guess you might need to adjust the saturation of the alpha in some cases to get closer to a realistic result. You'd have to experiment to see what works best.

You said there were some differences in the alpha when you changed the lighting conditions. This shouldn't really happen, but very small differences might occur due to rounding errors because some calculations take place in the renderer to extract the alpha from the results of the volumetric integrator. Do you think these differences will cause a problem?

Just because milk is white doesn't mean that clouds are made of milk.


However, if none of this is feasible and you need to use a greyscale alpha, I'd suggest trying the R channel of the alpha image. Be aware that it'll give different results and you might want to adjust how you paint your backgrounds (e.g. tinting yellow-orange towards the horizon) so that they look how you want them to after the planet atmosphere has been comp'ed over the top.

Just because milk is white doesn't mean that clouds are made of milk.


Wow, thank you very much for all out answer!

Now I see - Colored Alpha is deeper than we thought :).
We can use 8 bit per channel RGB alpha. Should be ok now. Will use whole RGB now.
"Chromatic Alpha" - good to know!
Thing that Photoshop does not support in it's masks. Using multiple layers compositions to replace it.

One more thing we use for our purpose with Alpha. Maybe someone will find it usefull:
We need smooth edge "atmo-space". It is ok in 32 bit per channel, but not smooth enough in 8 bit.
So we found solution:

Swap your Photoshop to Linear workspace (necessarily!)    (It works correctly if you doing it in Linear workspace only!)
32 bit per channel EXR Alpha (with Gamma 1.0 default) -> apply Gamma 2.2 (in Linear space) (Merge layers)
Convert to 8 bit per channel.
Save to RGB Alpha (TGA for example).

Then in our shaders reverse operation, 8 bit per channel Gamma 2.2 -> Gamma 1.0 (float), and then per channel operations in linear space.
We loose some details in opaque parts but have much smoother transparent parts.

About difference in Alpha with different light:
I don't think small difference in alpha couse any problem.

Thanks again!


Thanks for replying, and also for the 8-bit remapping trick for your realtime shaders. I can see how that would be useful.
Just because milk is white doesn't mean that clouds are made of milk.