- Home /
Masking a 3D Object using a 3D Volume
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
https://www.youtube.com/watch?time_continue=59&v=0rE4MwLK1eE
Answer by Sundharss · Aug 24, 2020 at 10:59 AM
I think this is what you are asking for : https://youtu.be/7vFwTt4isDY
Answer by RocketFriday · Sep 15, 2018 at 04:28 AM
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 :P
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"
}
Answer by BastianUrbach · Sep 15, 2018 at 05:34 AM
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
Your answer
Follow this Question
Related Questions
Stencil and mask shader not working when building on Windows Desktop. 0 Answers
Obscuring / not rendering parts of an object on camera 2 Answers
Masking part of an object via raycasts 1 Answer
How to make effect between scenes with UI Mask or Shader 0 Answers
eraser effect in plane using shader 1 Answer