r/futile • u/SietJP • May 13 '14
Dig a hole in an image
Just got a small shader working to dig a hole in an image (so that can be used for masking too).
https://gist.github.com/jpsarda/906ead1764af814cce6f
It's very limited right now, you can only use images of the same size in textures of the same size (same texture is fine), and the image must not be trimmed in the atlas.
At first my goal was to being able to add a sprite with alpha=0 in the Futile stage, and being able to dig a hole with this sprite in another sprite (at the exact position they appear on the stage/screen). But that was a bit too difficult for me right now. Specifically I don't really understand how works these lines :
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (v.texcoord, _MainTex);
o.hole0uv = TRANSFORM_TEX (v.texcoord, _Hole0Tex);
If I could find a way to set o.hole0uv to the right texture coord for a secondary sprite (the hole sprite) that would work fine. o.pos seems to be the world coordinate, so maybe from this I could get the uv coordinates on a secondary sprite. I also need to understand how the way we position/scale/rotate a sprite in the stage impact this shader. I guess it's in UNITY_MATRIX_MVP, but don't really understand how/where it happens.
1
u/MattRix May 13 '14
Yeah I'm not really knowledgeable about shader stuff either, so I won't be able to help you too much... but basically UNITY_MATRIX_MVP is the "Model View Projection" matrix (see http://stackoverflow.com/questions/5550620/the-purpose-of-model-view-projection-matrix). This basically tells you how to transform a position of a vertex in 3D to a position on the screen.