Skip to content

Instantly share code, notes, and snippets.

@Chlumsky
Chlumsky / cogwheels.shadron
Created October 30, 2016 21:44
Shadron Cogwheels Tutorial
#include <math_constants>
#include <multisample>
glsl struct Cogwheel {
vec2 center;
float r;
int teeth;
float toothSize;
float toothShape;
@Chlumsky
Chlumsky / msdf-preview.shadron
Last active August 27, 2021 07:41
MSDF Preview
#include <math_constants>
#include <median>
#include <billboard>
#include <affine_transform>
glsl float linearStep(float a, float b, float x) {
return clamp((x-a)/(b-a), 0.0, 1.0);
}
#define PLOT_SAMPLES 3
template <FN, XMIN, XMAX, YMIN, YMAX, XGRID, YGRID>
glsl vec4 plot(vec2 pos) {
vec2 tPos = vec2(
mix(float(XMIN), float(XMAX), pos.x),
mix(float(YMIN), float(YMAX), pos.y)
);
vec2 pxSize = vec2((XMAX)-(XMIN), (YMAX)-(YMIN))*shadron_PixelSize;
#include "plot.shadron"
image Input = file("julia.png") : map(clamp);
#define PXSIZE shadron_PixelSize
param int STEPS = 8;
param float SIGMA = 1;
param float blurRange = 8 : range(256);
#include <math_constants>
#include <affine_transform>
#include <lighting>
param int sides = 3 : logrange(3, 12);
param float zRotation : range(-PI, PI);
param float xRotation : range(-PI, PI);
glsl struct FragmentData {
#include <billboard>
#include <perlin>
#include <hsv>
param float OPACITY = 0.25;
glsl struct ParticleData {
vec2 position;
float phase;
#include <math_constants>
#include <shapes>
const vec3 WHITE = vec3(1.0, 1.0, 1.0);
const vec3 RED = vec3(0.698, 0.132, 0.203);
const vec3 BLUE = vec3(0.234, 0.233, 0.430);
#define A 1.0
#define B 1.9
glsl {
// Signed distance from half-plane defined by oriented line segment (a, b)
float halfPlaneDistance(vec2 pos, vec2 a, vec2 b) {
return dot(normalize(vec2(b.y-a.y, a.x-b.x)), a-pos);
}
// Anti-aliased half-plane defined by oriented line segment (a, b)
float halfPlaneSmooth(vec2 pos, vec2 a, vec2 b, float border) {
#include <math_constants>
image Input = file("maze.png");
glsl vec4 initialState(vec2 pos) {
vec4 input = texture(Input, pos);
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
// Detect starting point
if (input.g > 0.5 && input.r + input.b < 1.0)
@Chlumsky
Chlumsky / aztec-diamond-animation.shadron
Created December 29, 2020 00:51
Aztec Diamond Smooth Animation
#if !defined(SHADRON_VERSION) || SHADRON_VERSION < 140
#error This script requires Shadron 1.4 or later
#endif
#include <rng>
#include <shapes>
#include <linearstep>
////////////////////////////////////////////////////////////////