adapt temporal slide shader into processing; ouch !!
in
Core Library Questions
•
8 months ago
hello all,
I try to adapt a temporal slide shader into processing.
I'm pretty newbie to processing, and to the shader world.
The shader should do really cool effects of fading frames from camera for instance.
But still black screen...
here's the code pde, and fragment code:
I try to adapt a temporal slide shader into processing.
I'm pretty newbie to processing, and to the shader world.
The shader should do really cool effects of fading frames from camera for instance.
But still black screen...
here's the code pde, and fragment code:
- import processing.video.*;
PShader slide;
Capture cam;
void setup() {
size(320, 240, P2D);
cam = new Capture(this, 320, 240);
textureWrap(CLAMP);
slide = loadShader( "slide-frag.glsl");
cam.start(); slide.set("tex0", cam);
}
void draw() {
println(frameRate);
if (cam.available())
{
cam.read();
}
slide.set("slide_down", 20);
shader(slide);
image(cam, 0, 0,width,height);
}
here's the slide-frag.glsl code:
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endi
uniform float slide_up;
uniform float slide_down;
varying vec2 texcoord0;
varying vec2 texcoord1;
uniform sampler2D tex0;
uniform sampler2D tex1;
void main(void)
{
vec4 su, sd, up, down, amount;
// sample inputs at texcoords
vec4 input0 = texture2DRect(tex0, texcoord0);
vec4 input1 = texture2DRect(tex1, texcoord1);
// get contribution
amount.x = input0.x > input1.x ? 1.0 : 0.0;
amount.y = input0.y > input1.y ? 1.0 : 0.0;
amount.z = input0.z > input1.z ? 1.0 : 0.0;
amount.w = input0.w > input1.w ? 1.0 : 0.0;
// calculate slide down
float d = max(1.0, abs(slide_down));
sd = vec4(1.0 / d);
down = input1 + ((input0 - input1) * sd);
// calculate slide up
float u = max(1.0, abs(slide_up));
su = vec4(1.0 / u);
up = input1 + ((input0 - input1) * su);
// mix between down and up
gl_FragColor = mix(down, up, amount);
}
any help would be appreciated, thank you !!
1