Will this GLSL code create compile-time constants out of “oneSixth” and “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];
}
A colleague of mine thinks this code is inefficient and says I should hard-code the division or it will happen at run-time.
const float oneSixth = .1666666667;
const float twoThirds = .6666666667;
I’m new to GLSL but I’m skeptical that this is necessary. Any thoughts? Is it vendor dependent?
It will happen at compile-time. No need to hardcode trivialities like this. However, this is not mentioned in the GLSL specification.