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:-
Here is another glsl video capture sketch, this time in ruby (using my PiCrate gem):-
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
#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.);
}