Mgraphics to texture with transparency

Anthony Palomba's icon

Hey folks,

I am doing some experiments with drawing mgraphics sketches to a texture. I would like to display these on a texture transparently on a background, but I can not seem to set the transparency of the texture. Setting the blendcolor on the texture does not seem to set anything. Is there something I am missing? Some alpha channel setting I am not seeing?

MgraphicsToTexture.maxpat
Max Patch

ToJitter.js
js 1.97 KB

yaniki's icon

[mgraphics] itself works fine with transparency (and textures). Simple example here:

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

Anthony Palomba's icon

Your example does not seem to demonstrate any transparency. Is there something I am supposed to set?

yaniki's icon

You can't see the transparency. It's transparent.

Previous example uses [mgraphics] to create image with transparent background and white rect on the center.

And here another example - I've added second rectangle. This one is semitransparent.

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

Anthony Palomba's icon

Ahhh okay, I see it now. Thanks I will study this.

yaniki's icon

Anthony

I think, most important elements are on gl side, not in mgraphics (however clear_surface message is very useful). So, setting @blend_enable and @blend attributes is a key to success.

Anthony Palomba's icon

Yes I agree, ideally I would like to set this on the texture and have it rendered as transparent. I see there is a blend_enable and blend_mode on the gridshape I am using. I have updated my patch, please refer to previous .js file. I am using the default blend_mode, but still do not seem to be getting any transparency.

Actually I realize now that there are two things I am asking here.
1. How do you make the whole source image transparent?
2. How do you make a select color transparent? (In this case black)

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

yaniki's icon

Anthony

I messed with your project a bit (and I removed some parts, but should be rather easy to rebuild it), so you have to clear things by yourself, but I think this is the solution.

clear_surface(); (inside your script) and all the attributes related to depth and blend (inside the patch) are most important.

trans.zip
zip 3.36 KB

Anthony Palomba's icon

Awesome, that's it! I see you used a videoplane in the end, I tested it with a gridshape plane and it works as well.

Thanks!