簡體   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