Page 1 of 1

Webcam input for the new GLSLShader feature

Posted: Wed Sep 17, 2014 1:21 am
by wko
I trying to run a shader from shadertoy.com, but I am lost. The shader use a webcam input and I can't to find the right way.
It is a shader with edge detection, and is located at : https://www.shadertoy.com/view/XssGD7
Can you help me??

the code is:

Code: Select all

#define WEBCAM_RESOLUTION 512.0

void main(void)
{
	vec2 uv = gl_FragCoord.xy / iResolution.xy;
	
	// Sobel operator
	float offset = 1.0 / WEBCAM_RESOLUTION;
	vec3 o = vec3(-offset, 0.0, offset);
	vec4 gx = vec4(0.0);
	vec4 gy = vec4(0.0);
	vec4 t;
	gx += texture2D(iChannel0, uv + o.xz);
	gy += gx;
	gx += 2.0*texture2D(iChannel0, uv + o.xy);
	t = texture2D(iChannel0, uv + o.xx);
	gx += t;
	gy -= t;
	gy += 2.0*texture2D(iChannel0, uv + o.yz);
	gy -= 2.0*texture2D(iChannel0, uv + o.yx);
	t = texture2D(iChannel0, uv + o.zz);
	gx -= t;
	gy += t;
	gx -= 2.0*texture2D(iChannel0, uv + o.zy);
	t = texture2D(iChannel0, uv + o.zx);
	gx -= t;
	gy -= t;
	vec4 grad = sqrt(gx*gx + gy*gy);
	
	gl_FragColor = vec4(grad);
}

Re: Webcam input for the new GLSLShader feature

Posted: Wed Sep 17, 2014 1:34 am
by Magic
In general, you probably won't need to modify any code when you are using shaders.

Assuming you've copied the code into a text file (called "EdgeDetect.txt" for example), just do something like this to use your camera as input:
Image

Does that help?

Eric

Re: Webcam input for the new GLSLShader feature

Posted: Wed Sep 17, 2014 3:21 am
by wko
Yep, It's working!!!!
My webcam drivers was corrupted and I dont know why, a clean installing was necessary for correct function. The shader and output already works, I 'm happy..
Thanks