我有以下顶点着色器:
#version 330
layout (location = 0) in ivec4 inOHLC;
layout (location = 1) in int inVolume;
layout (location = 2) in int inTimestamp;
out ivec4 outOHLC;
out int outVolume;
out int outTimestamp;
void main()
{
outOHLC = inOHLC;
outVolume= inVolume;
outTimestamp = inTimestamp;
}
我想在几何着色器中接收outOHLC
、outVolume
和outTimestamp
。我这样写:
#version 330
in ivec4 inOHLC;
in int inVolume;
in int inTimestamp;
layout (line_strip, max_vertices = 2) out;
void main() {
float x = (float)inTimestamp / 100.0;
float y1 = (float)inOHLC[1] / 100.0;
float y2 = (float)inOHLC[1] / 100.0;
gl_Position = vec4(x, y1, 0.0, 0.0);
EmitVertex();
gl_Position = vec4(x, y2, 0.0, 0.0);
EmitVertex();
EndPrimitive();
}
但我得到以下错误:
run:
. . . vertex compilation success.
. . . geometry compilation failed.
Shader Info Log:
ERROR: 7:1: 'inOHLC' : geometry shader input varying variable must be declared as an array
ERROR: 8:1: 'inVolume' : geometry shader input varying variable must be declared as an array
ERROR: 9:1: 'inTimestamp' : geometry shader input varying variable must be declared as an array
ERROR: 15:1: ')' : syntax error syntax error
在@Rabbid76评论之后,我修改了代码如下:
#version 330
in ivec4 ohlc[];
in int volume[];
in int timestamp[];
layout (line_strip, max_vertices = 2) out;
void main()
{
float x = (float)timestamp / 100.0;
float y1 = (float)ohlc[1] / 100.0;
float y2 = (float)ohlc[2] / 100.0;
gl_Position = vec4(x, y1, 0.0, 0.0);
EmitVertex();
gl_Position = vec4(x, y2, 0.0, 0.0);
EmitVertex();
EndPrimitive();
}
现在我只得到一个错误:
run:
. . . vertex compilation success.
. . . geometry compilation failed.
Shader Info Log:
ERROR: 40:1: ')' : syntax error syntax error
我猜这与(float)
转换有关(GLSL中是否存在这种转换?)或float变量定义。
1条答案
按热度按时间z4iuyo4d1#
仔细阅读留言:
几何着色器输入可变变量必须声明为数组
Geometry shader的输入是基元。这意味着构成图元的顶点着色器的所有输出都是合成的。因此,几何体着色器的输入是数组:
此外,您必须指定几何着色器的输入图元类型。例如,对于一条线:
基元类型
lines
意味着几何着色器接收2个顶点(输入的数组大小为2)。GLSL没有像C那样的强制转换运算符。如果要将
int
转换为float
,则必须构造一个新的float
。重载的float
构造函数接受int
参数:float y1 = (float)ohlc[1] / 100.0;
索引从0开始,而不是从1开始(如C,C++,C#,Java,JavaScript,Python等):