I recently introduced geometry shader, but it didn’t work out well. I have trouble passing variables through vertex shader to geometry shader and vertex shader to fragment shader.
If I want to pass a variable through pipeline, do I have to pass it from vertex shader to geometry shader and then down to fragment shader? can I pass it from vertex shader directly to fragment shader?
What if I want to create a variable in geometry shader and pass it to fragment shader?
Can anyone explain this to me? Thank you very much!
can I pass it from vertex shader directly to fragment shader
No - think of the geometry shader as a consumer of the vertex or tesselation data and an exporter of data to the fragment shader. It does not have to export any of the date from the vertex shader if you don’t want to and it can create its own data to send to the fragment shader
All of a geometry shader’s output variables are created in the geometry shader.
Often, the values of the output variables are copied directly from elements of the input variables (which are always arrays whose size depends upon the input primitive type, e.g. 2 for lines, 3 for triangles, etc), but there’s nothing special about this case.