The alpha value [0, 1] passed to my GLSL TOP does not seem to work as expected. Even if I pass zero in “uAlpha” I just see an opaque white rectangle, and can see a bit transparency when adjusting the color value. (A test toe file attached.)
I am using macOS Catalina (10.15.4) and TouchDesigner 2020.22080.
Its working perfectly, if you use a toptochop Chop you see the alpha value changed.
The problem is TD doesn’t premultiply the alpha channel, so if you need a variation of the color, you must use: vec4 color = vec4(uAlpha);
A general rule for transparency is that the values in RGB should always be lower than the value in Alpha. So if you calculate a new alpha for a color, you can multiply the RGB by the alpha to get them in this legal range.
Now it works like a charm!
So this is so called ‘straight alpha’ isn’t it? I’m quite new to shading language, and curious if straight alpha is standard. I have written a few shaders for openFrameworks but alpha was premultiplied I believe.
I dont know for oFw but, for me, straight alpha is the normal way to do because in TD (as in some other software as Fusion), you can completely separate alpha and RGB, as for using glsl Top to drive instances of geometry. The question is how alpha is used after it and if you have the choice between straight or premult. If you prefer not to change your shader, you can use it like premultiplied using Matte Top, with matte channel on alpha (default)
What you created was straight alpha. What TouchDesigner assumes is that content will be premultiplied alpha. You can see other nodes create premultipled alpha by default, such as the Constant TOP or the Phong MAT