Convert shadertoy shader to OF .frag and .vert shaders


I’m trying to display this shader in my OF project by using ofShader.

It displays only a white rectangle instead of the rounded rectangle with nice drop shadow.
How can i convert this shadertoy shader to an ofShader readable shader (splitting it in a .vert and .frag files)

In setup():

In draw() :
shader.setUniform1f(“cornerRadius”, cornerRadius);
shader.setUniform1f(“blurRadius”, blurRadius);
shader.setUniform2f(“hsize”, size);

ofVec2f center(x2, y2 - pos.y);
shader.setUniform2f(“center”, center);

shader.setUniform3f(“background”, backgroundColor);
shader.setUniform3f(“foreground”, foregroundColor);

ofDrawRectangle(x, y, bounds.x, bounds.y);

I have this in my VS2022 output :

[ error ] ofShader: checkProgramLinkStatus(): program failed to link
[ error ] ofShader: ofShader: program reports:
Fragment info
(0) : error C3001: no program defined
(0) : error C3001: no program defined
(0) : error C3001: no program defined
(0) : error C3001: no program defined

Thanks a lot !

Found the solution by adding at the end of the shader :

void main(void)

1 Like

if you have the files in the data folder it should just be:

you might also need to change:

float cornerRadius = 32.0;
float blurRadius = 32.0f;


uniform float cornerRadius;
uniform float blurRadius;

in the shader.

mainImage should also be main:

void main() {

I think you would get the fragcoord with:
vec2 fragcoord = gl_FragCoord;

and then your out color would be
gl_FragColor = finalColor;


void main() {
vec2 fragcoord = gl_FragCoord;

//shader toy code 

gl_FragColor = finalColor;

And you need to specify iResolution.xy I think ( see the shader inputs section at the top )))
1 Like

FYI: there is also ofxShadertoy: GitHub - tiagosr/ofxShadertoy: Addon for openFrameworks that sets up and loads Shadertoy ( shaders

This can give you some hints about porting shadertoy shaders.