jovchaos
jovchaos

Reputation: 31

OpenGL, C++, In Out variables

I need to pass some variables directly from vertex shader to fragment shader but my pipeline also contains a TCS a TES and A GS that simply do passthrough stuff.

I already know that fragment shader expects to recieve values for its "in" variables from the last linked shader of the program, in my case the Geometry Shader, but I don't want to do MVP and normal calculations there.

How can I output a variable directly to the fragment shader from vertex shader? (skipping the rest of the shaders in the middle)

Is that even possible?

Upvotes: 1

Views: 766

Answers (1)

Nicol Bolas
Nicol Bolas

Reputation: 474436

How can i output a variable directly to the fragment shader from vertex shader? (skipping the rest of the shaders in the middle)

You don't.

Each stage can only access values provided by the previous active stage in the pipeline. If you want to communicate from the VS to the FS, then every stage between them must shepherd those values through themselves. After all:

my pipeline also contains a TCS a TES

If you're doing tessellation, then how exactly could a VS directly communicate with an FS? The fragment shaders inputs are per-fragment values generated by doing rasterization on the primitive being rendered. But since tessellation is active, the primitives the VS is operating on don't exist anymore; only the post-tessellation primitives exist.

So if the VS's primitives are all gone, how do the tessellated primitives get values? For a vertex that didn't exist until the tessellator activated, from where would it get a vertex value to be rasterized and interpolated across the generated primitive?

The job of figuring that out is given to the TES. It will use the values output from the VS (sent through the TCS if present) and interpolate/generate them in accord with the tessellation interpolation scheme it is coded with. That is what the TES is for.

The GS is very much the same way. Geometry shaders can take one primitive and turn it into twenty. It can discard entire primitives. How could the VS possibly communicate vertex information to a fragment shader through a GS which may just drop that primitive on the floor or create 30 separate ones? Or convert triangles into lines?

So there's not even a conceptual way for the VS to provide values to the FS through other shader pipelines.

Upvotes: 3

Related Questions