【发布时间】:2016-03-15 15:46:17
【问题描述】:
简而言之
在单个着色器通道中,我在顶点着色器中应用了几个不同的模型转换矩阵,并将结果写入不同的位置向量。 然后我对顶点着色器中的不同结果进行一些简单的算术运算。
//Vertex Shader
in layout(location=0) vec3 position;
in layout(location=1) vec3 vertexColor;
...
out vec3 result1;
out vec3 result2;
out vec3 result3;
out vec3 color;
void main()
{
gl_Position = transformationMatrix * vec4(position, 1.0);
vec4 pos1 = transformationMatrix1 * vec4(position, 1.0);
vec4 pos2 = transformationMatrix2 * vec4(position, 1.0);
...
result1 = pos1.xyz * pos2.xyz / 0.012313879834;
result2 = (pos2.xyz + pos1.xyz) * 1.5;
result3 = ....;
color = vertexColor;
}
我想通过片段着色器传递的数学结果(因此值被很好地插值,就像颜色一样)......
// Fragment shader
in vec3 color;
in vec3 result1;
in vec3 result2;
in vec3 result3;
layout(location = 0) out vec4 theColor;
layout(location = 1) out vec3 output1;
layout(location = 2) out vec3 output2;
layout(location = 3) out vec3 output3;
void main()
{
theColor = vec4(color, 1.0);
output1 = result1;
output2 = result2;
}
...最终将它们读回,以便我可以继续处理 CPU 上的数据。我需要读取的数据准确(浮点数 32)并且最好不要标准化为 [0, 1]。
关于这个我有几个问题:
- 最初我认为可以使用 GL_COLOR_ATTACHMENTi 来促进这一点,但我无法弄清楚如何。是否可以?如果是这样,我将如何处理?
- 自 OpenGL 4.2 以来使用图像加载/存储功能的解决方案会是什么样子?我需要注意哪些潜在的陷阱?
编辑:毕竟我让它与颜色附件一起工作。请参阅下文了解适合我的解决方案。
【问题讨论】:
标签: opengl