Skip to content

Instantly share code, notes, and snippets.

@SpineyPete
SpineyPete / tonemappers.glsl
Last active November 2, 2023 13:20
Tonemappers
#version 330
// Tonemapping
// -----------
// Some of these are attributed to certain games.
// But this is mostly secondhand info, so take it with a grain of salt.
vec3 Tonemap_Reinhard(vec3 x) {
// Simplest Reinhard tonemapper.
@SpineyPete
SpineyPete / colorspaces.glsl
Last active June 9, 2017 13:57
Colorspace Conversions
#version 330
// Colorspace conversions, I haven't checked the validity of this stuff.
// Some of them cause discolorations when transformed to and back so I'm
// probably doing wrong things that I don't understand -- Caveat emptor.
// CIELab XYZ
// ----------
// Matrices borrowed from Fundamentals Of Computer Graphics (3rd edition).
@SpineyPete
SpineyPete / phong_metal.glsl
Created July 28, 2017 12:13
Metallic BRDF
float PhongBase(vec3 viewdir, vec3 lightdir, vec3 normal) {
return max(-dot(viewdir, reflect(lightdir, normal)), 0.0);
}
// Analytic specular without ambient specular might look better like this.
float HalfPhongBase(vec3 viewdir, vec3 lightdir, vec3 normal) {
return -dot(viewdir, reflect(lightdir, normal)) / 2 + 0.5;
}
// Something to approximate the longer tail
@SpineyPete
SpineyPete / hdr_crosstalk.glsl
Last active October 27, 2017 01:02
Crosstalk
// Crosstalk makes HDR highlights tend towards white.
// This is more realistic and maintains definition in overexposed areas.
// --
// Threshold is the point at which the desaturation kicks in.
// Shallowness is the rate at which the color reaches pure white.
// Higher Shallowness values create a slower rise.
vec3 Crosstalk(vec3 color, float threshold, float shallowness) {
// Luminosity
float luma = color.r * 0.299 + color.g * 0.587 + color.b * 0.114;
// sRGB to/from linear-space conversions, by Ian Taylor
// source: http://chilliant.blogspot.be/2012/08/srgb-approximations-for-hlsl.html
// Alternate LinearToGamma(), without pow():
// srgb = 0.585122381 * sqrt(linear) +
// 0.783140355 * sqrt(sqrt(linear)) -
// 0.368262736 * sqrt(sqrt(sqrt(linear)));
vec3 LinearToGamma(in vec3 linear) {
return max(1.055f * pow3(linear, 0.416666667f) - 0.055f, 0);
// Makes text funky.
"use strict";
function funkyType(selector, args) {
function limitDecimals(n, decimals) {
decimals = Math.pow(10, decimals);
return Math.trunc(n * decimals) / decimals;
}
@SpineyPete
SpineyPete / gist:0f2ae2bbfe7a222f01158c14a6279890
Created December 4, 2018 19:35
Adaptively Subdivided Fan (Processing 3.0)
PVector clickPos = new PVector(0, 0);
PVector clickRadi = new PVector(100, 100);
void angler(
PVector arcPos, float arcRadi, float arcTurn, PVector arcDir,
float stepSize, boolean fixStep) {
float halfAngle = PI*arcTurn;
float totalAngle = TAU*arcTurn;
float totalSteps = totalAngle*arcRadi/stepSize;
@SpineyPete
SpineyPete / fibonacci.c
Created January 5, 2019 17:51
fibonacci number formula (untested)
double fib(int n) {
const double sqrt5 = sqrt(5);
const double phi_a = (1 + sqrt5)/2;
const double phi_b = (1 - sqrt5)/2;
return (pow(phi_a, n) - pow(phi_b, n))/sqrt5;
}
@SpineyPete
SpineyPete / hemisphere_concentric.pde
Last active April 11, 2022 18:40
Concentric Hemisphere Point Generator (Processing 3 Sketch)
// Visualization of Shirley and Chui's Concentric Mapping
// projected onto a hemisphere -- e.g. for irradiance tracing.
// The points are drawn to the window and C code is output to the console.
// This import is needed since Processing 4.
// In Processing complains about it not finding it:
// In the menubar go to to sketch -> import library -> add library,
// enter javafx in the searchbox and download it.
import processing.javafx.*;
@SpineyPete
SpineyPete / grid.styl
Last active October 6, 2019 14:32
Stylus Flexbox Grid System
// -------
// Globals
// -------
pagewidth = 50rem
hgap = 1rem
vgap = 1rem
// ----------------
// Utlity Functions