2013-08-31 130 views
0

我的GLSL着色器出現問題。 當我想編譯片段着色器的一部分,我得到以下錯誤:GLSL片段着色器結構輸出

0:24: error(#181) Cannot be used with a structure: out 
error(#273) 1 compilation errors. No code generated 

所以,問題在於在我出去的變量,我承擔。 這裏是我的片段着色器:

#version 410 

uniform mat4 gWVP; 
uniform mat4 gWorld; 

uniform sampler2D gColorMap;     

in VSOutput 
{ 
    vec3 WorldSpacePos; 
    vec2 TexCoord; 
    vec3 Normal; 
} FSin; 


struct FSOutput 
{     
    vec3 WorldSpacePos;  
    vec3 Diffuse;  
    vec3 Normal;  
    vec3 TexCoord; 
}; 

out FSOutput FSOut; 

void main() 
{           
    FSOut.WorldSpacePos = FSin.WorldSpacePos;     
    FSOut.Diffuse  = texture(gColorMap, FSin.TexCoord).xyz; 
    FSOut.Normal  = normalize(FSin.Normal);      
    FSOut.TexCoord  = vec3(FSin.TexCoord, 0.0);    
} 

據我所知,應該可以輸出結構在OpenGL 4.0及以上版本,不應該嗎?所以我沒有得到錯誤,這是一個驅動程序問題或類似的東西? 我正在用13.4驅動程序在Radeon HD 6950上運行。

+0

有些階段允許您輸出結構,片段着色器不是這些階段之一。來自片段着色器的輸出非常嚴格 - 最接近你想要的就是使用vec3數組;這與舊的'gl_FragData [n]'結構的工作方式類似。 –

回答

4

As i know it should be possible to output structs in OpenGL 4.0+, shouldn't it?

不,不應該。

GLSL規範很明顯:頂點着色器輸入和片段着色器輸出不能是結構。從GLSL 4.4規範,第4.3.6:

Fragment outputs can only be float, single-precision floating-point vectors, signed or unsigned integers or integer vectors, or arrays of any these. It is a compile-time error to declare any double-precision type, matrix, or structure as an output.

他們也不能聚合成interface blocks,如果你想知道。它們必須是鬆散的變量。

+0

啊好的,那麼我只是誤解了一些東西。實際上,我從教程中獲得了大部分的着色器。他爲什麼要解釋一些錯誤? – C0dR

+1

@ C0dR:你可以鏈接教程嗎?也許這是一種誤解,或者更可能是從HLSL着色器到GLSL的翻譯的快速hackjob。 –

+0

原始教程使用glfx,但是我用glfx打印出「已翻譯」着色器: http://ogldev.atspace.co.uk/www/tutorial35/tutorial35.html – C0dR