Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
#define C (7.0/13.0*A)
#define D (0.4*B)
#define E (0.1*C)
#define F E
#define G (1.0/12.0*D)
#define H G
#define L (1.0/13.0*A)
#define K (0.8*L)
const ivec2 DIMENSIONS = ivec2(1235, 650);
glsl float star(vec2 pos, float radius) {
float total = 0.0;
for (int i = 0; i < 5; ++i) {
float a1 = TAU/5.0*float(i);
float a2 = TAU/5.0*float(i-2);
vec2 p1 = radius*vec2(sin(a1), cos(a1));
vec2 p2 = radius*vec2(sin(a2), cos(a2));
total += halfPlaneSmooth(pos, p1, p2, A*shadron_PixelSize.y);
}
return clamp(total-3.0, 0.0, 1.0);
}
glsl float starPreview(vec2 coord) {
return star(coord-0.5, 0.5);
}
image Star = glsl(starPreview, 256, 256);
glsl float starPattern(vec2 pos, vec2 offset, vec2 size) {
pos = clamp(pos-offset, vec2(0.0), size);
pos = mod(pos, 2.0*vec2(H, F));
return star(pos-vec2(G, E), 0.5*K);
}
glsl float starPatternPreview(vec2 pos) {
return starPattern(pos, vec2(0.0), vec2(D, C));
}
image StarPattern = glsl(starPatternPreview, 512);
glsl vec3 usFlag(vec2 coord) {
vec2 pos = vec2(B, A)*coord;
if (pos.x < D && pos.y > A-C) {
float stars = starPattern(pos, vec2(0.0, A-C), vec2(D, C)) +
starPattern(pos, vec2(H, A-C+F), vec2(D, C)-2.0*vec2(H, F));
return mix(BLUE, WHITE, stars);
}
float stripe = step(L, mod(pos.y, 2.0*L));
return mix(RED, WHITE, stripe);
}
image Flag = glsl(usFlag, DIMENSIONS);
image Reference = file();
param float diffFactor = 1.0 : logrange(1.0, 256.0);
glsl vec3 diff(vec2 p) {
return diffFactor*abs(texture(Flag, p).rgb-texture(Reference, p).rgb);
}
image Difference = glsl(diff, sizeof(Flag));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.