From shadertoy to TD

I’ve tried to convert shader (created by florian berger (flockaroo) - 2019 to TD, but have an error:

0(34) : error C7011: implicit cast from “vec3” to “vec2”
(0) : error C2003: incompatible options for link

Tried to convert moviefilein to cube and use sTDCubeInputs, but that was error:

0(34) : error C1068: array index out of bounds
(0) : error C2003: incompatible options for link


// #define iResolution
#define iChannel0 sTD2DInputs[0]
#define iChannel1 sTD2DInputs[1]
#define iChannel2 sTD2DInputs[2]

#define Res  (iResolution.xy)

#define RandTex iChannel1

vec2 scuv(vec2 uv) {
    float zoom=1.;
    #ifdef SHADEROO
    return (uv-.5)*1.2*zoom+.5; 

vec4 myenv(vec3 pos, vec3 dir, float period)
    return texture(iChannel2,dir.xzy)+.15;

vec4  getCol(vec2 uv) { return texture(iChannel0,scuv(uv)); }
float getVal(vec2 uv) { return length(getCol(uv).xyz); }
vec2 getGrad(vec2 uv,float delta)
    vec2 d=vec2(delta,0); return vec2( getVal(uv+d.xy)-getVal(uv-d.xy),
                                       getVal(uv+d.yx)-getVal(uv-d.yx) )/delta;

//void mainImage( out vec4 fragColor, in vec2 fragCoord )

out vec4 fragColor;
void main()
	vec2 uv = gl_FragCoord.xy / iResolution.xy;
    // calculate normal from gradient (the faster the higher)
    vec3 n = vec3(-getGrad(uv,1.4/iResolution.x)*.02,1.);

    /*vec3 light = normalize(vec3(-1,1,2));
    float diff=clamp(dot(n,light),0.,1.0);
    float spec=clamp(dot(reflect(light,n),vec3(0,0,-1)),0.0,1.0); spec=exp2(log2(spec)*24.0)*2.5;*/
    // evironmental reflection
    vec2 sc=(gl_FragCoord.xy-Res*.5)/Res.x;
    vec3 dir=normalize(vec3(sc,-1.));
    vec3 R=reflect(dir,n);
    vec3 refl=myenv(vec3(0),R.xzy,1.).xyz;
    // slightly add velocityfield to color - gives it a bit of a 'bismuty' look
    vec4 col=getCol(uv)+.5;
    col=mix(vec4(1),col,.35);*=.95+-.05*n; // slightly add some normals to color
	// =*(.5+.5*diff)+.1*refl; =*refl;

You are pretty close. main thing is that when defining your iChannel2, you should be using the correct lookup for the cube map input:

#define iChannel2 sTDCubeInputs[0]

Especially see how it uses a 0 for the array position, reason being as described in the documentation here:

So for example say you have 5 inputs connected to your GLSL TOP, in this order: a 2D TOP, a 3D TOP, a 2D TOP, a Cube TOP, a 2D Array TOP. Then


And you can reference your inputs like this:

 texture(sTD2DInputs[0],; // first 2D input
 texture(sTD2DInputs[1],; // second 2D input, NOT the second input connected to the TOP though
 texture(sTD3DInputs[0], vUV.stp); // first 3D input
 texture(sTDCubeInputs[0], vUV.stp); // first cube input
 texture(sTD2DArrayInputs[0], vUV.stp); // first 2D array input

Hope this helps

1 Like

Thank you, Markus, it helped! And special thanks for the tutorial videos, they are very useful for the beginners like me)

1 Like