Do varyings always have a defined value when left unassigned in GLSL 1.20?

I was reading the GLSL 1.20 spec for clarification on varying defaults and noticed that 4.3.6 states:

Reading a varying variable in a vertex shader returns undefined values if it is read before being written.

That statement seems to be limited to the vertex shader only. There is no similar clarification given for the fragment shader or other stages suggesting that reading an unassigned varying variable is legal outside of the vertex shader.

It also states the following in the same section:

Only those varying variables used (i.e. read) in the fragment shader executable must be written to by the vertex shader …

Is it correct to assume using a varying in the fragment shader that hasn’t been written to by the vertex shader is a potential compile-time error, or will it just result in undefined values?

I am able to compile without error using an Nvidia card but can’t say for other vendors.

#version 120

attribute vec4 position;

void main() {
    gl_Position = position;
#version 120

varying vec4 ignored;

void main() {
    gl_FragColor = ignored;

A varying is written by the vertex shader and read by the fragment shader. The variable will already have its value at the point that the fragment shader is invoked. A fragment shader cannot write to a varying.

There aren’t any other stages in GLSL 1.2. Geometry shaders were added in OpenGL 3.2 (GLSL 1.5).

In OpenGL 1.2, it’s unclear. In later versions:

If an output is written within non-uniform control flow, it won’t be eliminated but its value will be undefined in cases where it isn’t written.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.