Cutting a hole in a mesh with alpha map.

I am trying to use an alpha map to cut a hole in a surface. And this cut hole needs to move across the surface.

My original hope was to put this onto a projector, so then I could just point the projector at something and instead of making a shadow, it would make a circle on the mesh that you see through.

Is this at all possible to do? I looked and as far as I could tell that was impossible, the projector could only add colors, not change the alpha map on the maintex of the shader it was being projected on.

My second hope was to implement this as an additional channel on the shader that was to have a hole cut in it. So you would attach a ‘cuthole’ map, a black and white circle, and then I would position this cuthole map by changing the uv coordinates it uses. But this too seemed impossible as the function in shaderlab which actually makes the pixels transparent is the ‘Blend SrcAlpha One’ line and that takes the alpha channel from the main texture, and I see no way to have it take the alpha from both the main texture and the ‘cuthole’ texture.

So is there anyway to do that?

Or is there another way to cut a hole in a mesh?

I do know about the depthMask functionality via the queue tag and do have this working. But I want the edges of the cutaway to fade. Which is why I want to figure a way to do it via an alpha map.

It might help to make sure it’s clear how projectors work:

  1. The projector first collects all meshes that intersect its projection frustum.
  2. Then each object’s mesh is rendered with the projector’s material, using projector space UV coordinates instead of whatever UV mapping the mesh has.

This means that every mesh is drawn again when a projector hits it, so the projector material can only communicate with the mesh’s standard material in the ways that other materials can communicate. The Z buffer is one of those ways, but as you’ve seen it will produce hard edges.

Another method to consider would be to render everything but the mesh you want to cut, then use the projector to render the hole, but only into the alpha channel, and finally to render your mesh with a blending function that used DstAlpha to determine its opacity. This would mean you couldn’t use the screen buffer’s alpha channel for anything else, such as overbright for the glow shader (which is what it is used for by default).

The easiest solution if you don’t want your hole to be projected in a complicated way would be to use a shader with a separate alpha texture for blending. Then you could adjust the tiling factor of the alpha texture at runtime in order to move the hole. This will only work if you can make a unique and continuous UV mapping for the area you want the hole to move along, which might be in a secondary UV map if you are repeating the base texture.

Give the .unitypackage on the bottom a try. It uses one of the methods Daniel mentioned.

http://forum.unity3d.com/viewtopic.php?p=237905

Awesome. Thank you.

Is it possible to get that projector to effect a transparent bumped specular shader? My attempts at combing it with other things are failing. Just putting a simple

UsePass “Transparent/Diffuse/BASE”

after the blend is making it so that every object through the whole renders as the diffuse color… which is an interesting in and of itself

And what exactly do these OneMinus blend commands do? I’ve read the documentation over and over so many times but I just can’t grasp what exactly is it doing or why certain combination of these commands are resulting in certain results.

The Blend command and its arguments map directly to OpenGL’s blending function. I recommend reading the beginning of Chapter 7 of the OpenGL red book. It explains the factors quite well.

You can’t use UsePass because you need to change the blending mode on each pass to use the destination alpha, but if you copy each pass out of the original shader code (available at the top of the forum here) you should be able to do it just by adding the right Blend command to each pass.