首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TouchDesigner的构造函数的参数太多

TouchDesigner的构造函数的参数太多
EN

Stack Overflow用户
提问于 2020-02-11 13:20:32
回答 1查看 69关注 0票数 1

我使用TouchDesigner的GLSL。我想尝试让颜色像alpha一样透明,但他会出现太多参数给XXX的构造函数

代码语言:javascript
复制
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)); 
}
EN

回答 1

Stack Overflow用户

发布于 2020-02-11 13:42:11

问题是这条线

vec3 backgroundColor = vec3(1.0,0,0,0);

您已经向vec3的构造函数传递了4个参数。Vector constructor采用向量存储的值的数量。

传递3个单点浮点值来解决这个问题:

代码语言:javascript
复制
vec3 backgroundColor = vec3(1.0, 0.0, 0.0);

alpha通道是第四个分量。如果要添加alpha通道,则必须使用vec4而不是vec3

代码语言:javascript
复制
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); 
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60162454

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档