# Gray glsl filter with video capture

**URL:** <https://discourse.processing.org/t/gray-glsl-filter-with-video-capture/21735>\
**Category:** Gallery\
**Created:** [June 10, 2020, 12:39pm UTC](https://discourse.processing.org/t/gray-glsl-filter-with-video-capture/21735 "2020-06-10T12:39:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![monkstone](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/monkstone/32/64_2.png) [@monkstone](https://discourse.processing.org/u/monkstone)\
**Post date:** [June 10, 2020, 12:39pm UTC](https://discourse.processing.org/t/gray-glsl-filter-with-video-capture/21735/1 "2020-06-10T12:39:47Z")

</div>

On a bit of roll with glsl filters and video capture on my RaspberryPI4. Previously people have reported issues using regular processing filters with video capture:-

1. [Opengl and face OSC](https://discourse.processing.org/t/grey-filter-doesnt-work-live-camera-using-open-gl-and-face-osc/6565)
2. [Filter with glvideo](https://discourse.processing.org/t/using-filter-with-glvideo/11758)

Here is another glsl video capture sketch, this time in ruby (using my PiCrate gem):-

```ruby
require 'picrate'

class Gray < Processing::App
	load_library :video

	attr_reader :gray, :cam

	def settings
	  size(640, 480, P2D)
	end 

	def setup
	sketch_title 'Grayscale'
	  @gray = load_shader(data_path('gray.glsl'))
          gray.set('sketchSize', width.to_f, height.to_f)
	  start_capture(width, height)
	end

	def start_capture(w, h)
	  @cam = Java::ProcessingVideo::Capture.new(self, w, h, "UVC Camera (046d:0825)")
	  cam.start
	end

	def draw
	  return unless cam.available

          cam.read
          image(cam, 0, 0)
          return if mouse_pressed?
          filter(gray)
	end
		
	def captureEvent(c)
	  c.read
	end
end

Gray.new

```

and the glsl code

```auto
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
#define GRAY vec3(0.299, 0.597, 0.114)

uniform sampler2D texture; // iChannel0 in Shadertoy
uniform vec2 sketchSize; // iResolution in Shadertoy

void main() {
    vec2 uv = gl_FragCoord.xy / sketchSize.xy;
    gl_FragColor = vec4(vec3(dot(texture2D(texture, uv).xyz, GRAY)), 1.);
}

```

 ![gray](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a6dfacbe60af7a3de60fb5af4beffceec310e9ec.png)
