Unity Intersections Mask

[亡魂溺海] 提交于 2020-01-03 16:48:08

问题


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:

  1. First pass renders a depth map for opaque objects in the scene
  2. 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:

  1. Render the plane as opaque geometry
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!