Previous topicNext topic

Webcam input for the new GLSLShader feature

Questions, comments, feedback, etc.
Post Reply
wko
Posts: 3
Joined: Thu Sep 04, 2014 8:20 am

Webcam input for the new GLSLShader feature

Post 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);
}
Magic
Site Admin
Posts: 3440
Joined: Wed Apr 09, 2014 9:28 pm

Re: Webcam input for the new GLSLShader feature

Post 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
wko
Posts: 3
Joined: Thu Sep 04, 2014 8:20 am

Re: Webcam input for the new GLSLShader feature

Post 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
Post Reply