I need to make a see through hole on a 2D texture using a custom shader.
Defined variables are:
r (hole radius)
x,y (hole position, either by float or vector2)
slope (not necessary, but a useful feature to set a alpha slope for our hole)
The way it should work is when a user wants to see through a building in a 2D game, he simply moves his mouse above it and then we change input variables via simple script command (renderer.material.SetFloat( “_Radius”, radius);, etc) we make that texture see-through, like the example below:
The building and grass are two separate orth 2d textures.
Is there a way of doing it without using Alpha test or anything expensive like that? (iOS project)
Whether it’s expensive depends on how many pixels you’re blending. You haven’t specified what orientation your world is in, so the properties here are in UV space. You could do it in world space, in 3D, as a generic solution, but I think it might be faster to only deal with two dimensions.
@Jessy’s got a good shader there, just thought I’d pitch a different option.
Why not just render a cylinder with the DepthMask shader though - that would do it if you could live without the edge fading and is very easy to position at the mouse point, especially if overlapping two different textures.