Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Persistent data in a shader – GLSL

Is it possible to have persistent data within the same shader? Something like a uniform, except that the shader itself can set it.

What I’m trying to do is embed a vertex in my vertex stream that will act as a "state change" and affect an operation on all vertices downstream. I.E. the vertex shader says "ah, I hit this vertex" and turns a boolean on or off… and later vertices can check that boolean. It doesn’t need to work between shaders, it just needs to work during a single pump of vertices.

Is this possible? Using GLSL.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

embed a vertex in my vertex stream that will act as a "state change" and affect an operation on all vertices downstream.

That’s not possible. Invocations of a particular shader stage execute in a largely undefined order with respect to other invocations within that stage (and drawing command). Regardless of the ability to read or write memory, you cannot ensure that "downstream" invocations will not have been executed before the "upstream" invocations wrote to that memory.

If you want to do something like that, you will need to put them into separate drawing commands as well as issue appropriate memory barriers (to make such writes visible to later commands ) between such draws.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading