开发者

GLSL, adding a single line makes nothing draw

I have the following GLSL vertex shader:

attribute vec3 开发者_运维百科a_vTangent;
attribute vec3 a_vBinormal;
attribute vec2 a_vCustomParams;

varying vec3 i_vTangent;
varying vec3 i_vBinormal;
varying vec4 i_vColor;
varying vec2 i_vCustomParams;

void main()
{   
   i_vTangent = a_vTangent;
   i_vBinormal = a_vBinormal;
   i_vColor = gl_Color;
   //i_vCustomParams = a_vCustomParams;

   gl_Position = gl_Vertex;
}

If I uncomment the line i_vCustomParams = a_vCustomParams;, none of anything rendered with this shader draws anymore, no GL errors, no shader compile or link errors. This surprises me, as the geometry shader doesn't even use i_vCustomParams yet, and furthermore, the other two vertex attributes (a_vTangent and a_vBinormal) work perfectly fine.

I know it's correct, but provided anyway is my vertex setup

layout = new VertexLayout(new VertexElement[]
{
    new VertexPosition(VertexPointerType.Short, 3),
    new VertexAttribute(VertexAttribPointerType.UnsignedByte, 2, 3), //2 elements, location 3
    new VertexColor(ColorPointerType.UnsignedByte, 4),
    new VertexAttribute(VertexAttribPointerType.Byte, 4, 1), //4 elements location 1
    new VertexAttribute(VertexAttribPointerType.Byte, 4, 2), //4 elements, location 2
});

for this vertex struct:

struct CubeVertex : IVertex
{
    public ushort3 Position;
    public byte2 Custom;
    public byte4 Color;
    public sbyte4 Tangent;
    public sbyte4 Binormal;
}

Any ideas why this happens?


When you uncomment the line your vertex shader starts to think the custom attribute is needed (because it's output depends on this attribute) and hence the shader program considers this attribute as used. This, in consequence, may change the assignments of the the input attributes to indices (if you are not forcing it by calling glBindAttribLocation). So you finish up with passing your data into incorrect attribute slots, resulting in a trashy (or empty) output.

Solution: Either force the attribute locations before linking the program or query GL for the auto-assigned locations before passing your data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜