2012-05-03 63 views
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的新手,但我很怀疑这是必要的。有什么想法吗?它依赖于供应商吗?

+0

http://www.opengl.org/wiki/Type_Qualifier_(GLSL)#Constant_qualifier – tauran

回答

2

它会在编译时发生。不需要像这样硬编码琐碎。但是,这在GLSL规范中没有提及。

1

如果有疑问,测量,但我会考虑任何在编译时没有做到这一点的实现中断。