javascript - 错误:0:147:'xFromT':找不到匹配的重载函数
问题描述
我是着色器的新手,我正在尝试使用 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 函数定义:
所有函数都必须在调用之前使用原型声明或使用主体定义。
在代码中使用该函数之前,必须先声明该函数。您必须移动功能xFromT
和yFromT
之前cubicBezier
:
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);
// [...]
}
另一种选择是为xFromT
和yFromT
之前声明函数原型cubicBezier
:
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;
}
推荐阅读
- java - Groovy CliBuilder - 包含空格的参数值
- laravel - 如何在 yajra 数据表中重新初始化 Html Builder - laravel 控制器
- linq - select语句中的linq减法
- openapi - OpenAPI 3 是否允许重复的参数名称但在不同的位置(路径/查询/标题)?
- django - 在 Linux 服务器上找不到 ffmpeg 或 avconv
- node.js - cURL 到带有 multipart/form-data 的 NodeJS 请求
- c# - 如何使用 selenium c#/ Specflow 自动化天蓝色广告身份验证或 MFA
- javascript - 针对特定时刻格式的 Jest 单元测试
- asp.net - 从 aspx 网页打开或下载 excel 文件失败:它没有在应用程序中打开
- python - 如何在具有不同 value_counts 的列中获取缺失值