From shadertoy to TD

I’ve tried to convert shader (created by florian berger (flockaroo) - 2019 https://www.shadertoy.com/view/WdVXWy) 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

Code:

// #define iResolution uTDOutputInfo.res.zw
#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
    zoom=1.-iMouseData.z/1000.;
    #endif
    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.);
    n=normalize(n);

    /*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);
    col.xyz*=.95+-.05*n; // slightly add some normals to color
    
	//fragColor.xyz = col.xyz*(.5+.5*diff)+.1*refl;
	fragColor.xyz = col.xyz*refl;
	fragColor.w=1.;
}

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

 TD_NUM_2D_INPUTS = 2
 TD_NUM_3D_INPUTS = 1
 TD_NUM_2D_ARRAY_INPUTS = 1
 TD_NUM_CUBE_INPUTS = 1

And you can reference your inputs like this:

 texture(sTD2DInputs[0], vUV.st); // first 2D input
 texture(sTD2DInputs[1], vUV.st); // 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
cheers
Markus

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

I have got the same issue now. I am trying to create the same GLSL which @max_madweed was trying to create. I am at the last stage and i am getting below error.

*Pixel Shader Compile Results: *
0(36) : error C7011: implicit cast from “vec3” to “vec2”

Above error comes at below line.
return texture(sTD2DInputs[2],dir.xzy)+.15;

I didnt convert my image file into cube hence i didnt use sTDCubeInputs[0]. However, it still gives me error.

my TD Network looks like following.

Please let me know, what could be the correct buffer/channel i should be passing for this to work.

And my code for last GLSL is following.

    #define PI2 6.283185

    #define Res0 vec2(textureSize(iChannel0,0))
    #define Res1 vec2(textureSize(iChannel1,0))

    vec2 scuv(vec2 uv) {
        float zoom=1.;
        #ifdef SHADEROO
        zoom=1.-iMouseData.z/1000.;
        #endif
        return (uv-.5)*1.2*zoom+.5; 
    }

    vec2 uvSmooth(vec2 uv,vec2 res)
    {
        // no interpolation
        //return uv;
        // sinus interpolation
        //return uv+.8*sin(uv*res*PI2)/(res*PI2);
        // iq's polynomial interpolation
        vec2 f = fract(uv*res);
        return (uv*res+.5-f+3.*f*f-2.0*f*f*f)/res;
    }


    vec2 iResolution = uTD2DInfos[0].res.zw;
    out vec4 fragColor;
    #define Res  (iResolution.xy)

    #define RandTex sTD2DInputs[1]

    vec4 myenv(vec3 pos, vec3 dir, float period)
    {
        return texture(sTD2DInputs[2],dir.xzy)+.15;
    }

    vec4  getCol(vec2 uv) { return texture(sTD2DInputs[0],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 )
    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.);
        n=normalize(n);

        /*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);
        col.xyz*=.95+-.05*n; // slightly add some normals to color
        
    	//fragColor.xyz = col.xyz*(.5+.5*diff)+.1*refl;
    	fragColor.xyz = col.xyz*refl;
    	fragColor.w=1.;
    }

without testing this looks like the problem. A 2D texture is sampled via 2 coordinates (basically x,y but in shaders usually called u and v) - hence it’s trying to convert the dir.xzy - which is a 3 item vector to a 2 item vector and fails. Not sure what the result will look like, but the error should go away by just removing the y swifle from that lookup:

return texture(sTD2DInputs[2],dir.xz)+.15;

Hope this helps
Markus

Thank you @snaut. I will give a try and let you know the outcome.