Basic PShader Issue

I tried making it work. Here are the first steps to fix it.

  • The screen is black, so I make float r = 1.0; in the fragment shader expecting the rect to turn red.
  • It doesn’t, so I compare to the default shaders from Processing. I see that they don’t use modelViewProjectionMatrix but transformMatrix so I make that change and it turns red. Good.
  • Next, I see that in my shaders I use texture2D instead of texture so I make that change. Then it fails to compile, because sampler2DRect should be sampler2D in that case. After that change, it compiles and I get a purple color that I think comes from the image.
  • I think the scale of the image is wrong, maybe related to not using Rect anymore.
  • I try setting float r = texture2D(tex, gl_FragCoord.xy/1000.0).r; to confirm that is a scaling issue (see the divided by 1000 to scale it down) and it seems to be the case: now I see the image.
  • So I try this:
  vec2 uv = gl_FragCoord.xy;
  uv.x /= resolution.x;
  uv.y /= resolution.y;

  float r = texture2D(tex, vec2(
        uv.x + drift * noise(vec2(p.x + x_noise.r, p.y + time)), 
        (resolution.y - uv.y) + drift * noise(vec2(p.x + time, p.y + y_noise.r)))).r;
  float g = texture2D(tex, vec2(
        uv.x + drift * noise(vec2(p.x + x_noise.g, p.y + time)), 
        (resolution.y - uv.y) + drift * noise(vec2(p.x + time, p.y + y_noise.g)))).g;
  float b = texture2D(tex, vec2(
        uv.x + drift * noise(vec2(p.x + x_noise.b, p.y + time)), 
        (resolution.y - uv.y) + drift * noise(vec2(p.x + time, p.y + y_noise.b)))).b;

Which gives me an animated noise effect. Not sure if that what it should do, but it looks interesting :slight_smile:

Maybe this helps you get started?


(I made it a bit brighter in gimp because it was probably too dark for this forum)

2 Likes