Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / main.glsl
Created October 27, 2026 14:24
4D apollo for synesthesia
#define ROT(p)p=Q*dot(Q,p)+cross(Q,p)
// License: Unknown, author: Claude Brezinski, found: https://mathr.co.uk/blog/2017-09-06_approximating_hyperbolic_tangent.html
vec4 tanh_approx(vec4 x) {
// Found this somewhere on the interwebs
// return tanh(x);
vec4 x2 = x*x;
return clamp(x*(27.0 + x2)/(27.0+9.0*x2), -1.0, 1.0);
}
@mrange
mrange / -README-.md
Last active October 25, 2026 17:33
Vertex Shader Example

LINES Multipass Audio Reactive shader

These shaders are designed to be used with kodelife.

Pass 0,2,3,4 are normal full fragment shader setups (ie orthographic projection) Pass 1 uses Perspective projection.

Passes file are prefixed with it's position in the pipeline, 0 coming before 1 and so on. They are suffixed with either _vs or _fs indicating if it's a vertex shader or fragement shader.

Passes might take other passes output as input.

@mrange
mrange / tic80.lua
Last active September 21, 2026 19:34
TIC80 music
pos=0
local abs = math.abs
local exp2 = function(x) return 2.0 ^ x end
local sin = math.sin
local mod = function(a, b) return a - math.floor(a / b) * b end -- GLSL mod (always positive)
local function music(t1)
local a3 = 0.0
for i1 = 1, 4 do
@mrange
mrange / neworder.js
Last active September 12, 2026 17:04
Strudel effect
/*
@title EffectTime testing
@by mrange
*/
class EffectTime {
constructor() {
this.time=0;
this.n=0;
this.lastOnset=-1;
@mrange
mrange / truchet..js
Last active September 12, 2026 10:46
Custom hydra effect
// https://hydra.ojack.xyz/
setFunction({
name: 'truchet',
type: 'src',
inputs: [
{
type: 'float',
name: 'T',
default: 0.,
@mrange
mrange / hydra.js
Last active September 10, 2026 17:29
Green Apollo
// https://hydra.ojack.xyz/
setFunction({
name: 'greenapollo',
type: 'src',
inputs: [
{
type: 'float',
name: 't',
default: 0,
@mrange
mrange / hydra.js
Last active September 7, 2026 19:47
My first hydra-hack
// https://hydra.ojack.xyz/
setFunction({
name: 'hack',
type: 'src',
inputs: [],
glsl:
`
vec2 P=2.*_st-1.;
P.x*=resolution.x/resolution.y;
@mrange
mrange / README.md
Last active September 6, 2026 09:08
Snippets for shader devs

Snippets for shader devs

⚠️ All text content on this blog is licensed under CC BY-SA 4.0. All code is licensed under CC0. ⚠️

All code assumes shadertoy environment:

// O - output color
// C - pixel coordinate
// iResolution - vec3 uniform containing the resolution, .z is 1 when generating 2D fragments.
void mainImage(out vec4 O, vec2 C) {
@mrange
mrange / main.c
Last active February 24, 2026 12:50
Obfuscated C experiment: Nothing special
#define _GNU_SOURCE
#include<math.h>
#include<sys/ioctl.h>
#define V for(n=0;n<3;++n)
#define F c+=sprintf(b+c,
//////////////////////////////////////
// "Nothing Special"-Posix version ///
// by mrange 2026-02-22 ////
// // //
// Compile and run with: // //
@mrange
mrange / Program.cs
Created February 21, 2026 11:51
Spectre Playground Effect
// "Nothing Special" shader by Mårten Rånge
var terminal = new BrowserTerminal(
AnsiConsole.Console,
AnsiConsole.Profile.Width,
AnsiConsole.Profile.Height);
var renderer = new Renderer(terminal);
var writer = AnsiConsole.Profile.Out.Writer;
writer.Write("\x1b[?25l"); // Hide cursor