Pass string to GLSL top as pixel shader

I have a glsl pixel shader string that I am building with a text DAT which is set to Python as the language.

I’m trying to pass this shader to a GLSL top.

I’ve tried using the expression “mod(‘text1’).fragmentShader” and this does return the value as a string. but I guess I can’t just use a string as the GLSL pixel shader.

any ideas on what workflow I should use?

i’m fairly new to TD, but I have been programming for awhile.

You can include a Text DAT in your GLSL TOP code like this:

#include "nameOfYourDAT"

Thank you, Yes, I realize that. I can’t just bring in the raw text though. I am replacing lines of the GLSL with expressions and format strings.

My DAT has a function which returns a compiled shader. How do i call that function to return the compiled shader from the GLSL Top?

You can’t evaluate strings from within the GLSL TOP, so you’d need to use an Evaluate DAT or Script DAT to execute your function and fill in a DAT with the final shader code you then want to #include

thank you.

how do i fill in a text DAT ?

I try using this in the text DAT

mod('text1').compileShader()

and it does not return the string into the text DAT

“text1” is a textdat with my functions and variables which build the GLSL string.

I’m unclear what you are doing exactly, but I think a Script DAT is what you want. If the Text DAT has your function, then you’d use a Script DAT to call those functions, build up your text, and assign it as the output of the Script DAT.

ahhhh ok. i think im understanding.

i have a script dat which has my functions. but how do i set/assign the output of it to be the returned string ? once I sort that out, getting the text into the GLSL is trivial.

i just need to build the script (which I am doing), and send the return of the function to a text top. thats where I am hung up.

eventually, i want to setup a pulse button or something that will rebuild my shader script on demand (eventually through midi messages)

Hey,
You can assign text to a text DAT using op(‘pathToYourTextDat’).text = ‘your text…’. In your GLSL TOP you simply set the respective text DAT as the Pixel Shader (pixeldat) parameter.
Best,
Josef

Thank you!!! I have it working now.

Now I need to sort out how to get a new random seed on some message input. But thats for another day. Thanks!

You could use a noise CHOP on random, connect a constant chop to it and snap the input whenever a message is sent.
Or use python and import random.

thanks!

I just used python

import random and time and used time as the seed

Now I need to sort out how to get MIDI as an input to trigger my script DAT