-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathxyz_patterns.yaml
349 lines (331 loc) · 13.3 KB
/
xyz_patterns.yaml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
styles:
### Patterns
# each pattern style should mixin `xyz_feature_attribute` (defined below), which adds an
# attribute with the name `xyz_feature` inside shader blocks
xyz_pattern_stripes:
base: polygons
mix: [xyz_feature_attribute, functions-aastep, patterns-stripes, space-screen, space-tile]
blend: inlay
# animated: true
shaders:
defines:
STRIPES_ALPHA: 0.75
STRIPES_SCALE: 2.
STRIPES_ANGLE: 0.7853981634
blocks:
color: |
color.rgb = u_pattern_color;
//vec2 st = getScreenNonStretchCoords();
vec2 st = getTileCoords() * .35;
//st.x += log(1. - xyz_feature) * u_time * .1;
color = mix(color, vec4(0.980, 0.980, 0.980, 0.25),
stripes(st*85., xyz_feature, STRIPES_ANGLE));
xyz_pattern_dash:
base: polygons
blend: inlay
mix: [xyz_feature_attribute, block, space-screen, space-tile, tiling-tile, shapes-type]
shaders:
defines:
ZOOM_START: 12.
ZOOM_END: 18.
ZOOM_IN: .0
ZOOM_OUT: 1.
DASH_SCALE: 7.
DASH_TILE_STYLE: tile
DASH_TYPE: fill
blocks:
global: |
float dashDF(vec2 st) {
return min(cos((st.x-st.y)*PI),-cos((st.x+st.y+.5)*PI*.6666)*5.);
}
color: |
vec3 dash_color = u_pattern_color;
vec3 dash_background_color = vec3(1.);
float dash_size = 1. - xyz_feature;
//vec2 st = getScreenNonStretchCoords();
vec2 st = getTileCoords();
color.rgb = mix(dash_color,
dash_background_color,
DASH_TYPE(dash_size, dashDF(DASH_TILE_STYLE(st*DASH_SCALE,3.))) );
### Add XYZ feature attribute
# adds an attribute with a normalized 0-1 value based on the current XYZ
# feature property and viz mode (range, rank, etc.)
xyz_feature_attribute:
shaders:
attributes:
xyz_feature:
type: float
uniforms:
u_pattern_color: [1, 1, 1] # RGB color to use for pattern fill
draw:
attributes:
xyz_feature: global.featureNormalizedValue
### Dependencies
functions-aastep:
doc:
author:
name: Matt DesLauriers
twitter: mattdesl
version: 0.0.1
tangram-version: 0.0.7
licence: MIT
description: |
AnitAliased ```step()``` function implemented by [Matt DesLauriers](https://twitter.com/mattdesl) in this module <https://github.com/stackgl/glsl-aastep>
shaders:
extensions: OES_standard_derivatives
blocks:
global: |
// AntiAliased Step function
//=============================
float aastep(float threshold, float value) {
#ifdef TANGRAM_FRAGMENT_SHADER
#ifdef TANGRAM_EXTENSION_OES_standard_derivatives
float afwidth = length(vec2(dFdx(value), dFdy(value))) * 0.70710678118654757;
return smoothstep(threshold-afwidth, threshold+afwidth, value);
#else
return step(threshold, value);
#endif
#else
return step(threshold, value);
#endif
}
patterns-stripes:
doc:
author:
name: Patricio Gonzalez Vivo
twitter: patriciogv
version: 0.0.1
tangram-version: 0.0.7
licence: MIT
description: |
Collection of functions to draw stripes. To learn more about patterns check [this chapter from the Book of Shaders](https://thebookofshaders.com/09/)
examples:
grain-area:
url: https://tangrams.github.io/tangram-sandbox/styles/grain-area.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/grain-area.png
lines: 26
press:
url: https://tangrams.github.io/tangram-sandbox/styles/press.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/press.png
lines: 150
radar:
url: https://tangrams.github.io/tangram-sandbox/styles/radar.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/radar.png
mix: [functions-aastep, geometry-matrices]
shaders:
defines:
PI: 3.14159265358979323846
blocks:
global: |
// Return a distance function of stripes
float stripesDF (vec2 st) {
return abs(sin(st.y*PI));
}
// Adjustable width stripes
float stripes (vec2 st, float width) {
return aastep(width, stripesDF(st));
}
// Adjustable Angle
float stripes (vec2 st, float width, float angle) {
st = rotate2D(angle) * st;
return stripes(st, width);
}
// Faster optimisation of diagonal stripes
float diagonalStripes (vec2 st) {
vec2 i_st = floor(st);
vec2 f_st = fract(st);
if (mod(i_st.y,2.) - mod(i_st.x,2.) == 0.) {
return 1.0 - aastep(f_st.x,f_st.y);
} else {
return aastep(f_st.x,f_st.y);
}
}
// Faster optimisation of diagonal stripes with controlable width
float diagonalStripes (vec2 st, float width) {
st.y -= st.x;
return stripes(st, width);
}
geometry-matrices:
doc:
author:
name: Patricio Gonzalez Vivo
twitter: patriciogv
version: 0.0.1
tangram-version: 0.0.7
licence: MIT
description: |
Useful set of functions to construct scale, rotation and translation of 2, 3 or 4 dimensions. For more information about matrices read [this chapter from The Book of Shaders](http://thebookofshaders.com/08/)
shaders:
blocks:
global: |
// Rotate in 2, 3 and 4 dimensions
// ================================
mat2 rotate2D (float angle) {
return mat2(cos(angle),-sin(angle),
sin(angle),cos(angle));
}
#ifdef TANGRAM_FRAGMENT_SHADER
vec2 rotate2D (vec2 st, float a) {
return (rotate2D(a)*(st-.5))+.5;
}
#endif
mat3 rotateX3D (float phi) {
return mat3(
vec3(1.,0.,0.),
vec3(0.,cos(phi),-sin(phi)),
vec3(0.,sin(phi),cos(phi)));
}
mat4 rotateX4D (float phi) {
return mat4(
vec4(1.,0.,0.,0),
vec4(0.,cos(phi),-sin(phi),0.),
vec4(0.,sin(phi),cos(phi),0.),
vec4(0.,0.,0.,1.));
}
mat3 rotateY3D (float theta) {
return mat3(
vec3(cos(theta),0.,-sin(theta)),
vec3(0.,1.,0.),
vec3(sin(theta),0.,cos(theta)));
}
mat4 rotateY4D (float theta) {
return mat4(
vec4(cos(theta),0.,-sin(theta),0),
vec4(0.,1.,0.,0.),
vec4(sin(theta),0.,cos(theta),0.),
vec4(0.,0.,0.,1.));
}
mat3 rotateZ3D (float psi) {
return mat3(
vec3(cos(psi),-sin(psi),0.),
vec3(sin(psi),cos(psi),0.),
vec3(0.,0.,1.));
}
mat4 rotateZ4D (float psi) {
return mat4(
vec4(cos(psi),-sin(psi),0.,0),
vec4(sin(psi),cos(psi),0.,0.),
vec4(0.,0.,1.,0.),
vec4(0.,0.,0.,1.));
}
//
// Scale 4 dimensions
// ================================
mat4 scale4D (float x, float y, float z) {
return mat4(
vec4(x, 0.0, 0.0, 0.0),
vec4(0.0, y, 0.0, 0.0),
vec4(0.0, 0.0, z, 0.0),
vec4(0.0, 0.0, 0.0, 1.0)
);
}
//
// Translate in 4 dimensions
mat4 translate4D (float x, float y, float z) {
return mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0),
vec4(x, y, z, 1.0)
);
}
space-screen:
doc:
author:
name: Patricio Gonzalez Vivo
twitter: patriciogv
version: 0.0.1
tangram-version: 0.0.7
licence: MIT
description: |
Get the coordinates in screen space streaching the proportion ('vec2 getScreenCoords ()') or non-streatching the proportion ('getScreenNonStretchCoords ()')
examples:
press:
url: https://tangrams.github.io/tangram-sandbox/styles/press.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/press.png
lines: 136-145
radar:
url: https://tangrams.github.io/tangram-sandbox/styles/radar.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/radar.png
lines: 0-143
test:
screen:
blocks:
color: |
vec2 st = getScreenCoords();
color.rg += fract(st*3.);
screen_nonstretch:
blocks:
color: |
vec2 st = getScreenNonStretchCoords();
color.rg += fract(st*3.);
shaders:
blocks:
global: |
#ifdef TANGRAM_FRAGMENT_SHADER
vec2 getScreenCoords () {
return gl_FragCoord.xy / u_resolution.xy;
}
vec2 getScreenNonStretchCoords () {
vec2 st = getScreenCoords();
if (u_resolution.y > u_resolution.x ) {
st.y *= u_resolution.y/u_resolution.x;
st.y -= (u_resolution.y*.5-u_resolution.x*.5)/u_resolution.x;
} else {
st.x *= u_resolution.x/u_resolution.y;
st.x -= (u_resolution.x*.5-u_resolution.y*.5)/u_resolution.y;
}
return st;
}
#endif
shapes-type:
mix: [functions-aastep]
shaders:
defines:
STROKE: 0.15
blocks:
global: |
float fill (in float size, in float x) {
return 1.-aastep(size, x);
}
float stroke (in float size, in float x) {
return aastep(size, x+STROKE) - aastep(size, x);
}
space-tile:
shaders:
blocks:
global: |
// Variant to be add to both vertex and fragments shaders
varying vec3 v_pos;
//
// Get the coordinates in tile space
// ================================
vec2 getTileCoords() {
return fract(v_pos.xy);
}
position: |
// Normalize the attribute position of a vertex
v_pos = modelPosition().xyz;
tiling-tile:
shaders:
blocks:
global: |
// Repeats a coordinate space (st) in diferent tiles
// ================================
vec2 tile (vec2 st, float zoom) {
st *= zoom;
return fract(st);
}
block:
shaders:
defines:
ADD: '+'
SUBTRACT: '-'
MULTIPLY: '*'
PI: 3.1415926535897932384626433832795
TWO_PI: 6.2831853071795864769252867665590
HALF_PI: 1.5707963267948966192313216916398
QUATER_PI: .785398163
EPSILON: 0.0000001
deg2rad(d): (((d)*3.1415926535897932384626433832795)/180.0)
rad2deg(d): (((d)*180.0)/3.1415926535897932384626433832795)