GLSL / error C1008: undefined variable "p"

Hi, So I’m again trying to convert a shader from Shader Toys.
I get
error C1008: undefined variable “p”
error C1008: undefined variable “c”

so there is something I forgot? big P so normally points, how can I define ‘c’ and 'p ’ this kind of shader usually has everything it needs to work.

super simple shader converted using the convertion tool.

layout (location = 0) out vec4 fragColor;
uniform vec3 iResolution;
uniform float iGlobalTime;
uniform float iChannelTime[4];
uniform vec3 iChannelResolution[4];
uniform vec4 iMouse;
uniform sampler2D sInput0;
uniform sampler2D sInput1;
uniform sampler2D sInput2;
uniform sampler2D sInput3;
uniform vec4 iDate;
uniform float iSampleRate;
// Damn your eyes
// @P_Malin

// Epilepsy warning or something - Click image to animate.

// Not sure how I arrived at this but I guess I saw something similar somewhere
// probably a Vasarely painting as Fabrice suggests.

void main()
{
vec2 uv = (p.xy / iResolution.xy) * 2. - 1.;
uv.x *= iResolution.x / iResolution.y;
float r = max( 0., 1. - length(uv) );
float t = iGlobalTime * 2.0;
if (iMouse.x <= 0.) t = 1.;
t = r * r * sin(r+t) * 3.0;
uv *= mat2( cos(t), -sin(t), sin(t), cos(t) );
c = vec4( sin( uv.x * 150. ) * 0.5 + 0.5 );
}

[code]
// You need to declare p, which I think in this case is supposed to be gl_FragCoord.xy
vec2 p = gl_FragCoord.xy;

// You need to declare c. You can’t use it without declaring it.
vec4 c = vec4( sin( uv.x * 150. ) * 0.5 + 0.5 );

// set the output
fragColor = c;[/code]

1 Like

Thx david, small steps here, but going somewhere.
My approach now is to convert and tweak every number in shader to find where i can ad new uniforms…
It seems to work.

Hi David, how u doing?
I think I need your help here, new encounter is the letter O
what does it usually stand for?
I figured out I with your method, now not sure. it its output gl-FragCoord.xy?
letter O =??

layout(location = 0) out vec4 fragColor;
uniform vec3 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
uniform float iTimeDelta; // render time (in seconds)
uniform int iFrame; // shader playback frame
uniform float iChannelTime[4]; // channel playback time (in seconds)
uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)
uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click
uniform sampler2D sTDInput0;
uniform sampler2D sTDInput1; // input channel. XX = 2D/Cube
uniform vec4 iDate; // (year, month, day, time in seconds)
uniform float iSampleRate; // sound sample rate (i.e., 44100)

vec2 I = gl_FragCoord.xy; ???

void main()
{
vec2 P = (I-.5iResolution.xy)/2e2;
vec3 R = vec3(P,sqrt(1.-dot(P,P)));
O = mix(texture.xy(sTDInput0,.01
iTime+.3R.xy/sqrt(R.z))max(R.x.3+R.y.9+R.z*.1+.5,.1),
vec4(.6,.4,.3,1)/dot(P,P*.5),pow(1.-sqrt(max(1.-dot(P,P),0.)),2.));
}

If anyone can help me out here, I’ll be grateful.

shadertoy.com/view/4d2fzw original

If you look at the shader on shadertoy, the O variable is declared as the output variable for mainImage(). So this is presumabl the output color for the pixel. What gl_FragColor used to be. So O should be replaced with whatever you have declared your output color. By default in the GLSL TOP the shader has it declared as fragColor.

Hi Malcom!
void main()
{
vec2 P = (gl_FragCoord.xy-.5iResolution.xy)/2e2;
vec3 R = vec3(P,sqrt(1.-dot(P,P)));
fragColor = mix(texture.xy(sTDInput0,.01
iTime+.3R.xy/sqrt(R.z))max(R.x.3+R.y.9+R.z*.1+.5,.1),
vec4(.6,.4,.3,1)/dot(P,P*.5),pow(1.-sqrt(max(1.-dot(P,P),0.)),2.));

}
like this?
It makes a c99999 error, sorry its almost like i’m dyslexic when it come to code. I tried all sorts here with vec4 in front of fragColor, without… could it be its actually impossible on that particular shader? (you tried it?) I’m loosing the plot here.

Hi there,

You might be missing the ‘out vec4 fragColor’ above void main.
Also ‘sTDInput0’ should be sTDInputs[0]… and well there are some other variables used that should fixed (iResolution → uTDOutputInfo.res.xy, iTime should be added as an uniform.

Added a working example.

Cheers,
tim
shadertoyShader.tox (1.03 KB)

greenpattern, don’t feel too down about the difficulty in ones like this, they were made for a competition that had maximum character counts of like ~300 characters, which is why all the variable names are stupid and single letters.

Like Malcolm mentioned, sometimes you can get clues by seeing where else the variable is being used/routed to. In the case of O, it was in the mainImage() as the “out”, so you could use our regular fragColor. You’ll just have to move through ones this like with a bit slower expectation or ignore any shaders with [SH*] in the title, because they’ll be from the competition.

Thx for support, No, you know I’m just joking here,I like to dramatize.hehe
It’s not first shader that resists. Actually I’ve got serious collection of converted shader going on here, and starting to be able to plug different inputs to use some precise effect needed, this is great, fun comes back when its all connected to touch designer and all works speed of light.
Now next quest is to make little galaxy ever seen before layering these modified shaders special planets.

youtube.com/watch?v=JjKY_oFHy68

Ok I’ll forget about the [SH*]
never noticed before.
shame because this one too is a killer. shadertoy.com/view/4dBBW1 :wink:

The SH* ones are indeed quite cryptic, though still possible to use if you redeclare the input/output and i* variables.

The ‘unknown for touch’ variables in this shader are c, u, iResolution, iTime and iChannel0.
c would be the output color (since its located in mainImage(out vec4 c, vec2 u))
u would be the input coordinate, this is in pixels in shadertoy. (so not the uv coordinates)
iResolution, the resolution of the TOP in pixels.
iTime, current time
iChannel0, first input top.

So to convert this you’ll get something like:

// create an uniform variable and set it to something like 'absTime.seconds'
uniform float uTime;

void main() {

// This is the output resolution of the current glsl TOP
vec3 iResolution = vec3(uTDOutputInfo.res.zw,1); 

// vUV.st is the uv coordinate of the TOP, multiply this with the
// resolution to get the pixel coordinate
vec2 u = vUV.st*iResolution.xy; 

// Declaring iTime to be our new uniform
float iTime = uTime; 

// First input TOP would be declared as this
sampler2D iChannel0 = sTD2DInputs[0]; 

...

cheers,
tim
SwirlyBall.tox (1.28 KB)