“平坦" GLSL预选赛? [英] "flat" qualifier in glsl?

查看:78
本文介绍了“平坦" GLSL预选赛?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在阅读"OpenGL官方指南"时,在他们讲授材质照明的部分中,他们突然使用"flat"限定符作为片段着色器中的输入变量. 我用谷歌搜索了这个问题,然后我想到的只是平面阴影"和平滑阴影"以及它们之间的区别,我无法理解它们与简单的"MatIndex"变量之间的关系. 这是本书中的示例代码:

So I was reading "The Official OpenGL Guide" and in a section where they taught material lighting, they suddenly used the "flat" qualifier for an input variable in the fragment shader. I google'd the matter and all I came up with was "flat shading" and "smooth shading" and the differences between them, which I cannot understand how it is related to a simple "MatIndex" variable. here's the example code from the book:

struct MaterialProperties {
vec3 emission;
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shininess;
};
// a set of materials to select between, per shader invocation
const int NumMaterials = 14;
uniform MaterialProperties Material[NumMaterials];
flat in int MatIndex; // input material index from vertex shader

这是怎么回事?

推荐答案

在一般情况下,顶点和片段之间没有1:1的映射.默认情况下,在整个图元上插值每个顶点的关联数据,以生成每个片段的相应关联数据,这就是 smooth 阴影所做的.

In the general case, there is not a 1:1 mapping between a vertex and a fragment. By default, the associated data per vertex is interpolated across the primitive to generate the corresponding associated data per fragment, which is what smooth shading does.

使用flat关键字,不会进行任何插值,因此在对该特定图元进行栅格化期间生成的每个片段都将获得相同的数据.由于基元通常由一个以上的顶点定义,因此这意味着在这种情况下仅使用来自一个顶点的数据.在OpenGL中,这称为 引发顶点 .

Using the flat keyword, no interpolation is done, so every fragment generated during the rasterization of that particular primitive will get the same data. Since primitives are usually defined by more than one vertex, this means that the data from only one vertex is used in that case. This is called the provoking vertex in OpenGL.

还要注意,整数类型永远不会插值.在任何情况下,您必须将它们声明为flat.

Also note that integer types are never interpolated. You must declare them as flat in any case.

在您的特定示例中,代码意味着每个图元只能具有一种材质,该材质由每个图元的激发顶点的材质ID定义.

In your specific example, the code means that each primitive can only have one material, which is defined by the material ID of the provoking vertex of each primitive.

这篇关于“平坦" GLSL预选赛?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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