1

i have a problem with my GLSL shader. When i want to compile the fragment shader part, i get the following error:

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

So the problem lies around my out variable, i assume. Here is my fragment shader:

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

As i know it should be possible to output structs in OpenGL 4.0+, shouldn't it? So I dont get the error, is it a driver problem or something like that? I'm running on a Radeon HD 6950 with 13.4 drivers.

1
  • Some stages allow you to output structures, fragment shaders are not one of those stages. The outputs from a fragment shader are pretty strict - the closest you could get to what you want is to use an array of vec3; this is similar to the way the old gl_FragData [n] construct worked. Commented Sep 1, 2013 at 0:01

1 Answer 1

6

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

No, it shouldn't.

The GLSL specification is quite clear on this: vertex shader inputs and fragment shader outputs cannot be structs. From the GLSL 4.4 specification, section 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.

They also can't be aggregated into interface blocks, in case you're wondering. They must be loose variables.

Sign up to request clarification or add additional context in comments.

5 Comments

ah ok, well then I just misunderstood something. Well actually i got most of this shader from a tutorial. Why would he explain something wrong?
@C0dR: Can you link the tutorial? Perhaps it's a misinterpretation, or more likely it was a quick hackjob of a translation from an HLSL shader to GLSL.
The original tutorial used glfx, but I printed out the "translated" shaders out of glfx: ogldev.atspace.co.uk/www/tutorial35/tutorial35.html
@C0dR: First, that's not the translated shader, as evidenced by the fact that it uses a struct. Either that, or GLfx is broken. Second, why would you use an OpenGL tutorial that refuses to actually use OpenGL? What good is learning "GLfx script" rather than the actual GLSL?
It was the only good(?) tutorial i found with deferred rendering content. So might glfx be broken? i tried every public version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.