简体   繁体   English

GLSL片段着色器语法错误

[英]GLSL fragment shader 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 以下简单片段着色器代码失败,在日志中留下了一条无信息的消息: ERROR: 0:1: 'gl_Color' : syntax error syntax error

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

while the following one works: 而以下一个有效:

void main()
{
  glFragColor = gl_Color;
}

This boggles my mind, as in Lighthouse3D's tutorial gl_Color is said to be a vec4. 这令人难以置信,就像在Lighthouse3D的教程中一样, gl_Color被认为是一个vec4。 Why can't I assign it to another vec4? 为什么我不能将它分配给另一个vec4?

Try normal assignment. 尝试正常分配。 Like this: 像这样:

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

Edit: 编辑:

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. 第二个答案实际上是正确的,但是没有必要使用vec4()构造函数,因为两者的类型相同。 If you had lets say a (r,g,b,w) tuple you could write: 如果你曾经说过(r,g,b,w)元组你可以写:

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

or 要么

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

etc 等等

Aparrently you should use slightly different syntax 一般来说,你应该使用稍微不同的语法

(see OpenGL Shading Language Specification ) (参见OpenGL着色语言规范

vec4 myOutputColor = vec4(gl_Color);
gl_FragColor = myOutputColor;

this unlike your sample compiles fine on my mashine (Windows, Nvidia card) 这不同于你的样本编译我的mashine(Windows,Nvidia卡)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM