Skip to content

Instantly share code, notes, and snippets.

@pyalot
pyalot / octahedral.shader
Last active December 17, 2023 19:51
octahedral mapping
#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{
@pyalot
pyalot / gist:5171175
Last active September 25, 2019 22:27
Minecraft mca/nbt parser
from struct import unpack
from zlib import decompress
class BufferStream:
def __init__(self, data):
self.pos = 0
self.data = data
def get(self, amount):
result = self.data[self.pos:self.pos+amount]
@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]
@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 / 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: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 / 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: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 / 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: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));