繁体   English   中英

错误:0:147:“xFromT”:找不到匹配的重载函数

[英]ERROR: 0:147: 'xFromT' : no matching overloaded function found

我是着色器的新手,我正在尝试使用 The Book of Shaders 上的示例进行实验,我目前坚持使用 Golan Levin 的 Cubic Bezier 函数:

float plotLine(vec2 uv, float y) {
  return smoothstep(y - 0.02, y, uv.y) - smoothstep(y, y + 0.02, uv.y);
}

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;

  // Solve for t given x (using Newton-Raphelson), then solve for y given t.
  // Assume for the first guess that t = x.
  float currentt = x;
  int nRefinementIterations = 5;
  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,1);
  }

  float y = yFromT (currentt,  E,F,G,H);
  return y;
}

// Helper functions:
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;
}

void main() {
  vec2 uv = gl_FragCoord.xy / u_resolution;

    float y = circularEaseIn(uv.x);

    vec3 gradient = vec3(y);

    float line = plotLine(uv, y);

    vec3 color = (1.0 - line) * gradient + line * lineColor;

    gl_FragColor = vec4(color, 1.0);
}

我犯了这个错误:

HREE.WebGL 程序:

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

错误:

0:147:'xFromT':找不到匹配的重载函数

有人可以帮助我了解我缺少什么吗?

请参阅OpenGL ES 着色语言 1.00 规范 - 6.1 函数定义

所有函数在被调用之前必须用原型声明或用函数体定义。


在代码中使用该函数之前,必须先声明该函数。 您必须在yFromT之前移动函数xFromTcubicBezier

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 cubicBezier (float x, float a, float b, float c, float d){
    // [...]
    for (int i=0; i < nRefinementIterations; i++){
        float currentx = xFromT (currentt, A,B,C,D);
        // [...]
    }

    float y = yFromT (currentt,  E,F,G,H);
    // [...]
}

另一种选择是声明函数原型xFromTyFromTcubicBezier

float xFromT (float t, float A, float B, float C, float D);
float yFromT (float t, float E, float F, float G, float H);

float cubicBezier (float x, float a, float b, float c, float d){
    // [...]
    for (int i=0; i < nRefinementIterations; i++){
        float currentx = xFromT (currentt, A,B,C,D);
        // [...]
    }

    float y = yFromT (currentt,  E,F,G,H);
    // [...]
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM