Page 1 of 1

Alpha Mask shader for the GLSLShader module

Posted: Mon Sep 15, 2014 10:23 pm
by Magic
EDIT: In Magic 1.6, the Alpha Mask is now included in the main installation (via the Mask module). I've left this tutorial here just in case anyone's curious or wants more information.
---

Magic 1.5's GLSLShader module introduces some powerful new functionality that makes it really easy to achieve cool effects.

Here's a new Alpha Mask shader I wrote pretty quickly:

Code: Select all

void main()
{
    vec2 pixelLocation = gl_FragCoord.xy / iResolution.xy;

    gl_FragColor = texture2D(iChannel0, pixelLocation) * texture2D(iChannel1, pixelLocation);
}
To explain it a little bit, basically what I'm doing is multiplying the color in the first image by the color in the second image. Even if you're not a programmer, you can see that not a lot of code is required.

To use this shader in your own projects, click here to download it:
AlphaMask.txt
(176 Bytes) Downloaded 2278 times
Then just load it into the GLSLShader module, as shown here:
Image

The two inputs to the GLSLShader module (the Image module and the Video module) are multiplied together, resulting in the alpha mask effect. (I put the Starfield in the background just so you can see where the video has become transparent.)

Note that circle.png and shortCars.avi are both in the Magic sample projects folder, so you should be able to duplicate the scene exactly. Or, try it out with different inputs to the GLSLShader module and I'm sure you'll have a lot of fun playing around with it.

Any questions, please let me know! :)
Eric

Re: Alpha Mask shader for the GLSLShader module

Posted: Tue Sep 16, 2014 7:28 am
by damstraversaz
that's really great ! thanks a lot

Re: Alpha Mask shader for the GLSLShader module

Posted: Tue Sep 16, 2014 7:47 pm
by Terry Payman
Hugely helpful!

Very many thanks Eric!

Re: Alpha Mask shader for the GLSLShader module

Posted: Fri Dec 05, 2014 4:54 am
by Magic
Since I think this is a pretty useful shader, I've attached it as a text file to my initial post, for quick downloading :).