Previous topicNext topic

Alpha Mask shader for the GLSLShader module

Tutorials, FAQs, resources, and examples for using Magic.
Post Reply
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Alpha Mask shader for the GLSLShader module

Post 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 2253 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
damstraversaz
Posts: 176
Joined: Tue Aug 26, 2014 11:22 am

Re: Alpha Mask shader for the GLSLShader module

Post by damstraversaz »

that's really great ! thanks a lot
Terry Payman
Posts: 710
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Alpha Mask shader for the GLSLShader module

Post by Terry Payman »

Hugely helpful!

Very many thanks Eric!
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Alpha Mask shader for the GLSLShader module

Post 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 :).
Post Reply