Skip to content

Instantly share code, notes, and snippets.

@pyalot
pyalot / octahedral.shader
Last active Apr 4, 2019
octahedral mapping
View octahedral.shader
#define sectorize(value) step(0.0, (value))*2.0-1.0
#define sum(value) dot(clamp((value), 1.0, 1.0), (value))
#define PI 3.141592653589793
vec2 normalToUvRectOct(vec3 normal){
normal /= sum(abs(normal));
if(normal.y > 0.0){
return normal.xz*0.5+0.5;
}
else{
View gist:05f5007b6826342621a8
createState: (framebuffer, code) ->
@fw.state
cull: 'back'
shader: [
fs.open('/pbr-tools.shader')
fs.open('tools.shader')
"""essl
fragment:
void main(){
#{code}
@pyalot
pyalot / gist:a6f3f3bf1921339ac842
Created Mar 27, 2015
simple physically inspired shading function
View gist:a6f3f3bf1921339ac842
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:123e0ebe5de3969f943c
Created Mar 26, 2015
environment prefiltering
View gist:123e0ebe5de3969f943c
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 / checker-sphere.glsl
Created Mar 3, 2015
anti-aliased checker-sphere procedural glsl pattern
View checker-sphere.glsl
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);
View 16-byte packing GLSL
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 / client-side.coffee
Last active Dec 24, 2015
ESSL shader error instrumentation
View client-side.coffee
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]
@pyalot
pyalot / gist:6474434
Last active Dec 22, 2015
ubuntu 13.04 install script for gtx-780 and cyborg rat9 mouse
View gist:6474434
## 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 / countFiles
Created Aug 24, 2013
Counts all files in the current directory recursively for each contained directory and outputs the count and directory name sorted numerically.
View countFiles
#!/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:5929967
Created Jul 4, 2013
Masking javascript globals
View gist:5929967
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({})