WebGL clipspace point visualization

Above you should see a black square with a little crosshair. The crosshair marks a point in space. This is drawn with WebGL. You can change the position of the point using the sliders to the right, representing four components of the point called X, Y, Z, and W.

By playing around with these sliders, you can discover many things about WebGL!

I implemented the above with a passthrough vertex shader, which passes on the vertex attributes as the vertex position:

attribute vec4 coord;
void main(void) { 
  gl_Position = coord; 

Then, whenever the sliders change, I pass in the six vertices of a 3D crosshair:

function redraw() {
  gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
    pos.x-CROSSHAIR_SIZE,  pos.y,                 pos.z,                pos.w,
    pos.x+CROSSHAIR_SIZE,  pos.y,                 pos.z,                pos.w,
    pos.x,                 pos.y-CROSSHAIR_SIZE,  pos.z,                pos.w,
    pos.x,                 pos.y+CROSSHAIR_SIZE,  pos.z,                pos.w,
    pos.x,                 pos.y,                 pos.z-CROSSHAIR_SIZE, pos.w,
    pos.x,                 pos.y,                 pos.z+CROSSHAIR_SIZE, pos.w,
  ]), gl.STATIC_DRAW);
  gl.drawArrays(gl.LINES, 0, 6);
I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.