GLSL片段着色器语法错误 [英] GLSL fragment shader syntax error

查看:115
本文介绍了GLSL片段着色器语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下简单的片段着色器代码失败,使我在日志中没有提供任何信息: ERROR: 0:1: 'gl_Color' : syntax error syntax error

the following simple fragment shader code fails, leaving me with an uninformative message in the log: ERROR: 0:1: 'gl_Color' : syntax error syntax error

void main()
{
  vec4 myOutputColor(gl_Color);
  gl_FragColor = myOutputColor;
}

以下一项有效:

void main()
{
  glFragColor = gl_Color;
}

这令人困惑,例如 Lighthouse3D的教程 gl_Color是据说是vec4.为什么不能将其分配给另一个vec4?

This boggles my mind, as in Lighthouse3D's tutorial gl_Color is said to be a vec4. Why can't I assign it to another vec4?

推荐答案

尝试正常分配.像这样:

Try normal assignment. Like this:

void main()
{
  vec4 myOutputColor = gl_Color;
  gl_FragColor = myOutputColor;
}

第二个答案确实一样正确,但是不需要使用vec4()构造函数,因为两者的类型相同.如果让我们说一个(r,g,b,w)元组,则可以编写:

The second answer is just as correct really, but there isn't any need to use the vec4() constructor, since both are of the same type. If you had lets say a (r,g,b,w) tuple you could write:

vec4 myOutputColor = vec4(r, g, b, w);

// assuming myRgbColor is a vec3
vec4 myOutputColor = vec4(myRgbColor, w);

这篇关于GLSL片段着色器语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆