【发布时间】:2014-09-09 02:36:04
【问题描述】:
我有一个顶点着色器,我正在尝试使用顶点着色器来渲染内容。当我使用普通的 vec3“in”属性时,我让它工作了,但现在我需要传递某些信息。我制作了一个结构体,将用于顶点着色器、几何着色器和计算着色器。
struct StellarEntity
{
vec3 position;
vec3 velocity;
double mass;
double radius;
};
这是我的顶点着色器(当然结构在里面):
#version 430
uniform mat4 projectionMatrix;
uniform mat4 viewMatrix;
uniform mat4 modelMatrix;
layout(location = 0) in StellarEntity in_entity;
void main()
{
gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4(in_entity.position, 1.0);
}
我认为问题可能是我绑定顶点属性的方式。
vao = new VAO();
//"entities" is a StellarEntity[256] with all data initialized
vao.BufferData(BufferTarget.ArrayBuffer, entities, BufferUsageHint.StaticDraw);
vao.VertexAttribPointer(0, 3, VertexAttribPointerType.Double, false, 0, 0);
vao.VertexAttribPointer(0, 3, VertexAttribPointerType.Double, false, 0, 0);
vao.VertexAttribPointer(0, 1, VertexAttribPointerType.Double, false, 0, 0);
vao.VertexAttribPointer(0, 1, VertexAttribPointerType.Double, false, 0, 0);
stride 和 offset(VertexAttribPointer 的最后两个参数)我不是很懂,所以我把它们放在了 0...
编辑:忘了打我的 BindAttributeLocation 电话,所以在这里:
//"program" being my shaderprogram, after the linking (worked fine for simple shaders)
program.BindAttribLocation(0, "in_entity");
【问题讨论】:
标签: c# opengl glsl buffer shader