Skip to content

Instantly share code, notes, and snippets.

View binarycrusader's full-sized avatar

Shawn Walker-Salas binarycrusader

View GitHub Profile
@mbrochh
mbrochh / gist:964057
Last active November 10, 2021 19:08
Fast Forward Your Fork
# kudos to https://github.com/drewlesueur
# stolen from here: https://github.com/blog/266-fast-forward-your-fork#comment-11535
git checkout -b upstream-master
git remote add upstream git://github.com/documentcloud/underscore.git
git pull upstream master
git checkout master // [my master branch]
git merge upstream-master
git push origin master
@jawa0
jawa0 / loadTexture.py
Created November 2, 2012 17:39
Use the Python Imaging Library (PIL), and NumPy to read an image into an OpenGL texture
from OpenGL.GL import *
import Image
import numpy
imname = 'uv-grey.jpg'
# glTexImage2D expects the first element of the image data to be the bottom-left corner of the image.
# Subsequent elements go left to right, with subsequent lines going from bottom to top.
#
# However, the image data was created with PIL Image tostring and numpy's fromstring, which means we
@transitive-bullshit
transitive-bullshit / billboard_sao.frag
Created September 30, 2013 21:08
WebGL GLSL SAO (Scalable Ambient Obscurance) fragment shader. SAO is a more efficient method for computing SSAO (Screen-Space Ambient Occlusion). Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. For details on the technique itself, see: McGuire et al [12] http://graphics.cs.wi…
// total number of samples at each fragment
#define NUM_SAMPLES {{ numSamples }}
#define NUM_SPIRAL_TURNS {{ numSpiralTurns }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
#define VARIATION {{ variation }}
uniform sampler2D sGBuffer;
@transitive-bullshit
transitive-bullshit / billboard_hbao.frag
Created September 30, 2013 21:10
WebGL GLSL HBAO (Horizon-Based Ambient Occlusion) fragment shader. HBAO is a higher quality approach for computing SSAO (Screen-Space Ambient Occlusion) developed by Nvidia in 2008. Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. Specifically, the technique views the depth bu…
// number of directions to sample in UV space
#define NUM_SAMPLE_DIRECTIONS {{ numSampleDirections }}
// number of sample steps when raymarching along a direction
#define NUM_SAMPLE_STEPS {{ numSampleSteps }}
#define APPLY_ATTENUATION {{ attenuation }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
@transitive-bullshit
transitive-bullshit / billboard_ssao.frag
Created September 30, 2013 21:12
WebGL GLSL SSAO (Screen-Space Ambient Occlusion) fragment shader. Converts the g-buffer to an occlusion buffer which estimates local ambient occlusion at each fragment in screen-space. This SSAO version uses per-fragment depth and normal data to integrate local visibility over a normal-oriented hemisphere in world space by comparing the linear d…
#define SAMPLE_COUNT {{ sampleCount }}
#define USE_ACTUAL_NORMALS {{ useActualNormals }}
uniform sampler2D sGBuffer;
uniform sampler2D sNoise;
uniform float uSampleRadius;
uniform float uIntensity;
uniform vec2 uNoiseScale;
uniform vec3 uKernel[SAMPLE_COUNT];
@rygorous
rygorous / glx.cpp
Created December 9, 2013 01:28
GLX
GLuint glx_compile_shader_source( GLenum type, char const * source )
{
if ( !source )
return 0;
// explicitly copy the source together so we can dump it as one string
size_t source_len = strlen( source );
char * fused_source = new char[shader_header_len + source_len + 1];
strcpy( fused_source, shader_header );
strcpy( fused_source + shader_header_len, source );
@rygorous
rygorous / d3dcompiler.cpp
Last active December 31, 2015 04:39
Using Win8 d3dcompiler without using Platform SDK headers for everything
// Okay, the Win8 version of d3dcompiler.dll is *substantially* faster to compile
// shaders, but switching to the Win8 SDK outright is painful if you need to
// support older compilers (the new headers don't work with old VC++ versions)
// or use D3DX.
//
// However, there's a dead simple solution that works just fine.
// Just link against June 2010 DX SDK d3dcompiler.lib and use its header files,
// then do this:
typedef HRESULT (__stdcall d3d_compile_func)(LPCVOID pSrcData, SIZE_T SrcDataSize, LPCSTR pSourceName, const D3D_SHADER_MACRO *pDefines, ID3DInclude *pInclude, LPCSTR pEntrypoint, LPCSTR pTarget, UINT Flags1, UINT Flags2, ID3DBlob **ppCode, ID3DBlob **ppErrorMsgs);
@castano
castano / hemicube.cpp
Created June 20, 2014 09:46
Hemicube Integrator
#include "hemicube.h"
#define PACK_HEMICUBES 1
static void get_hemicube_face_normal(int index, Vector3 *forward, Vector3 *left, Vector3 *up) {
// Unwrapped hemicube with positive-Z in the middle.
switch (index) {
case 0: *forward = Vector3(+1, 0, 0); *left = Vector3( 0, 1, 0); break;
@patriciogonzalezvivo
patriciogonzalezvivo / GLSL-Noise.md
Last active July 24, 2024 14:58
GLSL Noise Algorithms

Please consider using http://lygia.xyz instead of copy/pasting this functions. It expand suport for voronoi, voronoise, fbm, noise, worley, noise, derivatives and much more, through simple file dependencies. Take a look to https://github.com/patriciogonzalezvivo/lygia/tree/main/generative

Generic 1,2,3 Noise

float rand(float n){return fract(sin(n) * 43758.5453123);}

float noise(float p){
	float fl = floor(p);
  float fc = fract(p);
One of the primary benefits of using a fixed-width
programming font is that things line up in columns
if they are the same length in characters. (Please
note that monospacing is not just for indentation;
indentation works fine with proportional fonts. It
is only once you have a non-blank character on the
line that proportional vs. monospace differ much.)
In my experience, lining code up so features align
vertically makes it a lot easier to avoid the bugs