Skip to content

Instantly share code, notes, and snippets.

View caiwan's full-sized avatar
🐺

Caiwan caiwan

🐺
View GitHub Profile
vec4 packDepth(const in float depth) {
const vec4 bit_shift = vec4( 256.0*256.0*256.0, 256.0*256.0, 256.0, 1.0);
const vec4 bit_mask = vec4( 0.0, 1.0/256.0, 1.0/256.0, 1.0/256.0);
vec4 res = fract(depth * bit_shift);
res -= res.xxyz * bit_mask;
return res;
}
float unpackDepth(const in vec4 rgba_depth) {
const vec4 bit_shift = vec4(1.0/(256.0*256.0*256.0), 1.0/(256.0*256.0), 1.0/256.0, 1.0);
@caiwan
caiwan / colorspace.inc.glsl
Created May 8, 2015 10:42
2D Effect library of code snippets (Shadertoy:https://www.shadertoy.com/view/ldSXzt)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// *** COLOR TRANSFORMATION ***
//http://beesbuzz.biz/code/hsv_color_transforms.php
vec3 rgb2yiq(vec3 color){return color * mat3(0.299,0.587,0.114,0.596,-0.274,-0.321,0.211,-0.523,0.311);}
vec3 yiq2rgb(vec3 color){return color * mat3(1.,0.956,0.621,1,-0.272,-0.647,1.,-1.107,1.705);}
// Direkt HSV transzformacio
vec3 hsvTransform(vec3 color, vec3 hsv){float _h = hsv.x, _s = hsv.y, _v = hsv.y; float VSU = _v*_s*cos(_h*PI/180.), VSW = _v*_s*sin(_h*PI/180.), rr = (.299*_v+.701*VSU+.168*VSW)*color.x + (.587*_v-.587*VSU+.330*VSW)*color.y + (.114*_v-.114*VSU-.497*VSW)*color.z, gg = (.299*_v-.299*VSU-.328*VSW)*color.x + (.587*_v+.413*VSU+.035*VSW)*color.y + (.114*_v-.114*VSU+.292*VSW)*color.z, bb = (.299*_v-.300*VSU+1.25*VSW)*color.x + (.587*_v-.588*VSU-1.05*VSW)*color.y + (.114*_v+.886*VSU-.203*VSW)*color.z; return vec3(rr,gg,bb); }
@caiwan
caiwan / loader.inc.cpp
Last active August 29, 2015 14:20
Farbrausch-like loaderbar in a single shader
namespace {
//works!
///@return 0 if everything succeeds 1 otherwise (or throw an exception)
int initLoader(){
this->loader.s_loader= new FWrender::Shader();
this->loader.s_loader->createFromMemory( /* create(&vss, &fss) */
"#version 330 core\n"
"layout(location = 0) in vec3 "SHADER_ATTRIB_VERTEX";"
"void main(){"
"gl_Position = vec4("SHADER_ATTRIB_VERTEX",1.);"
@caiwan
caiwan / distantfunctions.inc.glsl
Last active November 13, 2017 21:22
Raymarch stuff
//http://iquilezles.org/www/articles/distfunctions/distfunctions.htm
// -- Distant functions
float sdPlane( vec3 p ) {return p.y+0.2;}
float sdSphere( vec3 p, float s ) {return length(p)-s;}
float sdCylinder( vec3 p, vec3 c ){ return length(p.xz-c.xy)-c.z; }
float udRoundBox( vec3 p, vec3 b, float r ){return length(max(abs(p)-b,0.0))-r;}
float udRoundBoxInf( vec3 p, vec2 b, float r ){return length(max(vec3(abs(p.xz)-b,0.0),0.0))-r;}
float maxcomp( vec3 p ) {return max(p.x,max(p.y,p.z));}
@caiwan
caiwan / stub.ahk
Created June 2, 2015 08:58
Autohotkey stub
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Description goez here
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; exit by typing 'qqq'
:*:qqq::
{
exitapp 0
}
IHR stands for interpolated HiRes.
This basically interpolates two HiRes images, one in even frames, and the
other in odd frames resulting in more colors, and up to 4 colors per 8x8
block. The selection of colors are limited though: they can be a mix of the
colors selected for the two source planes. It also limits mixing that if two
colors which supposed to make the displayed color are too far from each
other, the image will noticably flicker, and will be tiring for the eye to
look at it (Mixing black and white would result in 25Hz or 30Hz pratical
update rate what is simply miserable). There are several combinations though
import sys
import xml.etree.ElementTree as ET
class XMLBuilder(object):
def __init__(self, _outfile):
self._outfile = _outfile
self._outXML = None
def __enter__(self):
@caiwan
caiwan / BKE_curve_forward_diff_bezier.c.inc
Last active November 14, 2015 10:44
Code snippetst from blender source to interpolate it's own bezier types
/* forward differencing method for bezier curve */
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride)
{
float rt0, rt1, rt2, rt3, f;
int a;
f = (float)it;
rt0 = q0;
rt1 = 3.0f * (q1 - q0) / f;
f *= f;
@caiwan
caiwan / launch.json
Created August 20, 2016 15:35
Quick and dirty VScode
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch Chrome against localhost, with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"sourceMaps": true,
"webRoot": "${workspaceRoot}/src/ts/main.ts"
@caiwan
caiwan / .vimrc
Last active June 7, 2017 13:56
vimrc for py
set encoding=utf-8
set fileencoding=utf-8
filetype plugin indent on
syntax on
set smartindent
set expandtab
set ignorecase
set smartcase