Skip to content

Instantly share code, notes, and snippets.

View zz85's full-sized avatar

Joshua Koo zz85

View GitHub Profile
@zz85
zz85 / gist:5522800
Last active December 17, 2015 00:39
JS1K 2013 "Spring" Finalists
@zz85
zz85 / messages.js
Created September 7, 2013 23:48
Offline Rendering of @kig's Message presentation app using SlimerJS
/*
PDF Generator for @ilmarihei's Awesome "Messsage" Presentation App!
Usage:
./slimerjs messages.js
You may also need to
- get http://slimerjs.org/
- edit the config variables
- run `convert slides/*.jpg presentation.pdf`
@zz85
zz85 / ShaderUtils.js
Last active July 26, 2022 20:02
AutoGen Three.js Shader Uniforms
// https://github.com/mrdoob/three.js/issues/4145
// based on https://github.com/unconed/ShaderGraph.js/blob/master/src/Snippet.js
var typeMaps = {
'float': 'f',
'vec2': 'v2',
'vec3': 'v3',
'vec4': 'v4',
'mat3': 'm3',
'mat4': 'm4',
@zz85
zz85 / LoopSubdivisionModifier.js
Created February 18, 2014 04:32
Loop Scheme Subdivision Modifier for Three.js (Draft 1)
/*
* @author zz85 / http://twitter.com/blurspline / http://www.lab4games.net/zz85/blog
*
* Subdivision Geometry Modifier
* using Loop Subdivision Scheme
*
* References:
* http://graphics.stanford.edu/~mdfisher/subdivision.html
* http://www.holmes3d.net/graphics/subdivision/
* http://www.cs.rutgers.edu/~decarlo/readings/subdiv-sg00c.pdf
@zz85
zz85 / ParametricGeometry2.js
Last active August 29, 2015 13:56
Exploring ParametricGeometry2
/**
* @author zz85 / https://github.com/zz85
* Parametric Surfaces Geometry
* based on the brilliant article by @prideout http://prideout.net/blog/?p=44
*
* new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
*
*/
THREE.ParametricGeometry2 = function ( func, slices, stacks ) {
@zz85
zz85 / toon.js
Created March 11, 2014 23:30
Toon Pixel Shader (for Three.js Composer)
<script id="toon" type="frag/shader">
// Based on http://coding-experiments.blogspot.sg/2011/01/toon-pixel-shader.html
uniform float width;
uniform float height;
uniform sampler2D tDiffuse;
varying vec2 vUv;
#define HueLevCount 6
#define SatLevCount 7
@zz85
zz85 / gist:10542662
Created April 12, 2014 15:54
Coefficients Generation for Optimized Gaussian Blurs using Linear Sampling
/*
* @author zz85 / https://github.com/zz85
*
* Related Readings
*
* http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/
* http://www.sunsetlakesoftware.com/2013/10/21/optimizing-gaussian-blurs-mobile-gpu
* http://xissburg.com/faster-gaussian-blur-in-glsl/
* https://github.com/manuelbua/blur-ninja
*
@zz85
zz85 / mrdoob.json
Last active February 22, 2020 17:49
mrdoob style guide with jscs config
{
"requireCurlyBraces": ["while", "do", "try", "catch"],
"requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"],
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requirePaddingNewlinesInBlocks": true,
"requireSpacesInsideObjectBrackets": "all",
"requireSpacesInsideArrayBrackets": "allButNested",
"requireSpaceBeforeBlockStatements": true,
@zz85
zz85 / cssRule.js
Created June 27, 2014 16:18
Easy way for creating and modifying CSS Rules in JS
if (!document.styleSheets.length) document.head.appendChild(document.createElement('style'));
var sheet = document.styleSheets[document.styleSheets.length - 1];
var rules = {};
function cssRule(selector, styles) {
var index;
if (selector in rules) {
index = rules[selector];
sheet.deleteRule(index);
} else {
index = rules[selector] = sheet.cssRules.length;
@zz85
zz85 / mem.js
Last active August 29, 2015 14:05
Print Memory
function format_numbers(n) {
return (n / 1024 / 1024).toFixed(3) + 'MB';
}
function mem() {
if (performance && performance.memory) {
console.log('used heap', format_numbers(performance.memory.usedJSHeapSize))
console.log('total heap', format_numbers(performance.memory.totalJSHeapSize))
console.log('heap limit', format_numbers(performance.memory.jsHeapSizeLimit))
}