Skip to content

Instantly share code, notes, and snippets.

View mzgoddard's full-sized avatar

Z Goddard mzgoddard

  • Bocoup
  • Boston, MA
View GitHub Profile
// packing a float in glsl with multiplication and fract
vec4 packFloat( float depth ) {
const vec4 bit_shift = vec4(
256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bit_mask = vec4(
0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
// fract is the problem
vec4 res = fract( depth * bit_shift );
// packing a float in glsl with multiplication and mod
vec4 packFloat( float depth ) {
const vec4 bit_shift = vec4(
256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );
const vec4 bit_mask = vec4(
0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );
// combination of mod and multiplication and division works better
vec4 res = mod(
depth * bit_shift * vec4( 255 ),
// packing a float in javascript using multiplication and bitwise operators
function packFloat( texarray, posX, posY, num ) {
var index = ( posX + posY * texarray.width ) * 4;
texarray[ index ] = ( num * 256 * 256 * 256 * 256 ) & 255;
texarray[ index + 1 ] = ( num * 256 * 256 * 256 ) & 255;
texarray[ index + 2 ] = ( num * 256 * 256 ) & 255;
texarray[ index + 3 ] = ( num * 256 ) & 255;
}
@mzgoddard
mzgoddard / actionlist.js
Created September 18, 2012 21:18
GameLoop and Network stubs
// Actions should only store primitive values, when acting it'll look up stuff in a given idSetHash to act on
function Action() {}
// should be false if it shouldn't be cleared from a statebag, example player add / remove actions
Action.prototype.canClear = true
// some deserialized actions may produce a graphics effect, but otherwise their side effects should already be a part of the state?
// flags is an object determining if client, server, or under prediction or lockstep
Action.prototype.act = function( actionList, idSetHash, flags ) {}
// serialize for network transmission
Action.serialize = function( encoder, action ) {
// return argsArray as compressedString
@mzgoddard
mzgoddard / has_tests.js
Created September 20, 2012 21:21 — forked from tJener/gist:3758415
commonjs/amd boilerplate
// shamlessly stolen from lodash
/*global define:false*/
;(function( window, undefined ) {
var freeExports = false;
// must be loaded first!
var has = window.has;
if ( typeof exports === 'object' ) {
freeExports = exports;
@mzgoddard
mzgoddard / actionlist.js
Created October 10, 2012 16:01
ActionList buffer changes
// classes that are buffered
Action.prototype.useBuffer = false;
ActionList.prototype.bufferList = new ActionList
ActionList.prototype.store = function( Action, ... || [ Action... ] ) {
if ( action.useBuffer ) {
this.bufferList.store( action );
}
// normal store stuff
}
@mzgoddard
mzgoddard / gist:4146599
Created November 26, 2012 04:20
pillar of feathers
Tall, statuesque
A beam of support
or ancient ornamentation
a pillar
Short, feathered
A parent of life
or pest removal
an owl
@mzgoddard
mzgoddard / gist:4671039
Created January 30, 2013 05:56
build instructions for OSX box2d emscripten
# https://gist.github.com/1974955
brew install node spider-monkey closure-compiler yuicompressor
brew install llvm --with-clang
git clone git://github.com/kripken/emscripten.git
cd emscripten
./emcc
(mate|vim|emacs) ~/.emscripten
# Change EMSCRIPTEN and LLVM defaults
@mzgoddard
mzgoddard / gist:4760384
Created February 12, 2013 05:11
synergy owl poem
screech, called grandpa
the taletall sounds of him walking down the hall
the knock of his of his stubbed leg
the flap of his creaking wing
coming around the wall
into the lounge, giving me a stare
An aged look, longing for youth but arrogant in age.
"Everything does not tick on forever"
@mzgoddard
mzgoddard / gist:6276974
Created August 20, 2013 03:59
Space Leap TODO
✓ field of asteroids
✓ ignore particles
✓ ignore particle group
✓ leaper particle and trigger
✓ spawn on surface
✓ jump
✓ stick to new surface
- angle once stuck
✓ camera
✓ renderer, shaders, and views