问题
Is there any way to detect if an object with a certain amount of vertices hits a plane? If so, I want to draw it in binary (black/white) onto the plane or create a texture with it.
And I also don't care about if this can only be created with raycasts or some tricky physics operations / shaders / etc.. I'm just wondering what mathematical algorithm could create this.
Here is an example of what I'm trying to achieve:
Cheers, Michael
回答1:
Most games will achieve this with specialized shaders:
- First pass renders a depth map for opaque objects in the scene
- Second pass uses an intersection shader for transparent object(s)
The intersection shader looks for fragments where depth is equal (or nearly equal) to the depth from the first pass, then colors those fragments differently.
A question on the Game Development Stack Exchange goes into more detail, including screenshots and a WebGL demo.
In your case, this might look like:
- Render the plane as opaque geometry
- Render the other objects using intersection shader
- Fragments that intersect the plane are drawn
- Fragments that do not intersect the plane are discarded
Whether you are doing this for an entire scene, or just to generate a texture that you can apply to some other object, the shader principles remain the same either way.
来源:https://stackoverflow.com/questions/42278279/unity-intersections-mask