从没有插值的片段着色器中的所有顶点变化。为什么不?

Varyings from all vertices in fragment shader with no interpolation. Why not?

如果我们将任何几何阶段(顶点、几何或苔丝着色器)的变化传递给片段着色器,我们总是会丢失一些信息。基本上,我们通过两种方式松开它:

为什么 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 或除以重心坐标。

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

Is it hard to implement in hardware, or is it not widely requested by shader coders?

典型的着色算法通常不需要它。所以传统上,每个片段都有自动(或多或少)的插值。在当前的硬件中实现可能不太难,因为至少现代桌面 GPU 通常使用 "pull-model interpolation"(参见 Fabian Giesen's blog article),这意味着实际插值已经在着色器中完成,fixed-function hw 只是提供插值系数。但是 driver 对您隐藏了这一点。

Or am I not aware of it?

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

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