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

**URL:** <https://discourse.processing.org/t/sampler2d-doesnt-show-the-exact-pimage-but-the-average-color-of-the-pimage/36972>\
**Category:** Coding Questions\
**Created:** [May 19, 2022, 11:52pm UTC](https://discourse.processing.org/t/sampler2d-doesnt-show-the-exact-pimage-but-the-average-color-of-the-pimage/36972 "2022-05-19T23:52:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sevval](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@Sevval](https://discourse.processing.org/u/Sevval)\
**Post date:** [May 19, 2022, 11:52pm UTC](https://discourse.processing.org/t/sampler2d-doesnt-show-the-exact-pimage-but-the-average-color-of-the-pimage/36972/1 "2022-05-19T23:52:19Z")

</div>

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:

```auto
PShader shader;
PImage screen;

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

  loadPixels();
  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));
  }
  updatePixels();
  noStroke();
}

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

```

Fragment Shader:

```auto
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

---

<div class="post-metadata">

**Author:** ![noahbuddy](https://avatars.discourse-cdn.com/v4/letter/n/73ab20/32.png) [@noahbuddy](https://discourse.processing.org/u/noahbuddy)\
**Post date:** [May 20, 2022, 6:08am UTC](https://discourse.processing.org/t/sampler2d-doesnt-show-the-exact-pimage-but-the-average-color-of-the-pimage/36972/2 "2022-05-20T06:08:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Sevval](https://avatars.discourse-cdn.com/v4/letter/s/ba9def/32.png) [@Sevval](https://discourse.processing.org/u/Sevval)\
**Post date:** [May 20, 2022, 10:54am UTC](https://discourse.processing.org/t/sampler2d-doesnt-show-the-exact-pimage-but-the-average-color-of-the-pimage/36972/3 "2022-05-20T10:54:28Z")

</div>

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!
