Author Topic: How to use webcam texture in a GLSL Shader  (Read 5941 times)

0 Members and 1 Guest are viewing this topic.

Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4410
    • View Profile
How to use webcam texture in a GLSL Shader
« on: February 26, 2016, 06:07:34 PM »
That one is quite easy

 init_scene:

copy webcam code from geexlab_code_sample_pack/host_api/webcam/webcam_win32_spout_test.xml ( the other demos didn't work on my rig for some reason)

rename tex01 to webcamtex to avoid confusion

and don't forget (like me in first place) to add

quad = gh_mesh.create_quad(winW, winH)
shadertoy_prog = gh_node.getid("shadertoy_prog")



update_scene:

gh_texture.bind(webcamtex, 0)
gh_utils.webcam_grab_frame(webcam1)
gh_utils.webcam_update_texture(webcam1, webcamtex)
gh_gpu_program.uniform1i(shadertoy_prog, "iChannel0", 0)


That's all.

>>>download RippleCam<<<






Wrist slitter, originally for video texture

« Last Edit: February 26, 2016, 06:35:24 PM by Stefan »


JeGX

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2068
    • View Profile
    • Geeks3D.com
Re: How to use webcam texture in a GLSL Shader
« Reply #1 on: February 26, 2016, 06:37:34 PM »
Thanks for the effect!


copy webcam code from geexlab_code_sample_pack/host_api/webcam/webcam_win32_spout_test.xml ( the other demos didn't work on my rig for some reason)


I think it's because the demo tries to connect to the second webcam. Look for the following line in the INIT script:
Code: [Select]
gh_utils.webcam_start(webcam1, 2)

and replace it by:
Code: [Select]
gh_utils.webcam_start(webcam1, 1)

I have two webcams on my system and I forgot to update the demos.





Stefan

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4410
    • View Profile
Re: How to use webcam texture in a GLSL Shader
« Reply #2 on: February 26, 2016, 07:06:50 PM »

I think it's because the demo tries to connect to the second webcam.

Yes, that was the culprit.

I quickly converted some video demos to webcam demos.
Hail to the clipboard  :P

>>> download 10 webcam demos<<<

Quote
RippleCam_gl2.xml
webcam_Ascii_Art_gl2.xml
webcam_BillBoarding_gl2.xml
webcam_EGA_Style_gl2.xml
webcam_fractal_gl2.xml
webcam_heightfield_gl2.xml
webcam_mush_gl2.xml
webcam_Old_video_gl2.xml
webcam_Page_Curl_Effect_gl2.xml
webcam_Wrist_Slitter_gl2.xml