GLSL compile explanation

Hi people,

can someone from the group of GLSL masters explain me how to compile properly a particular shader from ShaderToy. I am not a coder so I just tried to follow some simple steps.

Thank you in advance
GLSL_glitch_compile.toe (4.43 KB)
GLSL_glitch.toe (11.4 KB)

I’m looking at this in 099, if you’re in 088 your results might be different.

You’ve got a few things here. The biggest error is your use of:

sTD2DInputs[1]

The indexing for this starts at 0, so you really want to use this instead:

sTD2DInputs[0]

The rational here is that in lists and one dimensional arrays the number that represents position starts at 0. If we have a list like this:

fruit = [ 'apple', 'orange', 'lemon' ]

The corresponding list positions are:

fruit[0] = apple fruit[1] = orange fruit[2] = lemon

The inputs for an operator also work in this same fashion, so the first input of your glslTOP is in the 0 position, the second in the 1 position, and the third in the 2 position.

Similarly, you’re using

sInput0

when I think you want

 sTD2DInputs[0]

You’re also using

fragCoord

instead of

gl_FragCoord

I also think you’re last line is intended to be

fragColor.xyz *= mask;

not

fragCoord.xyz

The rational here is gl_FragCoord represents coordinates for a given fragment - you might think of this as the position in your full image for a given pixel. fragColor on the other hand is the vec3 that’s responsible for the color of a given pixel. I’m pretty sure that what you want to do here is change the color value of a pixel, not try to change its position - which is probably going to throw an error.

Making those changes I see a glitchy result that’s either red or green with some scan lines.

As a general note here the uv coords of your image are already declared for you by TouchDesinger. Instead of calculating those with:

vec2 uv = gl_FragCoord.xy / iResolution.xy;

you can instead use

vec2 uv = vUV.st;

Thanks for the lesson. I’ll try it. I have the GLSL compiled by the ShaderToytoTD shared project. What is my concern is that the effect is kind of broken and don’t fit the original one.

I am attaching a screenshot from the original shader.

Best

Have you checked this out?

nvoid.gitbooks.io/introduction- … ertoy.html

Thank you both. I followed your steps and successfully compiled the shader. As my first concern - it is working in a very weird way. The distortion and rgb displacement are totally wrong from what it must be.

I am playing now with some values (plus a composite top) and it is becoming better. Hope that I will get also better with coding…someday