p5 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/{src → dist}/accessibility/color_namer.js +48 -3
  2. package/{src → dist}/accessibility/describe.js +2 -2
  3. package/{src → dist}/accessibility/gridOutput.js +2 -2
  4. package/dist/accessibility/index.js +60 -0
  5. package/{src → dist}/accessibility/outputs.js +2 -2
  6. package/{src → dist}/accessibility/textOutput.js +2 -2
  7. package/dist/app.js +120 -0
  8. package/{src → dist}/color/color_conversion.js +48 -10
  9. package/{src → dist}/color/color_spaces/hsb.js +3 -1
  10. package/dist/color/creating_reading.js +3 -0
  11. package/dist/color/index.js +13 -0
  12. package/dist/color/p5.Color.culori.js +1 -0
  13. package/dist/color/p5.Color.js +3 -0
  14. package/{src → dist}/color/setting.js +9 -6
  15. package/{src/core/constants.js → dist/constants-C-g_eAdC.js} +266 -130
  16. package/{src → dist}/core/States.js +3 -1
  17. package/dist/core/constants.js +1 -0
  18. package/{src → dist}/core/environment.js +7 -6
  19. package/{src → dist}/core/friendly_errors/browser_errors.js +1 -1
  20. package/{src → dist}/core/friendly_errors/fes_core.js +14 -44
  21. package/{src → dist}/core/friendly_errors/file_errors.js +6 -3
  22. package/dist/core/friendly_errors/index.js +23 -0
  23. package/dist/core/friendly_errors/param_validator.js +5455 -0
  24. package/{src → dist}/core/friendly_errors/sketch_reader.js +50 -4
  25. package/{src → dist}/core/friendly_errors/sketch_verifier.js +6 -6
  26. package/{src → dist}/core/friendly_errors/stacktrace.js +3 -5
  27. package/{src → dist}/core/friendly_errors/validate_params.js +50 -41
  28. package/{src → dist}/core/helpers.js +9 -6
  29. package/dist/core/init.js +105 -0
  30. package/dist/core/internationalization.js +302 -0
  31. package/dist/core/legacy.js +73 -0
  32. package/dist/core/main.js +44 -0
  33. package/dist/core/noop.js +3 -0
  34. package/dist/core/p5.Graphics.js +40 -0
  35. package/dist/core/p5.Renderer.js +11 -0
  36. package/dist/core/p5.Renderer2D.js +44 -0
  37. package/dist/core/reference.js +1 -0
  38. package/dist/core/rendering.js +40 -0
  39. package/{src → dist}/core/structure.js +3 -3
  40. package/{src → dist}/core/transform.js +2 -2
  41. package/{src/color/creating_reading.js → dist/creating_reading-D4AAKRbx.js} +841 -13
  42. package/{src → dist}/data/index.js +3 -1
  43. package/{src → dist}/data/local_storage.js +2 -8
  44. package/{src → dist}/dom/dom.js +11 -5
  45. package/dist/dom/index.js +18 -0
  46. package/{src → dist}/dom/p5.Element.js +14 -12
  47. package/{src → dist}/dom/p5.File.js +4 -4
  48. package/{src → dist}/dom/p5.MediaElement.js +10 -4
  49. package/{src → dist}/events/acceleration.js +2 -2
  50. package/{src → dist}/events/index.js +3 -1
  51. package/{src → dist}/events/keyboard.js +14 -11
  52. package/{src → dist}/events/pointer.js +16 -17
  53. package/dist/image/const.js +9 -0
  54. package/{src → dist}/image/filterRenderer2D.js +57 -37
  55. package/{src → dist}/image/filters.js +1 -3
  56. package/dist/image/image.js +40 -0
  57. package/dist/image/index.js +51 -0
  58. package/dist/image/loading_displaying.js +40 -0
  59. package/dist/image/p5.Image.js +11 -0
  60. package/{src → dist}/image/pixels.js +4 -3
  61. package/{src → dist}/io/csv.js +72 -70
  62. package/dist/io/files.js +40 -0
  63. package/dist/io/index.js +51 -0
  64. package/{src → dist}/io/p5.Table.js +6 -6
  65. package/{src → dist}/io/p5.TableRow.js +3 -4
  66. package/{src → dist}/io/p5.XML.js +2 -5
  67. package/{src → dist}/io/utilities.js +1 -1
  68. package/{src/core/p5.Renderer2D.js → dist/main-s72KWcUy.js} +735 -57
  69. package/{src → dist}/math/Matrices/Matrix.js +10 -8
  70. package/{src → dist}/math/Matrices/MatrixInterface.js +5 -3
  71. package/{src → dist}/math/Matrices/MatrixNumjs.js +12 -26
  72. package/{src → dist}/math/calculation.js +2 -2
  73. package/{src → dist}/math/index.js +6 -3
  74. package/{src → dist}/math/math.js +2 -2
  75. package/{src → dist}/math/noise.js +2 -2
  76. package/{src → dist}/math/p5.Matrix.js +7 -4
  77. package/{src → dist}/math/p5.Vector.js +6 -6
  78. package/{src → dist}/math/random.js +2 -2
  79. package/{src → dist}/math/trigonometry.js +16 -15
  80. package/{src/image/p5.Image.js → dist/p5.Renderer-CwAYZOC2.js} +390 -19
  81. package/dist/rendering--aAe5aq3.js +24925 -0
  82. package/{src → dist}/shape/2d_primitives.js +18 -17
  83. package/{src → dist}/shape/attributes.js +18 -17
  84. package/{src → dist}/shape/curves.js +2 -2
  85. package/{src → dist}/shape/custom_shapes.js +44 -64
  86. package/{src → dist}/shape/index.js +10 -2
  87. package/{src → dist}/shape/vertex.js +2 -3
  88. package/dist/type/index.js +25 -0
  89. package/{src → dist}/type/lib/Typr.js +76 -94
  90. package/{src → dist}/type/p5.Font.js +37 -61
  91. package/{src → dist}/type/textCore.js +34 -57
  92. package/{src → dist}/type/unicodeRanges.js +3 -1
  93. package/{src → dist}/utilities/conversion.js +2 -2
  94. package/{src → dist}/utilities/index.js +3 -1
  95. package/{src → dist}/utilities/time_date.js +6 -7
  96. package/{src → dist}/utilities/utility_functions.js +2 -2
  97. package/dist/webgl/3d_primitives.js +40 -0
  98. package/{src → dist}/webgl/GeometryBufferCache.js +3 -1
  99. package/{src → dist}/webgl/GeometryBuilder.js +12 -8
  100. package/{src → dist}/webgl/ShaderGenerator.js +79 -82
  101. package/{src → dist}/webgl/ShapeBuilder.js +26 -23
  102. package/dist/webgl/index.js +76 -0
  103. package/{src → dist}/webgl/interaction.js +7 -6
  104. package/dist/webgl/light.js +40 -0
  105. package/{src → dist}/webgl/loading.js +45 -12
  106. package/dist/webgl/material.js +40 -0
  107. package/dist/webgl/p5.Camera.js +40 -0
  108. package/{src → dist}/webgl/p5.DataArray.js +3 -5
  109. package/dist/webgl/p5.Framebuffer.js +40 -0
  110. package/{src → dist}/webgl/p5.Geometry.js +12 -15
  111. package/{src → dist}/webgl/p5.Quat.js +5 -4
  112. package/{src → dist}/webgl/p5.RenderBuffer.js +2 -3
  113. package/dist/webgl/p5.RendererGL.js +40 -0
  114. package/dist/webgl/p5.Shader.js +40 -0
  115. package/dist/webgl/p5.Texture.js +40 -0
  116. package/{src → dist}/webgl/text.js +51 -9
  117. package/lib/p5.esm.js +102 -48
  118. package/lib/p5.js +102 -48
  119. package/lib/p5.min.js +1 -1
  120. package/package.json +17 -16
  121. package/translations/dev.js +6 -6
  122. package/translations/index.js +1 -1
  123. package/src/README.md +0 -27
  124. package/src/accessibility/index.js +0 -13
  125. package/src/app.js +0 -61
  126. package/src/color/index.js +0 -9
  127. package/src/color/p5.Color.culori.js +0 -66
  128. package/src/color/p5.Color.js +0 -851
  129. package/src/core/README.md +0 -91
  130. package/src/core/friendly_errors/index.js +0 -13
  131. package/src/core/friendly_errors/param_validator.js +0 -561
  132. package/src/core/init.js +0 -58
  133. package/src/core/internationalization.js +0 -195
  134. package/src/core/legacy.js +0 -29
  135. package/src/core/main.js +0 -689
  136. package/src/core/noop.js +0 -1
  137. package/src/core/p5.Graphics.js +0 -696
  138. package/src/core/p5.Renderer.js +0 -408
  139. package/src/core/reference.js +0 -2060
  140. package/src/core/rendering.js +0 -697
  141. package/src/dom/index.js +0 -11
  142. package/src/image/const.js +0 -6
  143. package/src/image/image.js +0 -731
  144. package/src/image/index.js +0 -15
  145. package/src/image/loading_displaying.js +0 -1431
  146. package/src/io/files.js +0 -2210
  147. package/src/io/index.js +0 -11
  148. package/src/math/README.md +0 -40
  149. package/src/type/index.js +0 -9
  150. package/src/webgl/3d_primitives.js +0 -2741
  151. package/src/webgl/index.js +0 -37
  152. package/src/webgl/light.js +0 -1851
  153. package/src/webgl/material.js +0 -3854
  154. package/src/webgl/p5.Camera.js +0 -4010
  155. package/src/webgl/p5.Framebuffer.js +0 -1865
  156. package/src/webgl/p5.RendererGL.js +0 -2867
  157. package/src/webgl/p5.Shader.js +0 -1505
  158. package/src/webgl/p5.Texture.js +0 -541
  159. package/src/webgl/shaders/basic.frag +0 -6
  160. package/src/webgl/shaders/filters/base.frag +0 -22
  161. package/src/webgl/shaders/filters/base.vert +0 -19
  162. package/src/webgl/shaders/filters/blur.frag +0 -60
  163. package/src/webgl/shaders/filters/default.vert +0 -18
  164. package/src/webgl/shaders/filters/dilate.frag +0 -39
  165. package/src/webgl/shaders/filters/erode.frag +0 -39
  166. package/src/webgl/shaders/filters/gray.frag +0 -16
  167. package/src/webgl/shaders/filters/invert.frag +0 -15
  168. package/src/webgl/shaders/filters/opaque.frag +0 -12
  169. package/src/webgl/shaders/filters/posterize.frag +0 -29
  170. package/src/webgl/shaders/filters/threshold.frag +0 -23
  171. package/src/webgl/shaders/font.frag +0 -216
  172. package/src/webgl/shaders/font.vert +0 -44
  173. package/src/webgl/shaders/imageLight.vert +0 -33
  174. package/src/webgl/shaders/imageLightDiffused.frag +0 -82
  175. package/src/webgl/shaders/imageLightSpecular.frag +0 -134
  176. package/src/webgl/shaders/light.vert +0 -37
  177. package/src/webgl/shaders/light_texture.frag +0 -26
  178. package/src/webgl/shaders/lighting.glsl +0 -227
  179. package/src/webgl/shaders/line.frag +0 -74
  180. package/src/webgl/shaders/line.vert +0 -294
  181. package/src/webgl/shaders/normal.frag +0 -6
  182. package/src/webgl/shaders/normal.vert +0 -72
  183. package/src/webgl/shaders/phong.frag +0 -84
  184. package/src/webgl/shaders/phong.vert +0 -87
  185. package/src/webgl/shaders/point.frag +0 -29
  186. package/src/webgl/shaders/point.vert +0 -19
  187. package/src/webgl/shaders/sphereMapping.frag +0 -26
  188. package/src/webgl/shaders/webgl2Compatibility.glsl +0 -34
@@ -1,39 +0,0 @@
1
- // Increase the bright areas in an image
2
-
3
- precision highp float;
4
-
5
- varying vec2 vTexCoord;
6
-
7
- uniform sampler2D tex0;
8
- uniform vec2 texelSize;
9
-
10
- float luma(vec3 color) {
11
- // weighted grayscale with luminance values
12
- // weights 77, 151, 28 taken from src/image/filters.js
13
- return dot(color, vec3(0.300781, 0.589844, 0.109375));
14
- }
15
-
16
- void main() {
17
- vec4 color = texture2D(tex0, vTexCoord);
18
- float lum = luma(color.rgb);
19
-
20
- // set current color as the brightest neighbor color
21
-
22
- vec4 neighbors[4];
23
- neighbors[0] = texture2D(tex0, vTexCoord + vec2( texelSize.x, 0.0));
24
- neighbors[1] = texture2D(tex0, vTexCoord + vec2(-texelSize.x, 0.0));
25
- neighbors[2] = texture2D(tex0, vTexCoord + vec2(0.0, texelSize.y));
26
- neighbors[3] = texture2D(tex0, vTexCoord + vec2(0.0, -texelSize.y));
27
-
28
- for (int i = 0; i < 4; i++) {
29
- vec4 neighborColor = neighbors[i];
30
- float neighborLum = luma(neighborColor.rgb);
31
-
32
- if (neighborLum > lum) {
33
- color = neighborColor;
34
- lum = neighborLum;
35
- }
36
- }
37
-
38
- gl_FragColor = color;
39
- }
@@ -1,39 +0,0 @@
1
- // Reduces the bright areas in an image
2
-
3
- precision highp float;
4
-
5
- varying vec2 vTexCoord;
6
-
7
- uniform sampler2D tex0;
8
- uniform vec2 texelSize;
9
-
10
- float luma(vec3 color) {
11
- // weighted grayscale with luminance values
12
- // weights 77, 151, 28 taken from src/image/filters.js
13
- return dot(color, vec3(0.300781, 0.589844, 0.109375));
14
- }
15
-
16
- void main() {
17
- vec4 color = texture2D(tex0, vTexCoord);
18
- float lum = luma(color.rgb);
19
-
20
- // set current color as the darkest neighbor color
21
-
22
- vec4 neighbors[4];
23
- neighbors[0] = texture2D(tex0, vTexCoord + vec2( texelSize.x, 0.0));
24
- neighbors[1] = texture2D(tex0, vTexCoord + vec2(-texelSize.x, 0.0));
25
- neighbors[2] = texture2D(tex0, vTexCoord + vec2(0.0, texelSize.y));
26
- neighbors[3] = texture2D(tex0, vTexCoord + vec2(0.0, -texelSize.y));
27
-
28
- for (int i = 0; i < 4; i++) {
29
- vec4 neighborColor = neighbors[i];
30
- float neighborLum = luma(neighborColor.rgb);
31
-
32
- if (neighborLum < lum) {
33
- color = neighborColor;
34
- lum = neighborLum;
35
- }
36
- }
37
-
38
- gl_FragColor = color;
39
- }
@@ -1,16 +0,0 @@
1
- precision highp float;
2
-
3
- varying vec2 vTexCoord;
4
-
5
- uniform sampler2D tex0;
6
-
7
- float luma(vec3 color) {
8
- // weighted grayscale with luminance values
9
- return dot(color, vec3(0.2126, 0.7152, 0.0722));
10
- }
11
-
12
- void main() {
13
- vec4 tex = texture2D(tex0, vTexCoord);
14
- float gray = luma(tex.rgb);
15
- gl_FragColor = vec4(gray, gray, gray, tex.a);
16
- }
@@ -1,15 +0,0 @@
1
- // Set each pixel to inverse value
2
- // Note that original INVERT does not change the opacity, so this follows suit
3
-
4
- precision highp float;
5
-
6
- varying vec2 vTexCoord;
7
-
8
- uniform sampler2D tex0;
9
-
10
- void main() {
11
- vec4 color = texture2D(tex0, vTexCoord);
12
- vec3 origColor = color.rgb / color.a;
13
- vec3 invertedColor = vec3(1.0) - origColor;
14
- gl_FragColor = vec4(invertedColor * color.a, color.a);
15
- }
@@ -1,12 +0,0 @@
1
- // Set alpha channel to entirely opaque
2
-
3
- precision highp float;
4
-
5
- varying vec2 vTexCoord;
6
-
7
- uniform sampler2D tex0;
8
-
9
- void main() {
10
- vec4 color = texture2D(tex0, vTexCoord);
11
- gl_FragColor = vec4(color.rgb / color.a, 1.0);
12
- }
@@ -1,29 +0,0 @@
1
- // Limit color space for a stylized cartoon / poster effect
2
-
3
- precision highp float;
4
-
5
- varying vec2 vTexCoord;
6
-
7
- uniform sampler2D tex0;
8
- uniform float filterParameter;
9
-
10
- vec3 quantize(vec3 color, float n) {
11
- // restrict values to N options/bins
12
- // and floor each channel to nearest value
13
- //
14
- // eg. when N = 5, values = 0.0, 0.25, 0.50, 0.75, 1.0
15
- // then quantize (0.1, 0.7, 0.9) -> (0.0, 0.5, 1.0)
16
-
17
- color = color * n;
18
- color = floor(color);
19
- color = color / (n - 1.0);
20
- return color;
21
- }
22
-
23
- void main() {
24
- vec4 color = texture2D(tex0, vTexCoord);
25
-
26
- vec3 restrictedColor = quantize(color.rgb / color.a, filterParameter);
27
-
28
- gl_FragColor = vec4(restrictedColor.rgb * color.a, color.a);
29
- }
@@ -1,23 +0,0 @@
1
- // Convert pixels to either white or black,
2
- // depending on if their luma is above or below filterParameter
3
-
4
- precision highp float;
5
-
6
- varying vec2 vTexCoord;
7
-
8
- uniform sampler2D tex0;
9
- uniform float filterParameter;
10
-
11
- float luma(vec3 color) {
12
- // weighted grayscale with luminance values
13
- return dot(color, vec3(0.2126, 0.7152, 0.0722));
14
- }
15
-
16
- void main() {
17
- vec4 color = texture2D(tex0, vTexCoord);
18
- float gray = luma(color.rgb / color.a);
19
- // floor() used to match src/image/filters.js
20
- float threshold = floor(filterParameter * 255.0) / 255.0;
21
- float blackOrWhite = step(threshold, gray);
22
- gl_FragColor = vec4(vec3(blackOrWhite) * color.a, color.a);
23
- }
@@ -1,216 +0,0 @@
1
- #ifndef WEBGL2
2
- #extension GL_OES_standard_derivatives : enable
3
- #endif
4
-
5
- #if 0
6
- // simulate integer math using floats
7
- #define int float
8
- #define ivec2 vec2
9
- #define INT(x) float(x)
10
-
11
- int ifloor(float v) { return floor(v); }
12
- ivec2 ifloor(vec2 v) { return floor(v); }
13
-
14
- #else
15
- // use native integer math
16
- precision highp int;
17
- #define INT(x) x
18
-
19
- int ifloor(float v) { return int(v); }
20
- int ifloor(int v) { return v; }
21
- ivec2 ifloor(vec2 v) { return ivec2(v); }
22
-
23
- #endif
24
-
25
- uniform sampler2D uSamplerStrokes;
26
- uniform sampler2D uSamplerRowStrokes;
27
- uniform sampler2D uSamplerRows;
28
- uniform sampler2D uSamplerColStrokes;
29
- uniform sampler2D uSamplerCols;
30
-
31
- uniform ivec2 uStrokeImageSize;
32
- uniform ivec2 uCellsImageSize;
33
- uniform ivec2 uGridImageSize;
34
-
35
- uniform ivec2 uGridOffset;
36
- uniform ivec2 uGridSize;
37
- uniform vec4 uMaterialColor;
38
-
39
- IN vec2 vTexCoord;
40
-
41
- // some helper functions
42
- int ROUND(float v) { return ifloor(v + 0.5); }
43
- ivec2 ROUND(vec2 v) { return ifloor(v + 0.5); }
44
- float saturate(float v) { return clamp(v, 0.0, 1.0); }
45
- vec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }
46
-
47
- int mul(float v1, int v2) {
48
- return ifloor(v1 * float(v2));
49
- }
50
-
51
- ivec2 mul(vec2 v1, ivec2 v2) {
52
- return ifloor(v1 * vec2(v2) + 0.5);
53
- }
54
-
55
- // unpack a 16-bit integer from a float vec2
56
- int getInt16(vec2 v) {
57
- ivec2 iv = ROUND(v * 255.0);
58
- return iv.x * INT(128) + iv.y;
59
- }
60
-
61
- vec2 pixelScale;
62
- vec2 coverage = vec2(0.0);
63
- vec2 weight = vec2(0.5);
64
- const float minDistance = 1.0/8192.0;
65
- const float hardness = 1.05; // amount of antialias
66
-
67
- // the maximum number of curves in a glyph
68
- const int N = INT(250);
69
-
70
- // retrieves an indexed pixel from a sampler
71
- vec4 getTexel(sampler2D sampler, int pos, ivec2 size) {
72
- int width = size.x;
73
- int y = ifloor(pos / width);
74
- int x = pos - y * width; // pos % width
75
-
76
- return TEXTURE(sampler, (vec2(x, y) + 0.5) / vec2(size));
77
- }
78
-
79
- void calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {
80
-
81
- // get the coefficients of the quadratic in t
82
- vec2 a = p0 - p1 * 2.0 + p2;
83
- vec2 b = p0 - p1;
84
- vec2 c = p0 - vTexCoord;
85
-
86
- // found out which values of 't' it crosses the axes
87
- vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));
88
- vec2 t1 = ((b - surd) / a).yx;
89
- vec2 t2 = ((b + surd) / a).yx;
90
-
91
- // approximate straight lines to avoid rounding errors
92
- if (abs(a.y) < 0.001)
93
- t1.x = t2.x = c.y / (2.0 * b.y);
94
-
95
- if (abs(a.x) < 0.001)
96
- t1.y = t2.y = c.x / (2.0 * b.x);
97
-
98
- // plug into quadratic formula to find the corrdinates of the crossings
99
- C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;
100
- C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;
101
- }
102
-
103
- void coverageX(vec2 p0, vec2 p1, vec2 p2) {
104
-
105
- vec2 C1, C2;
106
- calulateCrossings(p0, p1, p2, C1, C2);
107
-
108
- // determine on which side of the x-axis the points lie
109
- bool y0 = p0.y > vTexCoord.y;
110
- bool y1 = p1.y > vTexCoord.y;
111
- bool y2 = p2.y > vTexCoord.y;
112
-
113
- // could web be under the curve (after t1)?
114
- if (y1 ? !y2 : y0) {
115
- // add the coverage for t1
116
- coverage.x += saturate(C1.x + 0.5);
117
- // calculate the anti-aliasing for t1
118
- weight.x = min(weight.x, abs(C1.x));
119
- }
120
-
121
- // are we outside the curve (after t2)?
122
- if (y1 ? !y0 : y2) {
123
- // subtract the coverage for t2
124
- coverage.x -= saturate(C2.x + 0.5);
125
- // calculate the anti-aliasing for t2
126
- weight.x = min(weight.x, abs(C2.x));
127
- }
128
- }
129
-
130
- // this is essentially the same as coverageX, but with the axes swapped
131
- void coverageY(vec2 p0, vec2 p1, vec2 p2) {
132
-
133
- vec2 C1, C2;
134
- calulateCrossings(p0, p1, p2, C1, C2);
135
-
136
- bool x0 = p0.x > vTexCoord.x;
137
- bool x1 = p1.x > vTexCoord.x;
138
- bool x2 = p2.x > vTexCoord.x;
139
-
140
- if (x1 ? !x2 : x0) {
141
- coverage.y -= saturate(C1.y + 0.5);
142
- weight.y = min(weight.y, abs(C1.y));
143
- }
144
-
145
- if (x1 ? !x0 : x2) {
146
- coverage.y += saturate(C2.y + 0.5);
147
- weight.y = min(weight.y, abs(C2.y));
148
- }
149
- }
150
-
151
- void main() {
152
-
153
- // calculate the pixel scale based on screen-coordinates
154
- pixelScale = hardness / fwidth(vTexCoord);
155
-
156
- // which grid cell is this pixel in?
157
- ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));
158
-
159
- // intersect curves in this row
160
- {
161
- // the index into the row info bitmap
162
- int rowIndex = gridCoord.y + uGridOffset.y;
163
- // fetch the info texel
164
- vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);
165
- // unpack the rowInfo
166
- int rowStrokeIndex = getInt16(rowInfo.xy);
167
- int rowStrokeCount = getInt16(rowInfo.zw);
168
-
169
- for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {
170
- if (iRowStroke >= rowStrokeCount)
171
- break;
172
-
173
- // each stroke is made up of 3 points: the start and control point
174
- // and the start of the next curve.
175
- // fetch the indices of this pair of strokes:
176
- vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);
177
-
178
- // unpack the stroke index
179
- int strokePos = getInt16(strokeIndices.xy);
180
-
181
- // fetch the two strokes
182
- vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);
183
- vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);
184
-
185
- // calculate the coverage
186
- coverageX(stroke0.xy, stroke0.zw, stroke1.xy);
187
- }
188
- }
189
-
190
- // intersect curves in this column
191
- {
192
- int colIndex = gridCoord.x + uGridOffset.x;
193
- vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);
194
- int colStrokeIndex = getInt16(colInfo.xy);
195
- int colStrokeCount = getInt16(colInfo.zw);
196
-
197
- for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {
198
- if (iColStroke >= colStrokeCount)
199
- break;
200
-
201
- vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);
202
-
203
- int strokePos = getInt16(strokeIndices.xy);
204
- vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);
205
- vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);
206
- coverageY(stroke0.xy, stroke0.zw, stroke1.xy);
207
- }
208
- }
209
-
210
- weight = saturate(1.0 - weight * 2.0);
211
- float distance = max(weight.x + weight.y, minDistance); // manhattan approx.
212
- float antialias = abs(dot(coverage, weight) / distance);
213
- float cover = min(abs(coverage.x), abs(coverage.y));
214
- OUT_COLOR = vec4(uMaterialColor.rgb, 1.) * uMaterialColor.a;
215
- OUT_COLOR *= saturate(max(antialias, cover));
216
- }
@@ -1,44 +0,0 @@
1
- IN vec3 aPosition;
2
- IN vec2 aTexCoord;
3
- uniform mat4 uModelViewMatrix;
4
- uniform mat4 uProjectionMatrix;
5
-
6
- uniform vec4 uGlyphRect;
7
- uniform float uGlyphOffset;
8
-
9
- OUT vec2 vTexCoord;
10
- OUT float w;
11
-
12
- void main() {
13
- vec4 positionVec4 = vec4(aPosition, 1.0);
14
-
15
- // scale by the size of the glyph's rectangle
16
- positionVec4.xy *= uGlyphRect.zw - uGlyphRect.xy;
17
-
18
- // Expand glyph bounding boxes by 1px on each side to give a bit of room
19
- // for antialiasing
20
- vec3 newOrigin = (uModelViewMatrix * vec4(0., 0., 0., 1.)).xyz;
21
- vec3 newDX = (uModelViewMatrix * vec4(1., 0., 0., 1.)).xyz;
22
- vec3 newDY = (uModelViewMatrix * vec4(0., 1., 0., 1.)).xyz;
23
- vec2 pixelScale = vec2(
24
- 1. / length(newOrigin - newDX),
25
- 1. / length(newOrigin - newDY)
26
- );
27
- vec2 offset = pixelScale * normalize(aTexCoord - vec2(0.5, 0.5));
28
- vec2 textureOffset = offset * (1. / vec2(
29
- uGlyphRect.z - uGlyphRect.x,
30
- uGlyphRect.w - uGlyphRect.y
31
- ));
32
-
33
- // move to the corner of the glyph
34
- positionVec4.xy += uGlyphRect.xy;
35
-
36
- // move to the letter's line offset
37
- positionVec4.x += uGlyphOffset;
38
-
39
- positionVec4.xy += offset;
40
-
41
- gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
42
- vTexCoord = aTexCoord + textureOffset;
43
- w = gl_Position.w;
44
- }
@@ -1,33 +0,0 @@
1
- precision highp float;
2
- attribute vec3 aPosition;
3
- attribute vec3 aNormal;
4
- attribute vec2 aTexCoord;
5
-
6
- varying vec3 localPos;
7
- varying vec3 vWorldNormal;
8
- varying vec3 vWorldPosition;
9
- varying vec2 vTexCoord;
10
-
11
- uniform mat4 uModelViewMatrix;
12
- uniform mat4 uProjectionMatrix;
13
- uniform mat3 uNormalMatrix;
14
-
15
- void main() {
16
- // Multiply the position by the matrix.
17
- vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);
18
- gl_Position = uProjectionMatrix * viewModelPosition;
19
-
20
- // orient the normals and pass to the fragment shader
21
- vWorldNormal = uNormalMatrix * aNormal;
22
-
23
- // send the view position to the fragment shader
24
- vWorldPosition = (uModelViewMatrix * vec4(aPosition, 1.0)).xyz;
25
-
26
- localPos = vWorldPosition;
27
- vTexCoord = aTexCoord;
28
- }
29
-
30
-
31
- /*
32
- in the vertex shader we'll compute the world position and world oriented normal of the vertices and pass those to the fragment shader as varyings.
33
- */
@@ -1,82 +0,0 @@
1
- precision highp float;
2
- varying vec3 localPos;
3
-
4
- // the HDR cubemap converted (can be from an equirectangular environment map.)
5
- uniform sampler2D environmentMap;
6
- varying vec2 vTexCoord;
7
-
8
- const float PI = 3.14159265359;
9
-
10
- vec2 nTOE( vec3 v ){
11
- // x = r sin(phi) cos(theta)
12
- // y = r cos(phi)
13
- // z = r sin(phi) sin(theta)
14
- float phi = acos( v.y );
15
- // if phi is 0, then there are no x, z components
16
- float theta = 0.0;
17
- // else
18
- theta = acos(v.x / sin(phi));
19
- float sinTheta = v.z / sin(phi);
20
- if (sinTheta < 0.0) {
21
- // Turn it into -theta, but in the 0-2PI range
22
- theta = 2.0 * PI - theta;
23
- }
24
- theta = theta / (2.0 * 3.14159);
25
- phi = phi / 3.14159 ;
26
-
27
- vec2 angles = vec2( phi, theta );
28
- return angles;
29
- }
30
-
31
- float random(vec2 p) {
32
- vec3 p3 = fract(vec3(p.xyx) * .1031);
33
- p3 += dot(p3, p3.yzx + 33.33);
34
- return fract((p3.x + p3.y) * p3.z);
35
- }
36
-
37
- void main()
38
- {
39
- // the sample direction equals the hemisphere's orientation
40
- float phi = vTexCoord.x * 2.0 * PI;
41
- float theta = vTexCoord.y * PI;
42
- float x = sin(theta) * cos(phi);
43
- float y = sin(theta) * sin(phi);
44
- float z = cos(theta);
45
- vec3 normal = vec3( x, y, z);
46
-
47
- // Discretely sampling the hemisphere given the integral's
48
- // spherical coordinates translates to the following fragment code:
49
- vec3 irradiance = vec3(0.0);
50
- vec3 up = vec3(0.0, 1.0, 0.0);
51
- vec3 right = normalize(cross(up, normal));
52
- up = normalize(cross(normal, right));
53
-
54
- // We specify a fixed sampleDelta delta value to traverse
55
- // the hemisphere; decreasing or increasing the sample delta
56
- // will increase or decrease the accuracy respectively.
57
- const float sampleDelta = 0.100;
58
- float nrSamples = 0.0;
59
- float randomOffset = random(gl_FragCoord.xy) * sampleDelta;
60
- for(float rawPhi = 0.0; rawPhi < 2.0 * PI; rawPhi += sampleDelta)
61
- {
62
- float phi = rawPhi + randomOffset;
63
- for(float rawTheta = 0.0; rawTheta < ( 0.5 ) * PI; rawTheta += sampleDelta)
64
- {
65
- float theta = rawTheta + randomOffset;
66
- // spherical to cartesian (in tangent space) // tangent space to world // add each sample result to irradiance
67
- float x = sin(theta) * cos(phi);
68
- float y = sin(theta) * sin(phi);
69
- float z = cos(theta);
70
- vec3 tangentSample = vec3( x, y, z);
71
-
72
- vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal;
73
- irradiance += (texture2D(environmentMap, nTOE(sampleVec)).xyz) * cos(theta) * sin(theta);
74
- nrSamples++;
75
- }
76
- }
77
- // divide by the total number of samples taken, giving us the average sampled irradiance.
78
- irradiance = PI * irradiance * (1.0 / float(nrSamples )) ;
79
-
80
-
81
- gl_FragColor = vec4(irradiance, 1.0);
82
- }
@@ -1,134 +0,0 @@
1
- precision highp float;
2
- varying vec3 localPos;
3
- varying vec2 vTexCoord;
4
-
5
- // our texture
6
- uniform sampler2D environmentMap;
7
- uniform float roughness;
8
-
9
- const float PI = 3.14159265359;
10
-
11
- float VanDerCorput(int bits);
12
- vec2 HammersleyNoBitOps(int i, int N);
13
- vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);
14
-
15
-
16
- vec2 nTOE( vec3 v ){
17
- // x = r sin(phi) cos(theta)
18
- // y = r cos(phi)
19
- // z = r sin(phi) sin(theta)
20
- float phi = acos( v.y );
21
- // if phi is 0, then there are no x, z components
22
- float theta = 0.0;
23
- // else
24
- theta = acos(v.x / sin(phi));
25
- float sinTheta = v.z / sin(phi);
26
- if (sinTheta < 0.0) {
27
- // Turn it into -theta, but in the 0-2PI range
28
- theta = 2.0 * PI - theta;
29
- }
30
- theta = theta / (2.0 * 3.14159);
31
- phi = phi / 3.14159 ;
32
-
33
- vec2 angles = vec2( phi, theta );
34
- return angles;
35
- }
36
-
37
-
38
- void main(){
39
- const int SAMPLE_COUNT = 400; // 4096
40
- int lowRoughnessLimit = int(pow(2.0,(roughness+0.1)*20.0));
41
- float totalWeight = 0.0;
42
- vec3 prefilteredColor = vec3(0.0);
43
- float phi = vTexCoord.x * 2.0 * PI;
44
- float theta = vTexCoord.y * PI;
45
- float x = sin(theta) * cos(phi);
46
- float y = sin(theta) * sin(phi);
47
- float z = cos(theta);
48
- vec3 N = vec3(x,y,z);
49
- vec3 V = N;
50
- for (int i = 0; i < SAMPLE_COUNT; ++i)
51
- {
52
- // break at smaller sample numbers for low roughness levels
53
- if(i == lowRoughnessLimit)
54
- {
55
- break;
56
- }
57
- vec2 Xi = HammersleyNoBitOps(i, SAMPLE_COUNT);
58
- vec3 H = ImportanceSampleGGX(Xi, N, roughness);
59
- vec3 L = normalize(2.0 * dot(V, H) * H - V);
60
-
61
- float NdotL = max(dot(N, L), 0.0);
62
- if (NdotL > 0.0)
63
- {
64
- prefilteredColor += texture2D(environmentMap, nTOE(L)).xyz * NdotL;
65
- totalWeight += NdotL;
66
- }
67
- }
68
- prefilteredColor = prefilteredColor / totalWeight;
69
-
70
- gl_FragColor = vec4(prefilteredColor, 1.0);
71
- }
72
-
73
- vec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness){
74
- float a = roughness * roughness;
75
-
76
- float phi = 2.0 * PI * Xi.x;
77
- float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a * a - 1.0) * Xi.y));
78
- float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
79
- // from spherical coordinates to cartesian coordinates
80
- vec3 H;
81
- H.x = cos(phi) * sinTheta;
82
- H.y = sin(phi) * sinTheta;
83
- H.z = cosTheta;
84
-
85
- // from tangent-space vector to world-space sample vector
86
- vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
87
- vec3 tangent = normalize(cross(up, N));
88
- vec3 bitangent = cross(N, tangent);
89
-
90
- vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;
91
- return normalize(sampleVec);
92
- }
93
-
94
-
95
- float VanDerCorput(int n, int base)
96
- {
97
- #ifdef WEBGL2
98
-
99
- uint bits = uint(n);
100
- bits = (bits << 16u) | (bits >> 16u);
101
- bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
102
- bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
103
- bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
104
- bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
105
- return float(bits) * 2.3283064365386963e-10; // / 0x100000000
106
-
107
- #else
108
-
109
- float invBase = 1.0 / float(base);
110
- float denom = 1.0;
111
- float result = 0.0;
112
-
113
-
114
- for (int i = 0; i < 32; ++i)
115
- {
116
- if (n > 0)
117
- {
118
- denom = mod(float(n), 2.0);
119
- result += denom * invBase;
120
- invBase = invBase / 2.0;
121
- n = int(float(n) / 2.0);
122
- }
123
- }
124
-
125
-
126
- return result;
127
-
128
- #endif
129
- }
130
-
131
- vec2 HammersleyNoBitOps(int i, int N)
132
- {
133
- return vec2(float(i) / float(N), VanDerCorput(i, 2));
134
- }