2
此GLSL代碼是否會在「oneSixth」和「twoThirds」之外創建編譯時常量?glsl編譯時除法const
// 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的新手,但我很懷疑這是必要的。有什麼想法嗎?它依賴於供應商嗎?
http://www.opengl.org/wiki/Type_Qualifier_(GLSL)#Constant_qualifier – tauran