错误:错误: 0:161: '=' : 无法从 'const float' 转换为 'highp int'



我是着色器的新手,我正在尝试使用着色器之书中出现的示例,我目前坚持使用 Golan Levin 的立方贝塞尔函数:

const vec3 lineColor = vec3(0.0, 1.0, 0.0);
float slopeFromT (float t, float A, float B, float C){
float dtdx = 1.0/(3.0*A*t*t + 2.0*B*t + C);
return dtdx;
}
float xFromT (float t, float A, float B, float C, float D){
float x = A*(t*t*t) + B*(t*t) + C*t + D;
return x;
}
float yFromT (float t, float E, float F, float G, float H){
float y = E*(t*t*t) + F*(t*t) + G*t + H;
return y;
}
float plotLine(vec2 uv, float y) {
return smoothstep(y - 0.02, y, uv.y) - smoothstep(y, y + 0.02, uv.y);
}
float constrain(float y, float a, float b);
float cubicBezier (float x, float a, float b, float c, float d){
float y0a = 0.00; // initial y
float x0a = 0.00; // initial x
float y1a = b;    // 1st influence y
float x1a = a;    // 1st influence x
float y2a = d;    // 2nd influence y
float x2a = c;    // 2nd influence x
float y3a = 1.00; // final y
float x3a = 1.00; // final x
float A =   x3a - 3.0*x2a + 3.0*x1a - x0a;
float B = 3.0*x2a - 6.0*x1a + 3.0*x0a;
float C = 3.0*x1a - 3.0*x0a;
float D =   x0a;
float E =   y3a - 3.0*y2a + 3.0*y1a - y0a;
float F = 3.0*y2a - 6.0*y1a + 3.0*y0a;
float G = 3.0*y1a - 3.0*y0a;
float H =   y0a;
float currentt = x;
int nRefinementIterations = 100.0;
for (int i=0; i < nRefinementIterations; i++){
float currentx = xFromT (currentt, A,B,C,D);
float currentslope = slopeFromT (currentt, A,B,C);
currentt -= (currentx - x)*(currentslope);
currentt = constrain(currentt, 0.0, 1.0);
}
float y = yFromT (currentt,  E,F,G,H);
return y;
}
void main() {
vec2 uv = gl_FragCoord.xy / u_resolution;
float y = cubicBezier(uv.x, 0.500, 0.100, 0.340, 0.873);
vec3 gradient = vec3(y);
float line = plotLine(uv, y);
vec3 color = (1.0 - line) * gradient + line * lineColor;
gl_FragColor = vec4(color, 1.0);
}

我得到这个错误:

哗啦啦。WebGLProgram:

着色器错误: 0 35715 false gl.getProgramInfoLog 当至少附加了一个图形着色器时,没有编译的片段着色器。

错误:

错误: 0:161: '=' : 无法从 'const float' 转换为 'highp int'

有人可以帮我了解我错过了什么吗?

在 GLSL ES 1.00 中,浮点值不会自动转换为整数值。

100.0是浮点值,但nRefinementIterations的数据类型为int。您必须通过整数值初始化nRefinementIterations

int nRefinementIterations = 100.0;

int nRefinementIterations = 100;

请注意,整数值也可以由浮点值构造:

int nRefinementIterations = int(100.0);

最新更新