此 GLSL 代码会从“oneSixth”和“twoThirds”创建编译时常量吗?
// GLSL TESSELLATION EVALUATION SHADER
#version 410
layout (isolines, equal_spacing) in;
in vec4 tessColor[];
out vec4 pointColor;
const float oneSixth = 1. / 6.;
const float twoThirds = 2. / 3.;
void main ()
{
float s2 = gl_TessCoord.s * gl_TessCoord.s;
float s3 = s2 * gl_TessCoord.s;
float w0 = oneSixth - .5 * gl_TessCoord.s + .5 * s2 - oneSixth * s3;
float w1 = twoThirds - s2 + .5 * s3;
float w2 = oneSixth + .5 * gl_TessCoord.s + .5 * s2 - .5 * s3;
float w3 = oneSixth * s3;
gl_Position = w0 * gl_in[0].gl_Position + w1 * gl_in[1].gl_Position +
w2 * gl_in[2].gl_Position + w3 * gl_in[3].gl_Position;
pointColor = w0 * tessColor[0] + w1 * tessColor[1] +
w2 * tessColor[2] + w3 * tessColor[3];
}
我的一位同事认为这段代码效率低下,并说我应该对分区进行硬编码,否则它将在运行时发生。
const float oneSixth = .1666666667;
const float twoThirds = .6666666667;
我是 GLSL 的新手,但我怀疑这是必要的。有什么想法吗?它依赖于供应商吗?