Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is writing to `gl_Position` in Vertex Shader necessary when there is a Geometry Shader

Tags:

opengl

glsl

Suppose I have a geometry shader that computes its output gl_Position from some inputs other than gl_in[].gl_Position. If the previous pipelines stages (vertex and tessellation) do not write to their out gl_Position, does the action of the entire pipeline still remain well-defined?

Or put it other way, does the value of gl_Position has any effect on the functioning of the GL before the completion of the Geometry shader? If not, it would mean I can simply use it as an extra slot for passing data without any special spatial interpretation between stages, right?

(The question assumes OpenGL 4.5 forward profile.)

like image 931
Yakov Galka Avatar asked Oct 30 '22 09:10

Yakov Galka


1 Answers

gl_Position only needs to be written by the final Vertex Processing stage (VS, tessellation, and GS) in the rendering pipeline. So if you have an active GS, the VS that connects to it need not write to gl_Position at all. Or it can put any arbitrary vec4 data in it.

Do note that gl_Position does still need to be written by whatever the final vertex processing stage is. Assuming you want rasterization, of course. And no, that's not being flippant; you could be doing transform feedback.

If not, it would mean I can simply use it as an extra slot for passing data without any special spatial interpretation between stages, right?

If there's a GS, then none of the outputs from the previous shader stages will have "any special spatial interpretation". gl_Position isn't special in this regard.

Interpolation is a function of the Rasterizer, which happens after vertex processing. Indeed, in GLSL 4.30+, the interpolation qualifiers on the fragment shader inputs are the only ones that matter. They're not even used for interface matching anymore.

like image 70
Nicol Bolas Avatar answered Nov 02 '22 11:11

Nicol Bolas