I am trying to mask a 3D object using a mask 3D volume such that it only renders vertices/faces within the mask volume. This YouTube Video essentially demonstrates what I am trying to build
I think this is what you are asking for : Unity Mask 3D - YouTube
This essentially does the opposite of what you want but hopefully helps.
This shader will basically hide anything inside the object that you put it on. But if you put it on a donut shaped mesh. Tada. Exactly what you want
Shader "Custom/BufferStencil" {
SubShader {
// draw after all opaque objects (queue = 2001):
Tags { "Queue"="Geometry+1" }
Pass {
Blend Zero One // keep the image behind it
}
}
FallBack "Diffuse"
}
If you know how to write shaders then that would probably be the easiest way. Make a shader where you pass the world space position to the fragment shader (or the surface function in a surface shader), then use clip(someformula) to exclude fragments where someformula evaluates to a negative number. For example, for a sphere, you could use:
clip(radius - distance(worldPos, center))
Note that in a Surface shader, getting the world space position is trivial: you just need to declare
float3 worldPos;in the Input struct and it will be available in the surface function as IN.worldPos