# Glsl background difference

**URL:** https://discourse.processing.org/t/glsl-background-difference/18024
**Category:** Libraries
**Created:** [February 22, 2020, 8:05pm UTC](https://discourse.processing.org/t/glsl-background-difference/18024 "2020-02-22T20:05:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![bitCrasher](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bitcrasher/32/408_2.png) [@bitCrasher](https://discourse.processing.org/u/bitCrasher)
#### Post date: [February 22, 2020, 8:05pm UTC](https://discourse.processing.org/t/glsl-background-difference/18024/1 "2020-02-22T20:05:10Z")

</div>

hi to all!  
i’m tryng to subtract the background ov a video stream

processing code

```auto
import processing.video.*;

Capture video;

PShader shader;
PGraphics pg;

void setup() {
  size(1280, 720, P2D);
  shader = loadShader("passImage.glsl");
  pg = createGraphics(width, height, P2D);
  shader.set("u_resolution", width/1., height/1.);
  video = new Capture(this, width, height);
  video.start();
}

void draw() {
  println(frameRate);
  if (video.available() == true) {
    video.read();
  }
  pg.beginDraw();
  pg.loadPixels();
  video.loadPixels();
  shader.set("textureCam", video);
  shader.set("preTextureCam", pg);
  shader(shader);
  pg.pixels = video.pixels;
  pg.updatePixels();
  video.updatePixels();
  pg.endDraw();
  rect(0, 0, width, height);
}

```

glsl code

```auto
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

uniform sampler2D textureCam, preTextureCam;
uniform vec2 u_resolution;
vec3 background = vec3(0);

void main(){
	vec2 st = gl_FragCoord.xy/u_resolution.xy;
	st.xy = vec2(1)-st.xy;
	vec2 st2 = gl_FragCoord.xy/u_resolution.xy;
	st.x = 1-st.x;
	vec3 color = texture2D(textureCam, st).rgb;
	vec3 preColor = texture2D(preTextureCam, st2).rgb;
	vec3 diff = abs(color-preColor);
	gl_FragColor = vec4(diff, 1);
}

```

the code work a little bit strange, too much black frame  
any suggestion?
