Skip to content

Instantly share code, notes, and snippets.

vec2 pack16(float value){
float f = clamp(value, 0.0, 1.0)*255.0;
float digitLow = fract(f);
float digitHigh = floor(f)/255.0;
return vec2(digitHigh, digitLow);
}
float unpack16(vec2 value){
return value.x+value.y/255.0;
}
@pyalot
pyalot / checker-sphere.glsl
Created March 3, 2015 13:28
anti-aliased checker-sphere procedural glsl pattern
float checkerSphere(){
vec3 normal = normalize(vNormal);
float c = (acos(normal.y)/PI)*20.0;
float dc = fwidth(c);
c = mod(c, 2.0);
c = smoothstep(0.5-dc, 0.5+dc, c) - smoothstep(1.5-dc, 1.5+dc, c);
vec2 dir = normalize(normal.xz);
float t = (atan(dir.x, dir.y)/TAU)*40.0;
float dt = fwidth(t);
@pyalot
pyalot / gist:123e0ebe5de3969f943c
Created March 26, 2015 21:32
environment prefiltering
float lambertNDF(vec3 normal, vec3 dir, float roughness){
float exponent = getLambertExponent(roughness*PI*0.5);
float lambert = max(0.0, dot(normal, dir));
return pow(lambert, exponent);
}
float ggxNDF(vec3 normal, vec3 dir, float roughness){
float a = roughness*roughness;
float d = max(0.000001, dot(normal, dir));
@pyalot
pyalot / gist:a6f3f3bf1921339ac842
Created March 27, 2015 20:41
simple physically inspired shading function
vec3 shade(vec3 color, float roughness, float metallness){
float fresnelFactor = 0.93;
float specularFactor = 0.65;
vec3 normal = normalize(vNormal);
vec3 eyeDir = getEyeDir();
vec3 N = normal;
vec3 V = -eyeDir;
vec3 reflected = reflect(eyeDir, normal);
@pyalot
pyalot / gist:05f5007b6826342621a8
Created April 2, 2015 08:34
state assembly test
createState: (framebuffer, code) ->
@fw.state
cull: 'back'
shader: [
fs.open('/pbr-tools.shader')
fs.open('tools.shader')
"""essl
fragment:
void main(){
#{code}
@pyalot
pyalot / base64decode.coffee
Created January 14, 2013 13:44
Coffeescript efficient base64 decode to typed array.
decodingTable = new Uint8Array(256)
for c, i in 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
decodingTable[c.charCodeAt(0)] = i
base64decode = (string) ->
last = string[string.length-2...string.length]
if last == '=='
remainder = 2
else if last[1] == '='
remainder = 1
@pyalot
pyalot / gist:5929967
Created July 4, 2013 20:10
Masking javascript globals
maskEval = (src) ->
whitelist = ['Math', 'performance']
names = []
for name of window
if name not in whitelist
names.push name
names = names.join(',')
return eval("(function(){var #{names};return #{src};})").call({})
@pyalot
pyalot / countFiles
Created August 24, 2013 06:37
Counts all files in the current directory recursively for each contained directory and outputs the count and directory name sorted numerically.
#!/usr/bin/env bash
function countFiles {
for i in $(pwd)/* ; do
if [ -d "$i" ]; then
echo $(find $i -type f | wc -l) $i
fi
done
}
@pyalot
pyalot / gist:6474434
Last active December 22, 2015 12:48
ubuntu 13.04 install script for gtx-780 and cyborg rat9 mouse
## create backup of home! ##
## part 1 before reboot, update system ##
apt-get update
apt-get upgrade
shutdown -r now
## part 2 after first reboot install nvidia driver that works ##
apt-add-repository ppa:ubuntu-x-swat/x-updates
apt-get update
@pyalot
pyalot / client-side.coffee
Last active December 24, 2015 09:18
ESSL shader error instrumentation
preprocess: (source) ->
lines = []
result = []
filename = 'no file'
lineno = 1
for line in source.split('\n')
match = line.match /#line (\d+) (.*)/
if match
lineno = parseInt(match[1], 10)+1
filename = match[2]