Skip to content

Instantly share code, notes, and snippets.

View gordonnl's full-sized avatar

Nathan Gordon gordonnl

View GitHub Profile
@gordonnl
gordonnl / hitTest.js
Last active February 4, 2021 17:49
Hit test in threejs for skinnedMesh using RTT
/*
*
* Render current frame and check pixel
* transparency beneath mouse position.
* Threejs required.
*
*/
var gl = renderer.context;
var rtTexture = new THREE.WebGLRenderTarget(WIDTH, HEIGHT, {minFilter: THREE.LinearFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat});
@gordonnl
gordonnl / Serve.js
Created May 19, 2020 07:55
Node development server
// Based on https://github.com/lukejacksonn/servor
// For direct use
// node server ${process.cwd()} 8080 --debug
// node server ${process.cwd()}
const args = process.argv.slice(2).filter((x) => x.indexOf('-') !== 0);
const root = args[0];
const port = args[1];
const debug = ~process.argv.indexOf('--debug') || ~process.argv.indexOf('-d');
// Author: Nathan Gordon
// Title: Raytrace Background for http://patriciogonzalezvivo.github.io/glslEditor/
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_time;
@gordonnl
gordonnl / alchemy_AO
Created November 26, 2014 19:31
Alchemy AO Shader
uniform sampler2D depths;
uniform sampler2D wc_normals;
uniform sampler2D random_texture;
uniform vec3 wc_camera_eye_position;
uniform floatz_far;
uniform vec2 tc_window;
uniform mat4 projection_matrix;
@gordonnl
gordonnl / textToPages.js
Last active August 29, 2015 14:07
Return pages of text based on available space
/*
*
* Use:
* var textPages = textToPages(myElement)
* returns array of strings.
*
*/
var textToPages = function(element) {
var pages = [];
@gordonnl
gordonnl / dragZoom.js
Created October 6, 2014 09:44
Drag and zoom controls with touch support.
// Requires jquery and detectizr (checks classes of 'touch', 'firefox' and 'ie' on the html element)
var dragZoom = (function() {
// The container - normally styled to be the size of the page with overflow hidden.
var _cont = $('.container');
// The child of container, who is going to scale and move.
var _content = $('.content');
// Edit this to set max scale.
@gordonnl
gordonnl / inactive.js
Last active August 29, 2015 14:06
Pause Inactive Tab Using visibilitychange
var forced = false;
var pauseWhileInactive = function() {
switch (document.visibilityState) {
case 'hidden' :
if (!sfx.volume.value) return;
forced = sfx.volume.value;
sfx.volume.value = 0;
break;
case 'visible' :
if (!forced) return;