2011-04-25 64 views
0

我有以下GLSL頂點着色器:GLSL,添加一行使得沒有畫

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; 
} 

如果我取消對該行i_vCustomParams = a_vCustomParams;,沒有任何與這個shader渲染吸引了,沒有GL錯誤,不着色器編譯或鏈接錯誤。這令我感到驚訝,因爲幾何着色器甚至不使用i_vCustomParams,而且另外兩個頂點屬性(a_vTangenta_vBinormal)工作得很好。

我知道這是正確的,但無論如何提供的是我的頂點設置

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 
}); 

爲此頂點結構:

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

任何想法,爲什麼出現這種情況?

+0

您定位的是什麼GLSL版本?平臺和GL實施供應商? – genpfault 2011-04-25 21:12:58

回答

4

當您取消註釋該行時,頂點着色器開始認爲需要自定義屬性(因爲它的輸出取決於此屬性),因此着色器程序將此屬性視爲已使用。因此,這可能會將輸入屬性的賦值更改爲索引(如果不通過調用glBindAttribLocation強制賦值)。因此,您最終會將數據傳遞到不正確的屬性槽中,導致垃圾(或空)輸出。

解決方案: 要麼強制屬性位置之前鏈接的自動分配的位置的程序或查詢GL傳遞數據之前。

+0

這就是問題所在,我強迫他們,但我沒有意識到我必須在連接之前做到這一點。 – Hannesh 2011-04-29 15:09:09