forked from tangrams/generic-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.yaml
426 lines (398 loc) · 16 KB
/
scene.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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
sources:
osm:
type: TopoJSONTiles
url: //vector.mapzen.com/osm/all/{z}/{x}/{y}.topojson?api_key=vector-tiles-VLxfzaw
cameras:
perspective:
type: perspective
focal_length: [[16, 1], [20, 2]] # pairs of [zoom, focal len]
vanishing_point: [-250, -250] # relative to center of screen, in pixels
lights:
directional1:
type: directional
direction: [.1, .5, -1]
diffuse: .7
ambient: .5
styles:
space-tile:
shaders:
defines:
TILE_SCALE: 0.0002445
NORMALIZED_SHORT(x): (x * 32767.)
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*TILE_SCALE);
}
position: |
// Normalize the attribute position of a vertex
v_pos = NORMALIZED_SHORT(a_position.xyz);
generative-random:
shaders:
blocks:
global: |
// 1D Random for 1 and 2 dimentions
// ================================
float random (float x) {
return fract(sin(x)*1e4);
}
float random (vec2 xy) {
return fract(sin(dot(xy.xy, vec2(12.9898,78.233)))* 43758.5453123);
}
//
// 2D Random for 2 dimentions
// ================================
vec2 random2 (vec2 xy) {
return fract(sin(vec2(dot(xy,vec2(127.1,311.7)),dot(xy,vec2(269.5,183.3))))*43758.5453);
}
//
// 3D Random for 2 dimentions
// ================================
vec3 random3 (vec2 xy) {
return fract(sin(vec3( dot(xy,vec2(127.1,311.7)), dot(xy,vec2(269.5,183.3)), dot(xy,vec2(419.2,371.9)) ))*43758.5453);
}
vec3 random3(vec3 c) {
float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
vec3 r;
r.z = fract(512.0*j);
j *= .125;
r.x = fract(512.0*j);
j *= .125;
r.y = fract(512.0*j);
return r-0.5;
}
color-tools:
shaders:
blocks:
global: |
// Get the intensity of a color
// ================================
float getIntensity (vec3 c) {
return (c.r+c.g+c.b)/3.0;
}
float getIntensity (vec4 c) {
return getIntensity(c.rgb);
}
//
// Get the Brightness of a color
// ================================
float getBrightness (vec3 c) {
return 0.212655 * c.r + 0.715158 * c.g + 0.072187 * c.b;
}
float getBrightness (vec4 c) {
return getBrightness(c.rgb);
}
geometry-normal:
shaders:
blocks:
global: |
// Ask to the geometry normals if this surface is a Wall
bool isWall() {
return dot(v_normal,vec3(0.,0.,1.)) == 0.0;
}
//
// Ask to the geometry normals if this surface is a roof
bool isRoof() {
return dot(v_normal,vec3(0.,0.,1.)) == 0.0;
}
grid:
mix: space-tile
shaders:
blocks:
global: |
// Simple Grid
//=============================
float grid(in vec2 st, in float res, in float press){
st = fract(st*res);
return 1.0-(step(press*res,st.x) * step(press*res,st.y));
}
float grid(in vec2 st, in float res){
return grid(st,res,0.005);
}
// GridTile
//=============================
vec3 TileGrid(float res){
vec2 st = getTileCoords()*100.*res;
vec3 color = vec3(0.0);
float press = 0.5+(1.0-fract(u_map_position.z))*0.1;
color += vec3(0.1,0.,0.)*grid(st,0.02,press);
color += vec3(0.5,0.,0.)*grid(st,0.01,press);
color += 0.1*grid(st,0.1,press);
return color;
}
vec3 TileGrid(){ return mix(TileGrid(1.),TileGrid(2.),fract(u_map_position.z)); }
roads:
base: lines
mix: generative-random
animated: true
texcoords: true
shaders:
blocks:
global: |
float randomSerie(float x, float freq, float t) {
return step(.8,random( floor(x*freq)-floor(t) ));
}
color: |
vec2 st = v_texcoord.xy;
float t = 12.*u_time;
float freq = 100.;
if ( v_color.r < 0.5) {
float cols = 2.;
if (fract(st.x*cols* 0.5) < 0.5){
t *= -1.0;
}
}
float offset = 0.025;
color.r = randomSerie(st.y, freq, t+offset);
color.g = randomSerie(st.y, freq, t);
color.b = randomSerie(st.y, freq, t-offset);
color.rgb *= step(0.1,st.x)-step(0.9,st.x);
simple-grid:
base: polygons
mix: [grid, generative-random]
animated: false
shaders:
blocks:
color: |
color.rgb *= TileGrid();
vec2 st = u_tile_origin.xy+floor(getTileCoords()*2.);
float t = u_time*.8+random(st);
float time_i = floor(t);
float time_f = fract(t);
color.rgb += step(0.9,random(st+time_i))*(1.0-time_f);
buildings:
base: polygons
mix: [generative-random, color-tools, geometry-normal]
animated: true
texcoords: true
shaders:
blocks:
global: |
float pattern(vec2 st, vec2 v, float t) {
vec2 p = floor(st+v);
return step(t, random(100.+p*.000001)+random(p.x)*0.5 );
}
position: |
position.z *= max(1.0,0.5+(1.0-(u_map_position.z/20.0))*5.0);
color: |
if (isWall()) {
float r = random(getBrightness(color.rgb));
float amount = 0.5+random(color.rg)*0.5;
if ( r > .3) {
// DeFrag
vec2 st = v_texcoord.xy;
st.y *= 1.+amount*2.;
st.y = fract(st.y);
st *= vec2(50.0,10.);
vec2 ipos = floor(st);
ipos += vec2(0.,floor(v_texcoord.y*(1.+amount*5.)));
// Random Cells
vec2 vel = floor(vec2(u_time*6.)); // time
vel *= vec2(-1.,0.); // direction
vel *= (step(1., mod(ipos.y,2.0))-0.5)*2.; // Oposite directions
vel *= random(ipos.y); // random speed
// 100%
float t = mod(u_time*20.*(1.+r*.5)+(4324.*amount),500.);
vec2 head = vec2(mod(t,50.), floor(t/50.));
vec2 offset = vec2(0.1,0.);
float pct = 1.0;
pct *= step(10.-head.y,ipos.y);// Y
pct += (1.0-step(head.x,ipos.x))*step(10.-head.y,ipos.y+1.); // X
pct = clamp(pct,0.,1.);
color.rgb = vec3(pct);
// Assign a random value base on the integer coord
color.r *= random(floor(st+vel+offset));
color.g *= random(floor(st+vel));
color.b *= random(floor(st+vel-offset));
color.rgb = smoothstep(0.,amount,color.rgb*color.rgb);
// Margin
color.rgb *= step(.1,fract(st.x+vel.x))*step(.1,fract(st.y+vel.y));
} else {
// Running lines
vec2 st = vec2(v_texcoord.x,v_world_position.z*0.005);
vec2 grid = vec2(100.0,20.);
st *= grid;
vec2 ipos = floor(st); // integer
vec2 fpos = fract(st); // fraction
vec2 vel = vec2(u_time*max(grid.x,grid.y)); // time
vel *= vec2(-1.,0.0) * random(1.0+ipos.y); // direction
// Assign a random value base on the integer coord
vec2 offset = vec2(0.1,0.);
color.r = pattern(st+offset,vel,amount);
color.g = pattern(st,vel,amount);
color.b = pattern(st-offset,vel,amount);
color.rgb *= step(0.2,fpos.y);
}
} else {
color.rgb = vec3(0.);
}
# buildingsLines:
# base: lines
# mix: tools
# lighting: false
# texcoords: true
# shaders:
# blocks:
# position: |
# position.z *= max(1.0,0.5+(1.0-(u_map_position.z/20.0))*5.0);
tools:
animated: true
shaders:
extensions: OES_standard_derivatives
blocks:
global: |
// Common Values
//================================
float radio = 0.05;
vec2 size = vec2(1.,.6);
vec3 background = vec3(0.996,0.996,0.918);
vec3 midle = vec3(0.824, 0.812, 0.804);
vec3 foreground = vec3(0.275,0.298,0.251);
// Coord System
//================================
varying vec3 v_pos;
#ifdef TANGRAM_FRAGMENT_SHADER
vec2 TileCoords(){return fract(v_pos.xy*0.0002445);}
float aastep(float threshold, float value) {
#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
}
float pulse(float x,float p, float w){
x = abs(x - p);
if( x>w ) return 0.0;
x /= w;
return 1.0 - x*x*(3.0-2.0*x);
}
float boxDF(vec2 st, vec2 size) {
float aspect = u_resolution.x/u_resolution.y;
st = st*2.-1.;
st.x *= aspect;
return length(max(abs(st)-size,.0));
}
float stripes(vec2 st, float width){
return aastep(width,abs(sin(st.y*3.14159265358)));
}
mat2 rotate2d(float angle){
return mat2(cos(angle),-sin(angle),
sin(angle),cos(angle));
}
float stripes(vec2 st){
st = rotate2d(.72)*st;
st *= 92.;
return aastep(.3,abs(sin(st.y*3.14159265358)));
}
#endif
position: |
v_pos = a_position.xyz * 32767.;
filter: |
vec2 xy = gl_FragCoord.xy/u_resolution.xy;
xy.x *= u_resolution.x/u_resolution.y;
xy = xy-vec2(.5*u_resolution.x/u_resolution.y,.5);
float t = -u_time*.5;
float radius = 0.0;
// radius = length(xy)*10.;
radius = dot(xy,xy)*7.;
color.rgb = mix(color.rgb,1.-color.rgb,1.0-aastep(.5,sin(fract(radius+t)*3.1415)));
border:
base: lines
mix: tools
texcoords: true
shaders:
blocks:
color: |
vec2 st = v_texcoord.xy;
float pattern = aastep(.5,pulse(st.x,.7,.1)+pulse(st.x,.35,.25));
color.rgb = mix(background,color.rgb,pattern);
b_border:
base: lines
mix: tools
texcoords: true
shaders:
blocks:
color: |
vec2 st = v_texcoord.xy;
float pattern = aastep(.5,pulse(st.x,.5,.2));
color.rgb = mix(background,color.rgb,pattern);
hatch:
base: polygons
mix: tools
shaders:
blocks:
color: |
vec2 st = (gl_FragCoord.xy / u_resolution.xy);
float aspect = u_resolution.x/u_resolution.y;
// size.x *= aspect;
color.rgb = mix(color.rgb,background,stripes(st*2.5));
layers:
water:
data: { source: osm }
draw:
simple-grid:
order: 3
color: [0.250,1.000,1.000]
landuse:
data: { source: osm }
draw:
hatch:
order: 2
color: #464C40
b_border:
order: 5
cap: round
width: 8px
color: #464C40
width: 5px
small-roads:
data: { source: osm, layer: roads }
filter:
any:
- highway: service
- highway: footway
- highway: path
- highway: residential
- highway: track
- highway: steps
draw:
lines:
order: 4
color: white
width: [[5, 0.5px],[15, 2px],[85, 50]]
roads:
data: { source: osm }
filter:
none:
- highway: service
- highway: footway
- highway: path
- highway: residential
- highway: track
- highway: steps
- kind: rail
draw:
roads:
order: 5
color: [0, 0, 0]
width: 8
oneway:
filter: { oneway: yes }
draw: { roads: { color: red } }
buildings:
data: { source: osm }
draw:
polygons:
order: 50
color: '#999'
extruded:
draw:
polygons:
style: buildings
extrude: function () { return feature.height > 0 || $zoom >= 16; }