-
Notifications
You must be signed in to change notification settings - Fork 5
/
grid.yaml
59 lines (55 loc) · 2.63 KB
/
grid.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
import:
- ../space/tile.yaml
styles:
patterns-grid:
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 grids. To learn more about patterns check [this chapter from the Book of Shaders](https://thebookofshaders.com/09/)
examples:
blueprint:
url: https://tangrams.github.io/tangram-sandbox/styles/blueprint.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/blueprint.png
lines: 75-76
grain:
url: https://tangrams.github.io/tangram-sandbox/styles/grain.yaml
img: https://tangrams.github.io/tangram-sandbox/styles/grain.png
lines: 15
mix: [space-tile]
shaders:
blocks:
global: |
// Draw a grid in the space a specific resolution and pressition
bool grid (vec2 st, float res, float press) {
vec2 grid = fract(st*res);
return grid.x < res*press || grid.y < res*press;
}
//
// Draw a grid in the space a specific resolution
bool grid (vec2 st, float res) {
return grid(st, res, 1.0);
}
//
// Draw a grid in 45 degress with a specific width
float diagonalGrid(vec2 st, float width){
return step(.5,max( smoothstep(st.x-width,st.x,st.y)*(1.-smoothstep(st.x,st.x+width,st.y)),
smoothstep(st.x-width,st.x,1.0-st.y)*(1.-smoothstep(st.x,st.x+width,1.0-st.y))));
}
// Draw a grid using tile coordenates in a specific resolution
float tileGrid (float res) {
vec2 st = getTileCoords()*100.*res;
float pct = 0.0;
float press = 0.4+(1.0-fract(u_map_position.z))*0.1;
if (grid(st,0.01,press)) pct += 0.5;
if (grid(st,0.1,press)) pct += 0.1;
return pct;
}
// Draw two grid that smoothly interpolates acording to zooms
float tileGrid() {
return mix(tileGrid(1.),tileGrid(2.),fract(u_map_position.z));
}