Unity3D 中的几何发射着色器

Geometry Emission Shader in Unity3D

我正在尝试创建一个从网格的每个顶点发出四边形的 cg 着色器。我知道我正在考虑制作几何着色器,但找不到任何与 Unity 配合良好的几何添加着色器的文档或示例 - 大多数只修改顶点子着色器中的现有顶点。

对于网格上的每个顶点,我实质上是在创建一个粒子系统,该粒子系统由在网格上每个现有顶点处创建的四边形组成。

提前感谢您提供任何指导或资源!

old answer of mine elsewhere 为基础,您需要以下内容:

  • #pragma geometry geom
  • [maxvertexcount(N)]
    void geom(triangle v2g IN[3], inout TriangleStream<g2f> triStream)
  • 以及将输入顶点转换为输出顶点的一些代码。

请注意,上面的示例一次包含完整的三角形,尽管 there are other types. Second thing to note is the N in the annotation, that is you telling the GPU how many verticies you're sending back. In my case, I was sending 12 (4 for each edge in the original triangle), in your case you can use GL_POINTS and take in a single vertex and output 4 as a quad (so N would be 4 for you). See also the MSDN 文章介绍了如何为其他输入声明 geom 函数。