jit.gl, textures, transparency

James Harkins's icon

There is something (well, probably a lot of things) that I don't understand about alpha blending in jit.gl.*.

I read in traffic.mov and rgb2luma it to replace the original alpha. A jit.alphablend proves to me that the alpha is being calculated and processed correctly.

Then I pass the alpha-ized matrices into jit.gl.texture. jit.gl.gridshape correctly renders the RGB planes if @blend_enable is off.

I've got a green background at 0, 0, -0.1, and the texture is being applied to a jit.gl.gridshape (plane) at 0, 0, 0. What I thought would happen when I enable blending is that the green background would shine through the low alpha areas. That is, if the texture makes parts of the shape transparent, shouldn't you be able to see through that to whatever is behind?

Instead I saw a couple of different behaviors: either the gridshape simply disappears (which I'd say could be like the alpha channel is being treated as all 0, but, can't see why), or it turns gray and doesn't show the texture at all.

I tried several different blend modes but none of them do, well, transparency. I got a whole bunch of weird gray scale manipulations but nothing intuitive.

I'll admit here to not being confident in OpenGL basic concepts (I'm an audio guy, poor visual arts sense, not a graphics specialist at all), but, when I used transparent textures in Pd+Gem, I could just see right through the object as one would expect. So clearly OpenGL can do it, just not with the default settings in Max.

Max Patch
Copy patch and select New From Clipboard in Max.

TIA,

hjh

TFL's icon

The problem here appears to be @gl_color 1 1 1 which I suppose is internally converted to 1 1 1 0 which means that your alpha channel will be 0 no matter what, since your input texture color gets multiplied by gl_color. You also need to enable @blend_enable on that gridshape.

Disabling depth and setting a layer number also helps to make sure which gridshape is rendered on top of which.

Also, I recommand using texture from the beginning for more efficient processing.

Here is your patch with all of the above applied:

Max Patch
Copy patch and select New From Clipboard in Max.

Finally, if you only use plane gridshapes, you might want to use [jit.gl.videoplane] instead, or even [jit.gl.layer].

You might also prefer to use [jit.fx.co.lumakey] which directly creates an alpha channel based on the input textures brightness.

Max Patch
Copy patch and select New From Clipboard in Max.

On the example above I'm still using a gridshape for the green background instead of a jit.gl.videoplane or jit.gl.layer since those need an input texture to display something else than black.

If you just want your background to always be green you could also add @erase_color 0 1 0 1 to [jit.world] instead.