Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Flexi23
Flexi23 / gist:1713774
Created January 31, 2012 23:27
GLSL 2D vector buffer in a texture with a custom floating point precision
/*
These are the helper functions to store and to restore a 2D vector with a custom 16 floating point precision in a texture.
The 16 bit are used as follows: 1 bit is for the sign, 4 bits are used for the exponent, the remaining 11 bit are for the mantissa.
The exponent bias is asymmetric so that the maximum representable number is 2047 (and bigger numbers will be cut)
the accuracy from 1024 - 2047 is one integer
512-1023 it's 1/2 int
256-511 it's 1/4 int and so forth...
between 0 and 1/16 the accuracy is the highest with 1/2048 (which makes 1/32768 the minimum representable number)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Polar Coordinate Montage for Equirectangulars</title>
<script type="text/javascript" src="dat.gui.min.js"></script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aPos;
attribute vec2 aTexCoord;
varying vec2 uv;
void main(void) {
<html>
<head>
<title>Lemniscate Panorama Configurator</title>
<script type="text/javascript" src="dat.gui.min.js"></script>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aPos;
attribute vec2 aTexCoord;
varying vec2 uv;
void main(void) {
gl_Position = vec4(aPos, 1.);
@Flexi23
Flexi23 / gist:1585608
Created January 9, 2012 23:26
mapping vec4 rgba to higher precision vec2 in glsl (texture as vector field)
// GLSL fragment shader code to store and restore signed 15bit fixed point 2D vector in a normalized color value
// red and green are mapped to horizontal, blue and alpha to vertical
// the most significant bit is used as signum
// maximum velocity is 128 (7bit), overall accuracy is 1/256 (8bit)
// by Felix Woitzel (@Flexi23) Jan. 2012
// velocity vector to color value
vec4 encode(vec2 v){
vec4 rgba;
@Flexi23
Flexi23 / kinectv2HDFaceMeshTriangleIndices.js
Last active January 22, 2017 14:43
the static triangle indices of the hd face model's 1347 vertices
// https://msdn.microsoft.com/en-us/library/microsoft.kinect.kinectsensor.aspx
// https://msdn.microsoft.com/en-us/library/microsoft.kinect.bodyframereader.aspx
// https://msdn.microsoft.com/en-us/library/microsoft.kinect.body.aspx
// https://msdn.microsoft.com/en-us/library/microsoft.kinect.face.highdefinitionfaceframesource.aspx
// https://msdn.microsoft.com/en-us/library/microsoft.kinect.face.facemodel.aspx
// https://msdn.microsoft.com/en-us/library/microsoft.kinect.face.facealignment.aspx
// In C#, you obtain a face mesh with 1347 xyz vertices like
// var vertices = currentFaceModel.CalculateVerticesForAlignment(currentFaceAlignment);
// this array gets serialized to JSON and sent over WebSockets to a Javascript callback function
@Flexi23
Flexi23 / async-tsv-parser.js
Created September 13, 2016 21:24
Web Worker using Transferable ArrayBuffers with Float32 views to parse a tab separated value file. The first lines is expected to contain the titles. Also returns the global minimum, maximum, and average value per column.
onmessage = function(e) {
var arrayBuffers = [];
var float32Arrays = [];
var titles = [];
var reader = new FileReader();
reader.onload = function (progressEvent) {
var before = Date.now();
var lines = this.result.split('\n');
var endsWithNewLine = (lines[lines.length - 1] != "");
var statshtml = (lines.length - (endsWithNewLine ? 2 : 1)) + " samples loaded<br />";
@Flexi23
Flexi23 / flexi23faceMeshVertices.js
Created April 22, 2016 22:02
kinect v2 hd face builder data selfie
// [1347 * x, y, z]
var flexi23faceMeshVertices = [0.2134659,-0.005705297,0.722433,0.212817,-0.005387768,0.715305,0.2110647,-0.004223038,0.6984677,0.210155,-0.001397155,0.6876884,0.2101493,0.007630821,0.6790485,0.210469,0.01632698,0.6765092,0.2105639,0.02151701,0.6763196,0.2095879,0.02817391,0.6710931,0.2086814,0.02958079,0.6669077,0.2085692,0.03584543,0.6644162,0.2084697,0.04021845,0.6644133,0.2140796,0.1107494,0.657635,0.2114608,0.09714016,0.6507787,0.2094548,0.086901,0.6454346,0.208826,0.06492373,0.6580291,0.208032,0.05635805,0.6590701,0.2141992,0.1158569,0.6558515,0.2075247,0.07235055,0.6438907,0.2078904,0.0766855,0.6428182,0.2073243,0.05117314,0.658303,0.2081483,0.06660306,0.6521292,0.2074498,0.06921467,0.6458704,0.2069485,0.04758142,0.6589133,0.2086978,0.06627298,0.6560369,0.2144605,0.1142545,0.6581195,0.2102501,0.09101541,0.6475827,0.2085661,0.08178496,0.6434384,0.2155117,0.126471,0.654993,0.2186639,0.1575005,0.651559,0.2237054,0.1912093,0.6593531,0.220874,0.1748671,0.6531846,0.2076982,0.06732301,0.648
@Flexi23
Flexi23 / potleaf.glsl
Last active August 29, 2015 14:01 — forked from glslioadmin/TEMPLATE.glsl
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
void main() {
vec2 uv = gl_FragCoord.xy / resolution.xy;
vec2 leaf_uv = (uv - vec2(0.5))/10./pow(progress,3.5);