openglgeometry-shader

Is it possible to share a variable between iterations of a geometry shader?


Overview

I am generating a graph segments whose functions I know. What I want to do is add another function to this graph of tall bars of known area and height. The problem is that these bars can bleed from one segment to the next.

Implementation

I have a geometry shader that operates on a linestrip (let's call its vertices x1, x2, …) and generates a linestrip of greater resolution (y11, y12, y13…, y21, y22, y23, …) where yij corresponds to the span xi x{i+1}.

At each xi, I provide the height of the block to add, and the geometry shader knows then that the corresponding y11, y12, … need to be taller.

Unfortunately, sometimes, the block at yi bleeds into y{i+1}. Now, what I'd like to do is while processing span i, write into some variable how much bleeds, and then when I'm processing the i+1th span, examine that variable.

Is there such a mechanism in OpenGL's geometry shaders? It seems to me that it might be processing the spans sequentially, but I'm not sure. If it is, then there should be a way to pass values from one span to the next.

Alternatively, is there a way to do a kind of merging (in the way that merge sort merges sorted lists) whereby I merge two sorted lists of vertices by some function. I've never heard of such a thing, but it's something that OpenGL could theoretically do it seems.


Solution

  • No, you cannot.

    With the exception of certain very specific circumstances, all shader invocations for a particular stage execute in an unspecified order (or have no ordering with other invocations at all). They cannot talk to one another; they cannot declare variables that the others can see, and so forth (again, outside of certain very specific circumstances. None of which is available to a GS).