GLSL - swappable shaders

cybero's picture

I don't know if this is feasible, but I was wondering if it could ever be possible to 'hot swap' shaders on the fly?

What I mean is, create a composition, using a GLSL shader , then , either by means of a Boolean switch or some other Conditional switch , switch between different shaders.

Currently the only way close to this that I can envisage to achieve this is to have more than one GLSL patch and conditionally enabling / disabling shader patches.

That's surely down to the way that the GLSL Programming patch runs the GLSL code it contains and has no input for an alternate GLSL code stream.

Possibly a plugin [I don't mean that plugin to be containing the shaders to be switched between, but to allow shader listings to be loaded on the fly]?

vade's picture
Re: GLSL - swappable shaders

This ought to be 100% possible and doable. You'd have to (unfortunately, I think) use the "skank" SDK to make a "macro" like patch though.

OpenGL fully supports this, and, in fact, it is the 'correct' way of doing things, rather than loading resources more than once, just swap the active program.

cwright's picture
Re: GLSL - swappable shaders

Yep, vade's completely correct. Shaders should be properties of objects, much like colors or textures (e.g., they should be inputs, not environments). alas...

cybero's picture
Re: GLSL - swappable shaders

Thank you both @vade & @cwright for your clarifications and confirmations regarding how to achieve this within QC.