Cabbage Logo
Back to Cabbage Site

GLSL shader node

In the past couple years I have become quite proficient in GLSL shader programming for cross platform GPU realtime imagery. If you are unfamiliar with what I am talking about check out:

I am wondering what would be required for me to add a widget that allows loading GLSL shader code to be executed on the GPU. Part of the beauty here is that they require extremely minimal (next to 0) CPU resources and can generate complex and interesting imagery on any half way recent computing device.

The way this could work is as follows:
widget name could be GLSL
bounds would send the uniform vec2 resolution for the X and Y resolution
this would create an openGL rectangle with a quad or two triangles making up a quad with the fragment shader applied
uniform mouse vec2 for the mouse down x and y coordinates
uniform iMouse vec4 for the shadertoy style mouse :

A really great reference is the JUCE GLSL shader editor demo file that comes with JUCE, and I can supply a couple others. I have one that is a VST opensource of a GLSL shader editor.

These are great for audio reactive visualizers, custom spectrograms, and unique custom widgets of all sorts… any shape can be drawn with a minimum of code and updated 60fps on any semi recent GPU… and with ray marching and higher end hardware photorealistic 3D can even be created… its pretty fun

Can you point me to that JUCE demo? What’s the actual demo name?

OpenGLDemo2D, in the list under the projucer>File>Open Example>GUI>OpenGLDemo2D

It shouldn’t be too tricky to do this if it’s already available in JUCE :wink: But I won’t have time to look into it for a few weeks at the earliest. Feel free to bump this in a month or so if you don’t hear back from me!


It would be pretty simple if one only wants to generate some graphics, but any kind of interaction with the shader would not be trivial at all. Which makes me wonder if it’s worth it?

I’m just going to ping @MacroMachines too to see what they think about it…

1 Like

Heya, sorry I never saw the message until now. It is actually potentially quite trivial to add interaction in the shader, all you do is pass in a uniform of the XY and mouse click state, you can reference how they do it in shadertoy. (their site seems to be down at the moment though, but Ill find one example how they do it when its back up). for now I made an example in glslsandbox.

You can note the mouse uniform in there, its just the mouse position in this one, but in shadertoy you have the current mouse position, the click down state, I think also the position where it was clicked, and the position where it was released. That’s really all you need for doing everything from drag interactions to drawing etc. If we also have access to that information inside cabbage which I think we do if I am not mistaken, we could form some interactivity.