ERRor:ERROR:0:161:'=':无法从'const float'转换为'highp int'

问题描述 投票:1回答:1

我是着色器的新手,我正在尝试使用《着色器之书》中的示例,目前,我对Golan Levin的Cubic Bezier函数感到困惑:

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);
}

我得到这个错误:

HREE.WebGLProgram:

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

错误:

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

有人可以帮我了解我所缺少的东西吗]

javascript glsl shader
1个回答
1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.