GLSL Shadertoy Issues

Hi all!

I’ve been learning about using shadertoy tools and following this tutorial and while it looks like I resolved all the gl incompatibility issues, I’m still getting this error:

ERROR: No definition of main in fragment shader

I’ve googled this and haven’t seen in anything in relation with TouchDesigner and was wondering what the issue could be if the other compiler errors were solved.

Thank you!
Screen Shot 2018-04-08 at 11.12.09 AM.png
glslExercise.3.toe (4.63 KB)

instead of mainImage( out vec4 fragColor, in vec2 fragCoord )
you just use main()

and declare your out at the beginning:
out vec4 fragColor;

take a look at this:
[url]https://nvoid.gitbooks.io/introduction-to-touchdesigner/content/GLSL/12-6-Importing-Shadertoy.html[/url]

Thank you for the pointers and the resource!

I was able to get the above example to work thanks to the advice given by swampmonster
But with the following shader I am not able to get it to work.
I can get the following to compile by declaring

out vec4 fragColor;

at the top and changing

void mainImage( out vec4 c, vec2 u )

to

void main()

Here is the shader from shadertoy.com

[code]
#define r(a) mat2(cos(a + .78*vec4(0,6,2,0)))
void mainImage( out vec4 c, vec2 u ) {

c.xyz = iResolution;
u = (u+u-c.xy)/c.y*1.1;

vec4 n = vec4(u, sqrt(max(0., 1.-dot(u,u))), 1);

n.xy *= r(.8);
n.xz *= r(-.6);
n.xy *= r(n.z*4.+iTime*.3);
c = (n*.6+.9) * max(.2, n.z) * texture(iChannel0, n.xy*.1).r;
c.r *= .6;

}[/code]

It will compile but I get undeclared identifier errors.

[code]Vertex Shader Compile Results:

Compiled Successfully

=============

Pixel Shader Compile Results:
ERROR: 0:9: Use of undeclared identifier ‘c’
ERROR: 0:9: Use of undeclared identifier ‘iResolution’
ERROR: 0:10: Use of undeclared identifier ‘u’
ERROR: 0:10: Use of undeclared identifier ‘u’
ERROR: 0:10: Use of undeclared identifier ‘u’
ERROR: 0:10: Use of undeclared identifier ‘c’
ERROR: 0:10: Use of undeclared identifier ‘c’
ERROR: 0:12: Use of undeclared identifier ‘u’
ERROR: 0:12: Use of undeclared identifier ‘u’
ERROR: 0:12: Use of undeclared identifier ‘u’
ERROR: 0:14: Use of undeclared identifier ‘n’
ERROR: 0:15: Use of undeclared identifier ‘n’
ERROR: 0:16: Use of undeclared identifier ‘n’
ERROR: 0:16: Use of undeclared identifier ‘n’
ERROR: 0:16: Use of undeclared identifier ‘iTime’
ERROR: 0:17: Use of undeclared identifier ‘c’
ERROR: 0:17: Use of undeclared identifier ‘n’
ERROR: 0:17: Use of undeclared identifier ‘n’
ERROR: 0:17: Use of undeclared identifier ‘iChannel0’
ERROR: 0:17: Use of undeclared identifier ‘n’
ERROR: 0:18: Use of undeclared identifier ‘c’

=============

Program Link Results:
ERROR: One or more attached shaders not successfully compiled[/code]

read through the examples in the link. most of the errors you are getting will be explained in the first example.

As swampmonster said, make sure to go through the examples in that chapter. If you have any confusion I can answer questions on it.

You want

void mainImage( out vec4 c, vec2 u )

to actually be

void main()

as the first example goes through.

I’m a beginner and wanting to learn more about GLSL, And I was not able to open the link swampmonster posted maybe due to the amount of time passing but I’m experiencing an error message and only seeing a small portion effecting; the error currently is
`Traceback (most recent call last):
File “</project1/glsl1_pixel>”, line “op(‘/project1/glsl1_pixel’).run()”
td.tdError: File “/project1/glsl1_pixel”, line 1
uniform float uTime;
^^^^^
SyntaxError: invalid syntax
Results of run operation resulted in exception.
python >>>’

and the code is

uniform float uTime;
uniform sampler2D sTD2DInputs[1];
uniform vec4 uTD2DInfos[1];

out vec4 fragColor;

float noise3(vec3 x) {
    vec3 p = floor(x), f = fract(x);
    f = f * f * (3.0 - 2.0 * f);  // smoothstep to make derivative continuous at borders

    #define hash3(p) fract(sin(1e3 * dot(p, vec3(1, 57, -13.7))) * 4375.5453)  // rand

    return mix(
        mix(
            mix(hash3(p + vec3(0, 0, 0)), hash3(p + vec3(1, 0, 0)), f.x),  // trilinear interp
            mix(hash3(p + vec3(0, 1, 0)), hash3(p + vec3(1, 1, 0)), f.x), f.y),
        mix(
            mix(hash3(p + vec3(0, 0, 1)), hash3(p + vec3(1, 0, 1)), f.x),
            mix(hash3(p + vec3(0, 1, 1)), hash3(p + vec3(1, 1, 1)), f.x), f.y), f.z);
}

#define noise(x) (noise3(x) + noise3(x + 11.5)) / 2.0  // pseudoperlin improvement

void mainImage(out vec4 O, vec2 U) {  // draw isovalues
    vec2 R = uTD2DInfos[0].zw;
    float n = noise(vec3(U * 8.0 / R.y, 0.1 * uTime));
    float v = sin(6.28 * 10.0 * n);
    float t = uTime;

    v = smoothstep(1.0, 0.0, 0.5 * abs(v) / fwidth(v));

    O = mix(
        exp(-33.0 / R.y) * texture(sTD2DInputs[0], (U + vec2(1.0, sin(t))) / R),
        0.5 + 0.5 * sin(12.0 * n + vec4(0.0, 2.1, -2.1, 0.0)),
        v);
}

void main() {
    vec2 uv = gl_FragCoord.xy;
    mainImage(fragColor, uv);
}

thank you for you’re help!

Hi @Metaphoric,

from the error it looks like you are trying to execute the glsl shader in python?

Traceback (most recent call last):
File “</project1/glsl1_pixel>”, line “op(‘/project1/glsl1_pixel’).run()”
td.tdError: File “/project1/glsl1_pixel”, line 1
uniform float uTime;
^^^^^
SyntaxError: invalid syntax
Results of run operation resulted in exception.

could this be the case?
To use glsl shaders, you would have to use them with a GLSL TOP for example.

It’s a bit old but maybe still a good basic introduction to glsl and TouchDesigner:

cheers
Markus