Sampler2D doesnt show the exact PImage, but the average color of the PImage

I’m trying to write a simple shader where I just copy the current frame of the program into the shader via the shader.set function:

PShader shader;
PImage screen;

void setup(){
  size(1000, 1000, P2D);
  shader = new PShader(this, "Vert.vert", "Frag.frag");

  for(int i = 0; i < pixels.length; i++){
    pixels[i] = color(map(i, 0, pixels.length, 0, 255), 0, map(i, 0, pixels.length, 255, 0));

void draw(){
  screen = get();
  shader.set("text", screen);
  rect(0, 0, width, height);

Fragment Shader:

varying vec2 va_pos;
uniform sampler2D text;

void main(){
  gl_FragColor = texture2D(text, va_pos);

As described in the title, the program does not show a gradient between blue and red. The complete window ist just filled with a purple color

What does your vertex shader look like? Does it set va_pos?
If so, are the UV coordinates in the range of 0.0 to 1.0 or from 0.0 to width/height?

1 Like

I now realised, that the coordinates from va_pos range from 0.0 to width/height. Didn’t know, that the texture2D function() uses values between 0 and 1. Thank you very much!