Varying Variable Issue

Hey all,

I am playing around with geometry shaders on my Mac with an Nvidia 9400M graphics card, and at first everything seemed fine. But then I tried merging the new shader program with some existing code, and found that I can no longer send varying variables between the vertex and fragment shaders, only between the geometry and fragment shaders.

In a test shader with one varying float called a which is written in the vertex shader, and read in the fragment shader, I get the following error:

[quote]Validation Failed: Program is not successfully linked.

So what’s your question?

From my reading of ARB_geometry_shader4, that’s how it’s supposed to work.

Vertex -> geometry -> fragment


vertex -> fragment

Your choice. You can’t “skip over” the geometry shader if you have one enabled.

AFAIK, varying are passed from vertex to geometry, then from geometry to fragment shaders. So if you have a geometry shader, you can’t pass varyings from vertex to fragment.

Anyway, it’s hard to tell anything until you post shader sources.


Thanks for the replies, for some reason the board keeps cutting off the rest of my post, so half of it is missing.

Dark Photon, my question is, how do I pass a varying variable through from a vertex shader to a fragment shader whilst I have a geometry shader attached?

I have tried declaring the varying variable in all three shaders, but the vertex shader still claims the variable is not active, and the fragment shader will not read it.

It must be possible, otherwise I can’t use my shader for most of what it does, such as lighting, texturing, etc, as they rely on varyings between my vertex and fragment shaders.

DmitryM, they are just standard default shaders that do nothing, with an added varying variable.


I figured it out thanks to the OpenGL wiki, for some reason it decided to show up after changing my keywords in google.

For anyone else who gets stuck, here is how it works.

A variable going from a vertex shader to a geometry shader must be done like so:
Vertex Shader:
varying float a;

Geometry Shader:
varying in float a[3]; // 3 for triangles

A variable going from a geometry shader to a fragment shader is done as:
Geometry Shader:
varying out float b;

b = a[i]; // Inside of the vertices loop

Fragment Shader:
varying float b;

Thanks alot!