统一交叉口罩 [英] Unity Intersections Mask

查看:151
本文介绍了统一交叉口罩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方法可以检测具有一定数量顶点的对象是否撞到了平面?如果是这样,我想以二进制(黑/白)形式将其绘制到平面上或使用它创建纹理.

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:

干杯,迈克尔

推荐答案

大多数游戏将使用专门的着色​​器来实现:

Most games will achieve this with specialized shaders:

  1. 第一遍渲染场景中不透明物体的深度图
  2. 第二遍使用交集着色器用于透明对象
  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. 将平面渲染为不透明几何
  2. 使用相交着色器渲染其他对象
    • 绘制与平面相交的片段
    • 没有 与平面相交的片段将被丢弃
  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.

这篇关于统一交叉口罩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆