我使用TouchDesigner的GLSL。我想尝试让颜色像alpha一样透明,但他会出现太多参数给XXX的构造函数
void main()
{
vec2 r = vUV.st;
vec3 backgroundColor = vec3(1.0,0,0,0);
vec3 axesColor = vec3(0.0, 0.0, 1.0);
vec3 gridColor = vec3(0.5);
// start by setting the background color. If pixel's value
// is not overwritten later, this color will be displayed.
vec3 pixel = backgroundColor;
// Draw the grid lines
// we used "const" because loop variables can only be manipulated
// by constant expressions.
const float tickWidth = 0.1;
for(float i=0.0; i<1.0; i+=tickWidth) {
// "i" is the line coordinate.
if(abs(r.x - i)<0.002) pixel = gridColor;
if(abs(r.y - i)<0.002) pixel = gridColor;
}
// Draw the axes
if( abs(r.x)<0.005 ) pixel = axesColor;
if( abs(r.y)<0.006 ) pixel = axesColor;
fragColor = TDOutputSwizzle(vec4(pixel, 1.0));
}发布于 2020-02-11 13:42:11
问题是这条线
vec3 backgroundColor = vec3(1.0,0,0,0);
您已经向vec3的构造函数传递了4个参数。Vector constructor采用向量存储的值的数量。
传递3个单点浮点值来解决这个问题:
vec3 backgroundColor = vec3(1.0, 0.0, 0.0);alpha通道是第四个分量。如果要添加alpha通道,则必须使用vec4而不是vec3
void main()
{
vec2 r = vUV.st;
vec4 backgroundColor = vec4(1.0, 0.0, 0.0, 0.0); // red: 1, green: 0, blue: 0, alpha: 0
vec4 axesColor = vec3(0.0, 0.0, 1.0, 1.0); // red: 0, green: 0, blue: 1, alpha: 1
vec4 gridColor = vec3(0.5, 0.0, 0.0, 1.0); // red: 0.5, green: 0, blue: 0, alpha: 1
// start by setting the background color. If pixel's value
// is not overwritten later, this color will be displayed.
vec4 pixel = backgroundColor;
// Draw the grid lines
// we used "const" because loop variables can only be manipulated
// by constant expressions.
const float tickWidth = 0.1;
for(float i=0.0; i<1.0; i+=tickWidth) {
// "i" is the line coordinate.
if (abs(r.x - i) < 0.002 || abs(r.y - i) < 0.002)
pixel = gridColor;
}
// Draw the axes
if (abs(r.x) < 0.005 || abs(r.y) < 0.006)
pixel = axesColor;
fragColor = TDOutputSwizzle(pixel);
}https://stackoverflow.com/questions/60162454
复制相似问题