Shaders Cut hole in layer with shader

JeffJ

Member
I have two layers - layer A on top of layer B. I want to cut a hole through layer A on certain areas to see through to layer B.

I have already done this by placing a distinctly colored sprite/object where I want the cutout(s), draw the layer to a surface, and then apply a shader that removes all pixels with that distinct color.


However, I would like to achieve the same effect without using a surface. What I'm thinking is a shader that works sort of like a magic wand, that will select my distinct area(s) and then remove everything within that area but only on that layer.

But I'm not even completely sure if this can be done with shaders? And if so, any idea where to start?
 

JeffJ

Member
Got a working example but only in GMS2 (I don't have GMS 1 isntalled anymore). I recall you working on GMS 1.4 the last time. If that's still true, I'll post the code here.

This will create circular holes only but you can chnage the math within the shader if you want something different.

https://www.dropbox.com/s/r198dzs6w14ihe8/Jeff_punch_hole_in_layers.yyz?dl=0
Thank you so much! This is great!

Two things though -

1: How would I adapt the area to be based on a sprite rather than a mathematically defined shape?

2: Preferably I would be able to position spritebased objects where I wanted specific holes to be, but with the current architecture, it seems I'd need a unique start and end instance for every hole?

I actually do remember seeing that post before. I will have a closer look at it. Thanks!
 
1: How would I adapt the area to be based on a sprite rather than a mathematically defined shape?
Then you'd just use YellowAftrLife's post. He has both approaches there and I'm nowhere near his genious to find anything easier or better :)
 
Top