# Shader toy convertion not clear enough

Hello, I’m here attempting again to understand and apply instructions on converting shader from shader toys.

I managed first example no problem. But this 2nd example with cubmap is a nightmare.
I really think even if its best example out here, it is still very complicate and must scare many users from using touch designer all together.

what I want personally from Touch Designer is the same power they use in video games to do what ever I want with it, new concepts, interactive stuff… but hard to be creative when it’s that complex, that is why the interface should simplify clarify so we can be creative with this technology.
Probably what most people want to do because we are not all working in an atomic central or putting together data for the nasa!

It would be so simple if we could see a video of someone applying all this. I’d even do the video myself if only I could get it to work. I’ve been using TD for a bit now and even I have problems so imagine someone that turns it on for first time.

I’d say the shader part of TD is not so well documented than other sections.
it does feel like politicians keeping explaination complex to keep the control. I know its not the case and people on forum are very helpfull.

Written instrutions are not the way forward I think now a days. human brain has special function to mimic stuff why not use it. (even when people answer questions on forum, understanding the answers can be a problem too)

Now back to this shader in question

The shader used as an example ‘‘shard’’ is not displaying the shard itself on the shader toy website. (mozilla here) but instructions should still work.

I can follow most instructions by when it comes to that part;

When the LMB is clicked, we want to write the values of null2 to thez and w channels of constant1, and when it’s released, we want to set them back to 0.

Add the following code snippet to the ‘offToOn’ function:

z = op(‘null2’)[‘x’]
w = op(‘null2’)[‘y’]
op(‘constant1’).par.value0 = z
op(‘constant1’).par.value1 = w

And add the following code to the ‘onToOff’ function:

op(‘constant1’).par.value0 = 0
op(‘constant1’).par.value1 = 0

You can use another ‘Merge’ CHOP to merge constant1 with null2 and add another ‘Null’ CHOP after it. Go back to the ‘GLSL’ TOP and in the four Value fields of the iMouse uniform, you can reference the x, y, z, and w channels of null3. You can do this with Python references or exports.

WHEN its says Add the following code snippet to the ‘offToOn’ function I understand you can paste the whole thing in that space u use for exports but that makes an error.
Then add the following code to the ‘onToOff’ function, sorry this not clear either.

other problem I sometimes have is, it says shader compiled succesfully when obviously its not.
no indication on what you did wrong so end of road.

You might think I like moaning about stuff, but its all in the optic lets make it clearer, so more people can use it. I have wasted a lot of time already with all this.

in your example that line says “Add the following code snippet to the ‘offToOn’ function:”. So this means the offToOn function in the Python code, inside the Chop Execute DAT. In your attached example you have written this code in the value for the parameter offToOn toggle button.

I understand that you’re frustated that you have difficulties grasping the technology.
But writing GLSL shaders is in the the end a coding task, so if you want to use them you’ll have to learn how to code - it will never be click and play, and GLSL is very hard stuff to learn, hardcore mathematics, and it’s not something you will learn from start in a few days. (So is DirectX and Vulkan, also in game engines).
So don’t see it as waisting time, but see it as time well spent learning a new trade. And if you decide it’s a total nightmare and coding is not for you, then you’ll be far better off trying one of many other software packages which let you make beautiful stuff without any coding, so you can enjoy yourself.

But if you really want to learn about shaders and how to write GLSL, I recommend getting this great book which will teach you all about GLSL: Graphics Shaders Theory and practice, second edition. It has lots of practical examples and is updated to glsl 4.x. Once you know (a bit of) GLSL, it’s easy to implement this in TouchDesigner, or game engines like Unity or Unreal.

Next to that, you’ll really have to learn some basic Python if you want to use TouchDesigner. This you can learn everywhere on the internet, start with some basic interactive tutorials (for instance here [url=http://www.learnpython.org/]http://www.learnpython.org/[/url] )and code you way up. If you have just a little bit of basic Python knowledge (what is a variable, what is a function) , you can follow these instructions far more easily and it will save you errors like this one.

Starting your lessons by copying shadertoy examples (and the best minds of the GLSL world have placed very complicated shaders there) and trying to get them to work in TD can be a very steep way of learning 2 new languages (GLSL and Python) at the same time.

Maybe you should check out these free TD Toxes by David Braun, see his video, who has many GLSL shaders in his TOP section, and they are all prepared to work under TD: DBraun TouchDesigner Github so you can play with them immediately.
Also I guess you know Matthew made many video tutorials about learning touchdesigner
And he has a whole section now as well about writing python in TD!

Hey greenpattern,
Thanks for your feedback. A lot of what Idzard is saying is correct. GLSL is one of the more advanced things available in TouchDesigner, and it’s not a great way to learn the program if you don’t already know GLSL. We would expect GLSL to be learnt using the vast amount of other articles available on the internet rather than through our documentation. Our documentation is more geared towards ‘this is how to use your existing knowledge of GLSL inside of TouchDesigner’.

The part of the article you mention being difficult isn’t GLSL related at all though, as that is just Python. You’ll want to go through some more Python tutorials to get a handle on that part of the program first in my opinion.

You also mention this:

The GLSL is compiled by your graphics driver, so Nvidia/AMD/Intel is doing the compilation. Although driver bugs with compiles are possible, they are incredibly rare. So if the GLSL TOP says it has compiled properly, then it very likely has. Just because something compiles properly though doesn’t mean it will ‘work’. As with any code there could be bugs or missing data needed to make the shader work properly.

Hello, thx for the detailed reply, that really helps, and I am sure will help many who probably jump in touch designer with GLSL in mind.
that book you recommended, I actually have here, but must admit it is hardcore and I’m probably missing a bit of background to understand fully what is in that book. I’ve also printed few pages of that github(hanging on my bathroom wall lol), the info great, clearest by far, I did not find it straight from the start unfortunately, got tangled in plenty of other tutorials instead. best explaination i see for the particles in glsl so far.
I am dead serious about mastering this even if it takes years. I realise its not easy task, and its annoying when you want to learn something and don’t know which direction to go.
I gave up once on it, but now I am more familiar with touch designer and I start thinking procedural, lets try again.
Yes David shared stuff put me on the track again (thx david).
you are right there is probably a lot of confusion due to mixing of python an glsl.
I did manage to convert quite a bunch of shaders now and its becoming clearer, cool little explanations along in the shadertoy codes. I have seen many effects since I am more or less a VJ/ photographer, there is this invisible force attracting me towards the complex or unsolvable shaders. I can see how incredibly powerfull they can be.
hopefully I can contribute to the community at some point. thx for your help and opinion, very valuable.

PS; If there is anyone Living in Scotland (edinburgh) that is willing to team up to tackle shader stuff and meet in real, I’m up for it. most of my friends don’t show much interest in it despite my attempt to convert them. thx