【问题标题】:Varyings from all vertices in fragment shader with no interpolation. Why not?片段着色器中所有顶点的变化,没有插值。为什么不?
【发布时间】:2018-12-18 05:47:48
【问题描述】:

如果我们将变量从任何几何阶段(顶点、几何或 tess 着色器)传递到片段着色器,我们总是会丢失一些信息。基本上,我们通过两种方式释放它:

  • 通过插值:平滑、无透视或质心 - 无关紧要。如果我们在几何阶段传递了 3 个浮点数(每个顶点一个),我们将在片段阶段只得到一个混合浮点数。
  • 通过丢弃。在进行flat 插值时,硬件会丢弃除一个激发顶点之外的所有值。

为什么 OpenGL 不允许这样的功能:

顶点着色器:

// nointerp is an interpolation qualifier I would like to have
// along with smooth or flat.
nointerp out float val;

main()
{
    val = whatever;
}

片段着色器:

nointerp in float val[3];
// val[0] might contain the value from provoking vertex,
// and the rest of val[] elements contain values from vertices in winding order.

main()
{
    // some code
}

在 GLSL 330 中,如果我想要来自所有顶点的值,我需要创建整数索引 tricks 或除以片段着色器中的重心坐标。

很难在硬件中实现,还是着色器编码人员没有广泛要求?还是我不知道?

【问题讨论】:

    标签: opengl glsl language-lawyer specifications


    【解决方案1】:

    很难在硬件中实现,还是着色器编码人员没有广泛要求?

    在典型的着色算法中通常不需要它。因此,传统上,每个片段都有自动(或多或少)插值。在当前的硬件中实现可能并不太难,因为至少现代桌面 GPU 通常使用“拉模型插值”(参见Fabian Giesen's blog article),这意味着实际插值已经在着色器中完成,固定功能hw 只提供插值系数。但这被司机隐藏了。

    还是我不知道?

    嗯,在未扩展的 GL 中,目前 (GL 4.6) 没有这样的功能。但是,有两个相关的 GL 扩展:

    它基本上提供了您所要求的功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-24
      相关资源
      最近更新 更多