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:


shadertoy.com
glslsandbox.com
interactiveshaderformat.com

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!

+1

1 Like

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

@rorywalsh
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.

http://glslsandbox.com/e#66058.0

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.

Dear Rory and co, thank you infinitely for the amazing framework, can’t wait to get the pro license eventually to support the platform , but yes seconding the fact that I would love to have and help add glsl shader support for cabbage all the best

I’ve recently added openGL support for drawing but it’s quite hit and miss depending on the platform. Also, Mac are moving away from openGL entirely. So wouldn’t this become somewhat redundant?

1 Like

That’s a good point, OpenGL glsl is def more open and educational thus has many users in openframeworks and processing communities, metal obviously is proprietary so will be maintaining development and is hardware specific

Bumping this! If you let me know the version of juce cabbage is built with I’ll try to see if it works

It’s built with version 6 at the moment. You might want to take a look at the CabbageImage class. That’s a barebones class that draws to a component.

@euglossine4ever If you want I can add a simple openGL window for you that can be passed shader text from Csound? Let me know. If you are really interested in this, I’m happy to do some of the leg work :slight_smile:

1 Like

i would love that! itd be sick to be able to pass in uniforms so you could make audio reactive ui components

1 Like

I have something almost working now, but I’ll need a little more time :wink:

Ok, I may need your help here. Right now I’ve add an interface to the following class in JUCE:

https://docs.juce.com/master/structOpenGLGraphicsContextCustomShader.html

But I’m wondering if this enough as I’ve tried a few different shader from shadertoy and so many give me errors that I’m start to think I’m not doing it correctly. A basic example works fine, but anything complicated causes a GL compilation error of some sort. Can you send me a basic shader so I can test?

So I’ve continued to explore this and it seems that the OpenGLGraphicsContextCustomShader class is pretty limited. While basic shaders seem to work fine, gradients, fill, shapes, etc, anything more complex is a non-runner. It looks like uniforms are not supported. And one can’t pass information to the context at all. So I think this might be the end of the road for this. People are using OpenGL use with JUCE, but it has to be implemented through various C++ classes.

1 Like

I appreciate you taking a wack at it! sorry for the delay! hope you and the fam are well