GLSL Hacker v0.6.3.1 for Windows + Webcam

GLSL Hacker, webcam, displacement mapping

I uploaded a new dev version of GLSL Hacker for Windows (v0.6.3.1) that comes with a built-in webcam support. No additional library is required. You can use the webcam in Lua and Python. You can easily update a texture with the webcam output and use this texture like any regular texture.

I’ll wrote later an article about how to use the webcam with GLSL Hacker under all OSes (Windows, Linux and Mac OS X).

The following screenshot shows a simple displacement mapping demo. I must say that I spent few hours playing with this simple effect. The webcam texture is mapped to a wireframe mesh plane (100×100 segments). The demo is available in the code sample pack in the moon3d/gl-210-webcam/ folder. You can use the mouse and the keyboard to move the mouse. The red line comes from another postfx demo and is just the seperation between the webcam image without effect and image with postfx (here a posterization effect).

GLSL Hacker, webcam, displacement mapping

For the displacement mapping, I took some code in an old tutorial I wrote for oZone3D.Net: Vertex Displacement Mapping using GLSL. 7 years ago, displacement mapping was a bit hazardous, only nearest filtering was available in the vertex shader and it didn’t work on Radeon cards…

Here are the init and frame scripts of the demo. The parts related to the webcam are in bold.


app_dir = gh_utils.get_scripting_libs_dir() 		
dofile(app_dir .. "lua/Moon3D_v2.lua")

moon3d.init(2, 1)

camera =, 0, 0, 100) -- Orbit mode

glsl_prog ="gpu_prog_postfx_01")

webcam1 = gh_utils.webcam_create()
gh_utils.webcam_start(webcam1, 1)
webcam_name = gh_utils.webcam_get_name(webcam1)
frame_w, frame_h = gh_utils.webcam_get_frame_size(webcam1)

abs_path = 1
PF_U8_RGB = 1
PF_U8_BGR = 2
tex01 = gh_texture.create_2d_v2(frame_w, frame_h, PF_U8_BGR, 0)

mesh =, frame_h/5, 400, 400)
moon3d.object.setEulerAngles(mesh, 90, 0, 0)


moon3d.startFrame(0.1, 0.3, 0.3, 1.0)

local elapsed_time = moon3d.getTime()

gh_texture.bind(tex01, 0)
gh_utils.webcam_update_texture(webcam1, tex01)

gh_gpu_program.uniform1f(glsl_prog, "gamma", 0.6)
gh_gpu_program.uniform1f(glsl_prog, "numColors", 8.0)
gh_gpu_program.uniform1f(glsl_prog, "displacement_scale", 20.0)
gh_object.set_position(mesh, 0, 0, 0)

moon3d.print(10, 20, "GLSL Hacker | Moon3D - Simple webcam demo - PostFX")
moon3d.printRGBA(10, 40, 0, 1, 0, 1, "Webcam name: " .. webcam_name)


2 thoughts on “GLSL Hacker v0.6.3.1 for Windows + Webcam”

Comments are closed.