-
Notifications
You must be signed in to change notification settings - Fork 1
/
isoweave.txt
79 lines (58 loc) · 2.13 KB
/
isoweave.txt
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// xs_begin
// author : @AndyPolygon
// arg : { var = 'size' name = 'size' value = '3' range = '3 33' step = '3' precision = '0' }
// arg : { var = 'fill' name = 'fill' value = '0' range = '0 2' step = '1' precision = '0' }
// arg : { var = 'thicker' name = 'thicker' value = '0' range = '0 1' step = '1' precision = '0' }
// xs_end
//===== built-in args =====
// uniform vec3 i_volume_size; // volume size [1-256]
// uniform float i_color_index; // current color index [0-255]
// uniform int i_num_color_sels; // number of color selections [1-255]
//===== built-in functions =====
// float voxel( vec3 v ); // get voxel color index
// float color_sel( float k ); // get kth selected color index
// vec4 palette( float index ); // get palette color
//do not mix int and float without implicit conversion for older gpus!!
int fillv(vec3 v)
{
//size = how often verticals appear (size-1 gap between them)
//if thicker == 1 then double thick beams if size > 3
//fill = 0 means top isometric layer only, 1 = down to ground, 2 = just solid beams!
//select 3 colors for the 3 sets of beams
int thick = size > 3.0 && thicker > 0.0 ? 1 : 0;
int fx = int(mod(v.x,size));
int x = int(v.x/size);
int fy = int(mod(v.y,size));
int y = int(v.y/size);
if (thick > 0)
{
if (fx == thick) fx = 0;
if (fy == thick) fy = 0;
}
if (fx > 0 && fy > 0) return 0;
int z = int(v.z);
int height = (x+y)*int(size);
if (fx == 0 && fy == 0)
{
if (fill == 2.0) return 1;
if (fill == 1.0) return z <= height+thick ? 1 : 0;
int min = height - int(size);
return (z <= height+thick && z >= min) ? 1 : 0;
}
if (fill == 0.0)
return (z == height || z == height + thick) ? 1 : 0;
if (fill == 1.0 && z > height+thick) return 0;
int fz = int(mod(v.z,size)); if (fz == thick) fz = 0;
return fz == 0 ? 1 : 0;
}
float map( vec3 v )
{
float s3 = floor(size/3.0);
int c1 = fillv(v);
if (c1 == 1) return color_sel(0.0);
int c2 = fillv(v + vec3(s3,s3,s3*2.0));
if (c2 == 1) return color_sel(float(i_num_color_sels)/2.0);
int c3 = fillv(v + vec3(s3+s3,s3+s3,s3*4.0));
if (c3 == 1) return color_sel(float(i_num_color_sels));
return 0.0;
}