GLSL Code Snippet Question

Hi all,

I’ve just started using GLSL and I wanted to ask about using code snippets. I’ve been following along with Davide Santini’s TD Intro to GLSL and it’s been great, but I can’t get my code snippets to work. Here is my code snippet (it’s a .json and a .frag). Merely using a GLSL TOP to try to work this out.

Thank you!

glsl2

NAME is a function you need to call, and pass 4 arguments
NAME(cx, cy, sx, sy). Just referring it via vec3(NAME) will give a compile error. If you use an Info DAT you can see the compile errors for the shader to see what’s wrong.

1 Like

Got it to work! Question, will I have to have the entire code like as shown in my picture below? I can’t just say “float rect = centRect(cx, cy, sx, sy)?” It’s not a problem, just want to make sure. Thanks for clarifying!

Well you need values for cx cy sx and sy, so it depends what you want those values to be driven from.

I mean do say that can I just call the code on like 23 for example, or will I always have to have the full function script housed in my mine script in order to use it. My understanding is that you’re using code snippets to not have to do this, however if I comment it out, the centRect function on line 23 doesn’t work.

The function centRect will always need to be defined somewhere where your shader code knows about it. If you want to use the same functions in multiple GLSL shaders you can use #include directives to include code from a common DAT into multiple other DATs that need access to that function