-
Notifications
You must be signed in to change notification settings - Fork 2
/
crystallize.pbk
63 lines (55 loc) · 2.08 KB
/
crystallize.pbk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// - please send me a note if you use the code for anything cool !
//
<languageVersion : 1.0;>
kernel Crystallize
< namespace : "by Petri Leskinen";
vendor : "";
version : 1;
description : "Crystallize -filter";
>
{
parameter float size
<
minValue: float(1);
maxValue: float(300);
defaultValue: float(20);
description: "size";
>;
input image4 src;
output pixel4 dst;
// rot1: rotation matrix, 18 degrees
// rot1r: reverse rotation, -18 degrees
// base1: rotation base point (somewhere far enough from origin)
const float2x2 rot1 = float2x2(0.951,0.309,-0.309,0.951);
const float2x2 rot1r = float2x2(0.951,-0.309,0.309,0.951);
const float2 base1= float2(2400,-100);
// rot2: rotation matrix, 30 degrees
// rot2r: reverse rotation, -30 degrees
// base2: base point
const float2x2 rot2 = float2x2(0.866,0.5,-0.5,0.866); // 30 degress
const float2x2 rot2r = float2x2(0.866,-0.5,0.5,0.866);
const float2 base2= float2(-100,2400);
void
evaluatePixel()
{
// Crystallize, pseudo Voronoi-diagram using three nearby points,
// calculated from 'randomly' placed and rotated rectangular grids
// 1st grid and point
float div=size;
float2 newP= base1 + rot1r*div*( floor( rot1*(outCoord()-base1)/div ) +0.5);
// 2nd grid
div= 21.0/20.0*size; // factor 21, I picked some number that has no common denominators with the default size 20
float2 p= base2 + rot2r*div*( floor( rot2*(outCoord()-base2)/div ) +0.5);
// comparing distance to the 1st sample point
newP = length(p-outCoord()) < length(newP-outCoord()) ? p : newP;
// 3rd grid
div= 19.0/20.0*size;
p= div*( floor( outCoord()/div ) +0.5);
// comparing distance
newP = length(p-outCoord()) < length(newP-outCoord()) ? p : newP;
// the new color is picked from the nearist point
dst = sampleNearest(src,newP);
}
}