p5 2.2.1-rc.0 → 2.2.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.
- package/dist/accessibility/color_namer.js +5 -6
- package/dist/accessibility/describe.js +4 -26
- package/dist/accessibility/index.js +5 -6
- package/dist/accessibility/outputs.js +6 -38
- package/dist/app.js +5 -6
- package/dist/color/color_conversion.js +5 -6
- package/dist/color/creating_reading.js +1 -1
- package/dist/color/index.js +2 -2
- package/dist/color/p5.Color.js +1 -1
- package/dist/color/setting.js +59 -357
- package/dist/{constants-DEJVKr9Z.js → constants-DQyACdzq.js} +11 -61
- package/dist/core/constants.js +1 -1
- package/dist/core/environment.js +26 -158
- package/dist/core/filterShaders.js +1 -1
- package/dist/core/friendly_errors/fes_core.js +1 -1
- package/dist/core/friendly_errors/file_errors.js +1 -1
- package/dist/core/friendly_errors/index.js +1 -1
- package/dist/core/friendly_errors/param_validator.js +1 -1
- package/dist/core/friendly_errors/sketch_verifier.js +1 -1
- package/dist/core/helpers.js +1 -1
- package/dist/core/init.js +5 -6
- package/dist/core/internationalization.js +1 -1
- package/dist/core/legacy.js +5 -6
- package/dist/core/main.js +5 -6
- package/dist/core/p5.Graphics.js +4 -5
- package/dist/core/p5.Renderer.js +3 -4
- package/dist/core/p5.Renderer2D.js +5 -6
- package/dist/core/p5.Renderer3D.js +4 -5
- package/dist/core/rendering.js +4 -5
- package/dist/core/structure.js +13 -52
- package/dist/core/transform.js +32 -176
- package/dist/{creating_reading-CgHCHxqN.js → creating_reading-ZXzcZEsb.js} +3 -196
- package/dist/data/local_storage.js +4 -30
- package/dist/dom/dom.js +24 -159
- package/dist/dom/index.js +2 -2
- package/dist/dom/p5.Element.js +31 -208
- package/dist/dom/p5.File.js +1 -32
- package/dist/dom/p5.MediaElement.js +10 -113
- package/dist/events/acceleration.js +11 -64
- package/dist/events/keyboard.js +13 -81
- package/dist/events/pointer.js +18 -160
- package/dist/image/const.js +1 -1
- package/dist/image/filterRenderer2D.js +4 -5
- package/dist/image/image.js +4 -5
- package/dist/image/index.js +4 -5
- package/dist/image/loading_displaying.js +4 -5
- package/dist/image/p5.Image.js +3 -4
- package/dist/image/pixels.js +17 -100
- package/dist/io/files.js +4 -5
- package/dist/io/index.js +4 -5
- package/dist/io/p5.Table.js +66 -158
- package/dist/io/p5.TableRow.js +48 -71
- package/dist/io/p5.XML.js +6 -99
- package/dist/io/utilities.js +8 -3
- package/dist/{main-_RXV5Lx8.js → main-DvN69W3f.js} +13 -42
- package/dist/math/Matrices/Matrix.js +87 -126
- package/dist/math/Matrices/MatrixNumjs.js +1 -5
- package/dist/math/calculation.js +10 -112
- package/dist/math/index.js +1 -1
- package/dist/math/math.js +2 -12
- package/dist/math/noise.js +5 -32
- package/dist/math/p5.Matrix.js +3 -3
- package/dist/math/p5.Vector.js +104 -345
- package/dist/math/random.js +5 -32
- package/dist/math/trigonometry.js +15 -105
- package/dist/{p5.Renderer-QoFcvj3f.js → p5.Renderer-D-5LdCRz.js} +25 -178
- package/dist/{rendering-CsICjEXA.js → rendering-h9unX5K0.js} +254 -1156
- package/dist/shape/2d_primitives.js +33 -194
- package/dist/shape/attributes.js +12 -73
- package/dist/shape/curves.js +30 -95
- package/dist/shape/custom_shapes.js +63 -144
- package/dist/shape/index.js +2 -2
- package/dist/shape/vertex.js +21 -106
- package/dist/strands/p5.strands.js +248 -46
- package/dist/type/index.js +3 -4
- package/dist/type/p5.Font.js +4 -49
- package/dist/type/textCore.js +5 -158
- package/dist/utilities/conversion.js +17 -104
- package/dist/utilities/time_date.js +3 -40
- package/dist/utilities/utility_functions.js +6 -48
- package/dist/webgl/3d_primitives.js +4 -5
- package/dist/webgl/GeometryBuilder.js +1 -2
- package/dist/webgl/ShapeBuilder.js +22 -2
- package/dist/webgl/enums.js +1 -1
- package/dist/webgl/index.js +4 -5
- package/dist/webgl/interaction.js +6 -33
- package/dist/webgl/light.js +4 -5
- package/dist/webgl/loading.js +12 -46
- package/dist/webgl/material.js +4 -5
- package/dist/webgl/p5.Camera.js +4 -5
- package/dist/webgl/p5.DataArray.js +0 -4
- package/dist/webgl/p5.Framebuffer.js +4 -5
- package/dist/webgl/p5.Geometry.js +12 -106
- package/dist/webgl/p5.Quat.js +1 -1
- package/dist/webgl/p5.RendererGL.js +7 -18
- package/dist/webgl/p5.Shader.js +12 -36
- package/dist/webgl/p5.Texture.js +4 -5
- package/dist/webgl/text.js +4 -5
- package/dist/webgl/utils.js +4 -5
- package/dist/webgpu/index.js +1 -1
- package/dist/webgpu/p5.RendererWebGPU.js +529 -208
- package/dist/webgpu/shaders/color.js +32 -17
- package/dist/webgpu/shaders/filters/base.js +18 -7
- package/dist/webgpu/shaders/font.js +52 -40
- package/dist/webgpu/shaders/line.js +50 -36
- package/dist/webgpu/shaders/material.js +90 -83
- package/dist/webgpu/strands_wgslBackend.js +5 -2
- package/lib/p5.esm.js +5576 -7811
- package/lib/p5.esm.min.js +1 -1
- package/lib/p5.js +5576 -7811
- package/lib/p5.min.js +1 -1
- package/lib/p5.webgpu.esm.js +786 -453
- package/lib/p5.webgpu.js +786 -453
- package/lib/p5.webgpu.min.js +1 -1
- package/package.json +13 -13
- package/types/global.d.ts +16905 -16783
- package/types/p5.d.ts +11142 -11081
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { a7 as FLAT, a8 as SMOOTH } from '../constants-
|
|
1
|
+
import { a7 as FLAT, a8 as SMOOTH } from '../constants-DQyACdzq.js';
|
|
2
2
|
import { DataArray } from './p5.DataArray.js';
|
|
3
3
|
import { Vector } from '../math/p5.Vector.js';
|
|
4
4
|
import { downloadFile } from '../io/utilities.js';
|
|
5
|
-
import 'file-saver';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* @module Shape
|
|
@@ -105,8 +104,6 @@ class Geometry {
|
|
|
105
104
|
* @returns {Object} bounding box of the geometry.
|
|
106
105
|
*
|
|
107
106
|
* @example
|
|
108
|
-
* <div>
|
|
109
|
-
* <code>
|
|
110
107
|
* // Click and drag the mouse to view the scene from different angles.
|
|
111
108
|
*
|
|
112
109
|
* let particles;
|
|
@@ -165,8 +162,6 @@ class Geometry {
|
|
|
165
162
|
* pop();
|
|
166
163
|
* }
|
|
167
164
|
* }
|
|
168
|
-
* </code>
|
|
169
|
-
* </div>
|
|
170
165
|
*/
|
|
171
166
|
calculateBoundingBox() {
|
|
172
167
|
if (this.boundingBoxCache) {
|
|
@@ -268,8 +263,6 @@ class Geometry {
|
|
|
268
263
|
* <a href="#/p5/fill">fill()</a> function to apply color to the geometry.
|
|
269
264
|
*
|
|
270
265
|
* @example
|
|
271
|
-
* <div>
|
|
272
|
-
* <code>
|
|
273
266
|
* function setup() {
|
|
274
267
|
* createCanvas(100, 100, WEBGL);
|
|
275
268
|
*
|
|
@@ -313,8 +306,6 @@ class Geometry {
|
|
|
313
306
|
* 'Three squares drawn against a gray background. Red squares are at the center and the bottom-right. A blue square is at the top-right.'
|
|
314
307
|
* );
|
|
315
308
|
* }
|
|
316
|
-
* </code>
|
|
317
|
-
* </div>
|
|
318
309
|
*/
|
|
319
310
|
clearColors() {
|
|
320
311
|
this.vertexColors = [];
|
|
@@ -334,8 +325,6 @@ class Geometry {
|
|
|
334
325
|
* @param {String} [fileName='model.obj'] The name of the file to save the model as.
|
|
335
326
|
* If not specified, the default file name will be 'model.obj'.
|
|
336
327
|
* @example
|
|
337
|
-
* <div>
|
|
338
|
-
* <code>
|
|
339
328
|
* let myModel;
|
|
340
329
|
* let saveBtn;
|
|
341
330
|
* function setup() {
|
|
@@ -367,8 +356,6 @@ class Geometry {
|
|
|
367
356
|
* rotateY(millis() * 0.002);
|
|
368
357
|
* model(myModel);
|
|
369
358
|
* }
|
|
370
|
-
* </code>
|
|
371
|
-
* </div>
|
|
372
359
|
*/
|
|
373
360
|
saveObj(fileName = 'model.obj') {
|
|
374
361
|
let objStr= '';
|
|
@@ -438,8 +425,6 @@ class Geometry {
|
|
|
438
425
|
* @param {Object} [options] Optional settings.
|
|
439
426
|
* @param {Boolean} [options.binary=false] Whether or not a binary .stl file is saved.
|
|
440
427
|
* @example
|
|
441
|
-
* <div>
|
|
442
|
-
* <code>
|
|
443
428
|
* let myModel;
|
|
444
429
|
* let saveBtn1;
|
|
445
430
|
* let saveBtn2;
|
|
@@ -478,8 +463,6 @@ class Geometry {
|
|
|
478
463
|
* rotateY(millis() * 0.002);
|
|
479
464
|
* model(myModel);
|
|
480
465
|
* }
|
|
481
|
-
* </code>
|
|
482
|
-
* </div>
|
|
483
466
|
*/
|
|
484
467
|
saveStl(fileName = 'model.stl', { binary = false } = {}){
|
|
485
468
|
let modelOutput;
|
|
@@ -580,8 +563,6 @@ class Geometry {
|
|
|
580
563
|
* @for p5.Geometry
|
|
581
564
|
*
|
|
582
565
|
* @example
|
|
583
|
-
* <div>
|
|
584
|
-
* <code>
|
|
585
566
|
* let img;
|
|
586
567
|
*
|
|
587
568
|
* async function setup() {
|
|
@@ -621,8 +602,6 @@ class Geometry {
|
|
|
621
602
|
* function createShape() {
|
|
622
603
|
* plane(40);
|
|
623
604
|
* }
|
|
624
|
-
* </code>
|
|
625
|
-
* </div>
|
|
626
605
|
*/
|
|
627
606
|
flipU() {
|
|
628
607
|
this.uvs = this.uvs.flat().map((val, index) => {
|
|
@@ -672,8 +651,6 @@ class Geometry {
|
|
|
672
651
|
* @for p5.Geometry
|
|
673
652
|
*
|
|
674
653
|
* @example
|
|
675
|
-
* <div>
|
|
676
|
-
* <code>
|
|
677
654
|
* let img;
|
|
678
655
|
*
|
|
679
656
|
* async function setup() {
|
|
@@ -713,8 +690,6 @@ class Geometry {
|
|
|
713
690
|
* function createShape() {
|
|
714
691
|
* plane(40);
|
|
715
692
|
* }
|
|
716
|
-
* </code>
|
|
717
|
-
* </div>
|
|
718
693
|
*/
|
|
719
694
|
flipV() {
|
|
720
695
|
this.uvs = this.uvs.flat().map((val, index) => {
|
|
@@ -761,8 +736,6 @@ class Geometry {
|
|
|
761
736
|
* @chainable
|
|
762
737
|
*
|
|
763
738
|
* @example
|
|
764
|
-
* <div>
|
|
765
|
-
* <code>
|
|
766
739
|
* // Click and drag the mouse to view the scene from different angles.
|
|
767
740
|
*
|
|
768
741
|
* let myGeometry;
|
|
@@ -804,11 +777,8 @@ class Geometry {
|
|
|
804
777
|
* // Draw the p5.Geometry object.
|
|
805
778
|
* model(myGeometry);
|
|
806
779
|
* }
|
|
807
|
-
* </code>
|
|
808
|
-
* </div>
|
|
809
780
|
*
|
|
810
|
-
*
|
|
811
|
-
* <code>
|
|
781
|
+
* @example
|
|
812
782
|
* // Click and drag the mouse to view the scene from different angles.
|
|
813
783
|
*
|
|
814
784
|
* let myGeometry;
|
|
@@ -852,8 +822,6 @@ class Geometry {
|
|
|
852
822
|
* // Compute the faces array.
|
|
853
823
|
* this.computeFaces();
|
|
854
824
|
* }
|
|
855
|
-
* </code>
|
|
856
|
-
* </div>
|
|
857
825
|
*/
|
|
858
826
|
computeFaces() {
|
|
859
827
|
this.faces.length = 0;
|
|
@@ -930,8 +898,6 @@ class Geometry {
|
|
|
930
898
|
* @chainable
|
|
931
899
|
*
|
|
932
900
|
* @example
|
|
933
|
-
* <div>
|
|
934
|
-
* <code>
|
|
935
901
|
* // Click and drag the mouse to view the scene from different angles.
|
|
936
902
|
*
|
|
937
903
|
* let myGeometry;
|
|
@@ -992,11 +958,8 @@ class Geometry {
|
|
|
992
958
|
* pop();
|
|
993
959
|
* }
|
|
994
960
|
* }
|
|
995
|
-
* </code>
|
|
996
|
-
* </div>
|
|
997
961
|
*
|
|
998
|
-
*
|
|
999
|
-
* <code>
|
|
962
|
+
* @example
|
|
1000
963
|
* // Click and drag the mouse to view the scene from different angles.
|
|
1001
964
|
*
|
|
1002
965
|
* let myGeometry;
|
|
@@ -1041,11 +1004,8 @@ class Geometry {
|
|
|
1041
1004
|
* // Draw the p5.Geometry object.
|
|
1042
1005
|
* model(myGeometry);
|
|
1043
1006
|
* }
|
|
1044
|
-
* </code>
|
|
1045
|
-
* </div>
|
|
1046
1007
|
*
|
|
1047
|
-
*
|
|
1048
|
-
* <code>
|
|
1008
|
+
* @example
|
|
1049
1009
|
* // Click and drag the mouse to view the scene from different angles.
|
|
1050
1010
|
*
|
|
1051
1011
|
* let myGeometry;
|
|
@@ -1092,11 +1052,8 @@ class Geometry {
|
|
|
1092
1052
|
* }
|
|
1093
1053
|
* endShape();
|
|
1094
1054
|
* }
|
|
1095
|
-
* </code>
|
|
1096
|
-
* </div>
|
|
1097
1055
|
*
|
|
1098
|
-
*
|
|
1099
|
-
* <code>
|
|
1056
|
+
* @example
|
|
1100
1057
|
* // Click and drag the mouse to view the scene from different angles.
|
|
1101
1058
|
*
|
|
1102
1059
|
* let myGeometry;
|
|
@@ -1143,11 +1100,8 @@ class Geometry {
|
|
|
1143
1100
|
* }
|
|
1144
1101
|
* endShape();
|
|
1145
1102
|
* }
|
|
1146
|
-
* </code>
|
|
1147
|
-
* </div>
|
|
1148
1103
|
*
|
|
1149
|
-
*
|
|
1150
|
-
* <code>
|
|
1104
|
+
* @example
|
|
1151
1105
|
* // Click and drag the mouse to view the scene from different angles.
|
|
1152
1106
|
*
|
|
1153
1107
|
* let myGeometry;
|
|
@@ -1197,8 +1151,6 @@ class Geometry {
|
|
|
1197
1151
|
* }
|
|
1198
1152
|
* endShape();
|
|
1199
1153
|
* }
|
|
1200
|
-
* </code>
|
|
1201
|
-
* </div>
|
|
1202
1154
|
*/
|
|
1203
1155
|
computeNormals(shadingType = FLAT, { roundToPrecision = 3 } = {}) {
|
|
1204
1156
|
const vertexNormals = this.vertexNormals;
|
|
@@ -1353,8 +1305,6 @@ class Geometry {
|
|
|
1353
1305
|
|
|
1354
1306
|
/**
|
|
1355
1307
|
* @example
|
|
1356
|
-
* <div>
|
|
1357
|
-
* <code>
|
|
1358
1308
|
* let tetrahedron;
|
|
1359
1309
|
* function setup() {
|
|
1360
1310
|
* createCanvas(200, 200, WEBGL);
|
|
@@ -1382,6 +1332,7 @@ class Geometry {
|
|
|
1382
1332
|
* tetrahedron.faces.push([1, 2, 3]);
|
|
1383
1333
|
* tetrahedron.makeEdgesFromFaces();
|
|
1384
1334
|
* }
|
|
1335
|
+
*
|
|
1385
1336
|
* function draw() {
|
|
1386
1337
|
* background(200);
|
|
1387
1338
|
* strokeWeight(2);
|
|
@@ -1389,8 +1340,6 @@ class Geometry {
|
|
|
1389
1340
|
* rotateY(millis() * 0.001);
|
|
1390
1341
|
* model(tetrahedron);
|
|
1391
1342
|
* }
|
|
1392
|
-
* </code>
|
|
1393
|
-
* </div>
|
|
1394
1343
|
*/
|
|
1395
1344
|
makeEdgesFromFaces() {
|
|
1396
1345
|
this._makeTriangleEdges();
|
|
@@ -1681,8 +1630,6 @@ class Geometry {
|
|
|
1681
1630
|
* @chainable
|
|
1682
1631
|
*
|
|
1683
1632
|
* @example
|
|
1684
|
-
* <div>
|
|
1685
|
-
* <code>
|
|
1686
1633
|
* let myGeometry;
|
|
1687
1634
|
*
|
|
1688
1635
|
* function setup() {
|
|
@@ -1715,8 +1662,6 @@ class Geometry {
|
|
|
1715
1662
|
* // Draw the torus.
|
|
1716
1663
|
* model(myGeometry);
|
|
1717
1664
|
* }
|
|
1718
|
-
* </code>
|
|
1719
|
-
* </div>
|
|
1720
1665
|
*/
|
|
1721
1666
|
normalize() {
|
|
1722
1667
|
if (this.vertices.length > 0) {
|
|
@@ -1771,8 +1716,6 @@ class Geometry {
|
|
|
1771
1716
|
* See also the global <a href="#/p5/vertexProperty">vertexProperty()</a> function.
|
|
1772
1717
|
*
|
|
1773
1718
|
* @example
|
|
1774
|
-
* <div>
|
|
1775
|
-
* <code>
|
|
1776
1719
|
* let geo;
|
|
1777
1720
|
*
|
|
1778
1721
|
* function cartesianToSpherical(x, y, z) {
|
|
@@ -1842,8 +1785,6 @@ class Geometry {
|
|
|
1842
1785
|
* // Draw the geometry
|
|
1843
1786
|
* model(geo);
|
|
1844
1787
|
* }
|
|
1845
|
-
* </code>
|
|
1846
|
-
* </div>
|
|
1847
1788
|
*
|
|
1848
1789
|
* @param {String} propertyName the name of the vertex property.
|
|
1849
1790
|
* @param {Number|Number[]} data the data tied to the vertex property.
|
|
@@ -1964,8 +1905,6 @@ function geometry(p5, fn){
|
|
|
1964
1905
|
* @param {Function} [callback] function to call once the geometry is created.
|
|
1965
1906
|
*
|
|
1966
1907
|
* @example
|
|
1967
|
-
* <div>
|
|
1968
|
-
* <code>
|
|
1969
1908
|
* // Click and drag the mouse to view the scene from different angles.
|
|
1970
1909
|
*
|
|
1971
1910
|
* let myGeometry;
|
|
@@ -1996,11 +1935,8 @@ function geometry(p5, fn){
|
|
|
1996
1935
|
* // Draw the p5.Geometry object.
|
|
1997
1936
|
* model(myGeometry);
|
|
1998
1937
|
* }
|
|
1999
|
-
* </code>
|
|
2000
|
-
* </div>
|
|
2001
1938
|
*
|
|
2002
|
-
*
|
|
2003
|
-
* <code>
|
|
1939
|
+
* @example
|
|
2004
1940
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2005
1941
|
*
|
|
2006
1942
|
* let myGeometry;
|
|
@@ -2040,11 +1976,8 @@ function geometry(p5, fn){
|
|
|
2040
1976
|
* // left to top to right.
|
|
2041
1977
|
* this.faces.push([0, 1, 2]);
|
|
2042
1978
|
* }
|
|
2043
|
-
* </code>
|
|
2044
|
-
* </div>
|
|
2045
1979
|
*
|
|
2046
|
-
*
|
|
2047
|
-
* <code>
|
|
1980
|
+
* @example
|
|
2048
1981
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2049
1982
|
*
|
|
2050
1983
|
* let myGeometry;
|
|
@@ -2087,11 +2020,8 @@ function geometry(p5, fn){
|
|
|
2087
2020
|
* // Compute the surface normals to help with lighting.
|
|
2088
2021
|
* this.computeNormals();
|
|
2089
2022
|
* }
|
|
2090
|
-
* </code>
|
|
2091
|
-
* </div>
|
|
2092
2023
|
*
|
|
2093
|
-
*
|
|
2094
|
-
* <code>
|
|
2024
|
+
* @example
|
|
2095
2025
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2096
2026
|
*
|
|
2097
2027
|
* // Adapted from Paul Wheeler's wonderful p5.Geometry tutorial.
|
|
@@ -2168,8 +2098,6 @@ function geometry(p5, fn){
|
|
|
2168
2098
|
* // Compute the surface normals to help with lighting.
|
|
2169
2099
|
* this.computeNormals();
|
|
2170
2100
|
* }
|
|
2171
|
-
* </code>
|
|
2172
|
-
* </div>
|
|
2173
2101
|
*/
|
|
2174
2102
|
p5.Geometry = Geometry;
|
|
2175
2103
|
|
|
@@ -2188,8 +2116,6 @@ function geometry(p5, fn){
|
|
|
2188
2116
|
* @name vertices
|
|
2189
2117
|
*
|
|
2190
2118
|
* @example
|
|
2191
|
-
* <div>
|
|
2192
|
-
* <code>
|
|
2193
2119
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2194
2120
|
*
|
|
2195
2121
|
* let myGeometry;
|
|
@@ -2220,11 +2146,8 @@ function geometry(p5, fn){
|
|
|
2220
2146
|
* // Draw the p5.Geometry object.
|
|
2221
2147
|
* model(myGeometry);
|
|
2222
2148
|
* }
|
|
2223
|
-
* </code>
|
|
2224
|
-
* </div>
|
|
2225
2149
|
*
|
|
2226
|
-
*
|
|
2227
|
-
* <code>
|
|
2150
|
+
* @example
|
|
2228
2151
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2229
2152
|
*
|
|
2230
2153
|
* let myGeometry;
|
|
@@ -2272,8 +2195,6 @@ function geometry(p5, fn){
|
|
|
2272
2195
|
* pop();
|
|
2273
2196
|
* }
|
|
2274
2197
|
* }
|
|
2275
|
-
* </code>
|
|
2276
|
-
* </div>
|
|
2277
2198
|
*/
|
|
2278
2199
|
|
|
2279
2200
|
/**
|
|
@@ -2292,8 +2213,6 @@ function geometry(p5, fn){
|
|
|
2292
2213
|
* @for p5.Geometry
|
|
2293
2214
|
*
|
|
2294
2215
|
* @example
|
|
2295
|
-
* <div>
|
|
2296
|
-
* <code>
|
|
2297
2216
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2298
2217
|
*
|
|
2299
2218
|
* let myGeometry;
|
|
@@ -2354,11 +2273,8 @@ function geometry(p5, fn){
|
|
|
2354
2273
|
* pop();
|
|
2355
2274
|
* }
|
|
2356
2275
|
* }
|
|
2357
|
-
* </code>
|
|
2358
|
-
* </div>
|
|
2359
2276
|
*
|
|
2360
|
-
*
|
|
2361
|
-
* <code>
|
|
2277
|
+
* @example
|
|
2362
2278
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2363
2279
|
*
|
|
2364
2280
|
* let myGeometry;
|
|
@@ -2403,8 +2319,6 @@ function geometry(p5, fn){
|
|
|
2403
2319
|
* // Display the p5.Geometry object.
|
|
2404
2320
|
* model(myGeometry);
|
|
2405
2321
|
* }
|
|
2406
|
-
* </code>
|
|
2407
|
-
* </div>
|
|
2408
2322
|
*/
|
|
2409
2323
|
|
|
2410
2324
|
/**
|
|
@@ -2439,8 +2353,6 @@ function geometry(p5, fn){
|
|
|
2439
2353
|
* @for p5.Geometry
|
|
2440
2354
|
*
|
|
2441
2355
|
* @example
|
|
2442
|
-
* <div>
|
|
2443
|
-
* <code>
|
|
2444
2356
|
* // Click and drag the mouse to view the scene from different angles.
|
|
2445
2357
|
*
|
|
2446
2358
|
* let myGeometry;
|
|
@@ -2490,8 +2402,6 @@ function geometry(p5, fn){
|
|
|
2490
2402
|
*
|
|
2491
2403
|
* }
|
|
2492
2404
|
* }
|
|
2493
|
-
* </code>
|
|
2494
|
-
* </div>
|
|
2495
2405
|
*/
|
|
2496
2406
|
|
|
2497
2407
|
/**
|
|
@@ -2514,8 +2424,6 @@ function geometry(p5, fn){
|
|
|
2514
2424
|
* @for p5.Geometry
|
|
2515
2425
|
*
|
|
2516
2426
|
* @example
|
|
2517
|
-
* <div>
|
|
2518
|
-
* <code>
|
|
2519
2427
|
* let img;
|
|
2520
2428
|
*
|
|
2521
2429
|
* async function setup() {
|
|
@@ -2555,8 +2463,6 @@ function geometry(p5, fn){
|
|
|
2555
2463
|
* function createShape() {
|
|
2556
2464
|
* plane(40);
|
|
2557
2465
|
* }
|
|
2558
|
-
* </code>
|
|
2559
|
-
* </div>
|
|
2560
2466
|
*/
|
|
2561
2467
|
|
|
2562
2468
|
/**
|
package/dist/webgl/p5.Quat.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { ac as WEBGL, aa as WEBGL2, L as LIGHTEST, D as DARKEST, S as SUBTRACT, R as REPLACE, E as EXCLUSION, a as SCREEN, M as MULTIPLY, b as REMOVE, A as ADD, B as BLEND, c as TRIANGLES, p as CORNER, U as UNSIGNED_BYTE, g as LINEAR, aG as LINEAR_MIPMAP, h as TEXTURE, F as FLOAT, d as UNSIGNED_INT, H as HALF_FLOAT } from '../constants-
|
|
2
|
-
import { R as Renderer3D, o as readPixelWebGL, q as readPixelsWebGL, M as MipmapTexture, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, s as setWebGLUniformValue, e as setWebGLTextureParams, j as populateGLSLHooks, u as checkWebGLCapabilities } from '../rendering-
|
|
1
|
+
import { ac as WEBGL, aa as WEBGL2, L as LIGHTEST, D as DARKEST, S as SUBTRACT, R as REPLACE, E as EXCLUSION, a as SCREEN, M as MULTIPLY, b as REMOVE, A as ADD, B as BLEND, c as TRIANGLES, p as CORNER, U as UNSIGNED_BYTE, g as LINEAR, aG as LINEAR_MIPMAP, h as TEXTURE, F as FLOAT, d as UNSIGNED_INT, H as HALF_FLOAT } from '../constants-DQyACdzq.js';
|
|
2
|
+
import { R as Renderer3D, o as readPixelWebGL, q as readPixelsWebGL, M as MipmapTexture, h as getWebGLShaderAttributes, g as getWebGLUniformMetadata, s as setWebGLUniformValue, e as setWebGLTextureParams, j as populateGLSLHooks, u as checkWebGLCapabilities } from '../rendering-h9unX5K0.js';
|
|
3
3
|
import { getStrokeDefs } from './enums.js';
|
|
4
4
|
import { Shader } from './p5.Shader.js';
|
|
5
|
-
import { R as RGB, h as RGBA } from '../creating_reading-
|
|
6
|
-
import { I as Image } from '../p5.Renderer-
|
|
5
|
+
import { R as RGB, h as RGBA } from '../creating_reading-ZXzcZEsb.js';
|
|
6
|
+
import { I as Image } from '../p5.Renderer-D-5LdCRz.js';
|
|
7
7
|
import { glslBackend } from './strands_glslBackend.js';
|
|
8
8
|
import '../strands/ir_types.js';
|
|
9
9
|
import { getShaderHookTypes } from './shaderHookUtils.js';
|
|
@@ -23,7 +23,6 @@ import '../color/setting.js';
|
|
|
23
23
|
import 'omggif';
|
|
24
24
|
import '../io/csv.js';
|
|
25
25
|
import '../io/utilities.js';
|
|
26
|
-
import 'file-saver';
|
|
27
26
|
import 'gifenc';
|
|
28
27
|
import '../image/pixels.js';
|
|
29
28
|
import '../image/filters.js';
|
|
@@ -52,7 +51,7 @@ import '../ir_builders-DXNgaB9N.js';
|
|
|
52
51
|
import '../strands/ir_cfg.js';
|
|
53
52
|
import '../strands/strands_builtins.js';
|
|
54
53
|
|
|
55
|
-
var lightingShader = "#define PI 3.141592\n\nprecision highp float;\nprecision highp int;\n\nuniform mat4 uViewMatrix;\n\nuniform bool uUseLighting;\n\nuniform
|
|
54
|
+
var lightingShader = "#define PI 3.141592\n\nprecision highp float;\nprecision highp int;\n\nuniform mat4 uViewMatrix;\nuniform mat3 uCameraNormalMatrix;\n\nuniform bool uUseLighting;\n\nuniform int uDirectionalLightCount;\nuniform vec3 uLightingDirection[5];\nuniform vec3 uDirectionalDiffuseColors[5];\nuniform vec3 uDirectionalSpecularColors[5];\n\nuniform int uPointLightCount;\nuniform vec3 uPointLightLocation[5];\nuniform vec3 uPointLightDiffuseColors[5];\t\nuniform vec3 uPointLightSpecularColors[5];\n\nuniform int uSpotLightCount;\nuniform float uSpotLightAngle[5];\nuniform float uSpotLightConc[5];\nuniform vec3 uSpotLightDiffuseColors[5];\nuniform vec3 uSpotLightSpecularColors[5];\nuniform vec3 uSpotLightLocation[5];\nuniform vec3 uSpotLightDirection[5];\n\nuniform bool uSpecular;\nuniform float uShininess;\nuniform float uMetallic;\n\nuniform float uConstantAttenuation;\nuniform float uLinearAttenuation;\nuniform float uQuadraticAttenuation;\n\n// setting from _setImageLightUniforms()\n// boolean to initiate the calculateImageDiffuse and calculateImageSpecular\nuniform bool uUseImageLight;\n// texture for use in calculateImageDiffuse\nuniform sampler2D environmentMapDiffused;\n// texture for use in calculateImageSpecular\nuniform sampler2D environmentMapSpecular;\n\nconst float specularFactor = 2.0;\nconst float diffuseFactor = 0.73;\n\nstruct LightResult {\n float specular;\n float diffuse;\n};\n\nfloat _phongSpecular(\n vec3 lightDirection,\n vec3 viewDirection,\n vec3 surfaceNormal,\n float shininess) {\n\n vec3 R = reflect(lightDirection, surfaceNormal);\n return pow(max(0.0, dot(R, viewDirection)), shininess);\n}\n\nfloat _lambertDiffuse(vec3 lightDirection, vec3 surfaceNormal) {\n return max(0.0, dot(-lightDirection, surfaceNormal));\n}\n\nLightResult _light(vec3 viewDirection, vec3 normal, vec3 lightVector, float shininess, float metallic) {\n\n vec3 lightDir = normalize(lightVector);\n\n //compute our diffuse & specular terms\n LightResult lr;\n float specularIntensity = mix(1.0, 0.4, metallic);\n float diffuseIntensity = mix(1.0, 0.1, metallic);\n if (uSpecular)\n lr.specular = (_phongSpecular(lightDir, viewDirection, normal, shininess)) * specularIntensity;\n lr.diffuse = _lambertDiffuse(lightDir, normal) * diffuseIntensity;\n return lr;\n}\n\n// converts the range of \"value\" from [min1 to max1] to [min2 to max2]\nfloat map(float value, float min1, float max1, float min2, float max2) {\n return min2 + (value - min1) * (max2 - min2) / (max1 - min1);\n}\n\nvec2 mapTextureToNormal( vec3 v ){\n // x = r sin(phi) cos(theta) \n // y = r cos(phi) \n // z = r sin(phi) sin(theta)\n float phi = acos( v.y );\n // if phi is 0, then there are no x, z components\n float theta = 0.0;\n // else \n theta = acos(v.x / sin(phi));\n float sinTheta = v.z / sin(phi);\n if (sinTheta < 0.0) {\n // Turn it into -theta, but in the 0-2PI range\n theta = 2.0 * PI - theta;\n }\n theta = theta / (2.0 * 3.14159);\n phi = phi / 3.14159 ;\n \n vec2 angles = vec2( fract(theta + 0.25), 1.0 - phi );\n return angles;\n}\n\n\nvec3 calculateImageDiffuse(vec3 vNormal, vec3 vViewPosition, float metallic){\n // make 2 seperate builds \n vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0); // hardcoded world camera position\n vec3 worldNormal = normalize(vNormal * uCameraNormalMatrix);\n vec2 newTexCoor = mapTextureToNormal( worldNormal );\n vec4 texture = TEXTURE( environmentMapDiffused, newTexCoor );\n // this is to make the darker sections more dark\n // png and jpg usually flatten the brightness so it is to reverse that\n return mix(smoothstep(vec3(0.0), vec3(1.0), texture.xyz), vec3(0.0), metallic);\n}\n\nvec3 calculateImageSpecular(vec3 vNormal, vec3 vViewPosition, float shininess, float metallic){\n vec3 worldCameraPosition = vec3(0.0, 0.0, 0.0);\n vec3 worldNormal = normalize(vNormal);\n vec3 lightDirection = normalize( vViewPosition - worldCameraPosition );\n vec3 R = reflect(lightDirection, worldNormal) * uCameraNormalMatrix;\n vec2 newTexCoor = mapTextureToNormal( R );\n#ifdef WEBGL2\n // In p5js the range of shininess is >= 1,\n // Therefore roughness range will be ([0,1]*8)*20 or [0, 160]\n // The factor of 8 is because currently the getSpecularTexture\n // only calculated 8 different levels of roughness\n // The factor of 20 is just to spread up this range so that,\n // [1, max] of shininess is converted to [0,160] of roughness\n float roughness = 20. / shininess;\n vec4 outColor = textureLod(environmentMapSpecular, newTexCoor, roughness * 8.);\n#else\n vec4 outColor = TEXTURE(environmentMapSpecular, newTexCoor);\n#endif\n // this is to make the darker sections more dark\n // png and jpg usually flatten the brightness so it is to reverse that\n return mix(\n pow(outColor.xyz, vec3(10)),\n pow(outColor.xyz, vec3(1.2)),\n metallic \n );\n}\n\nvoid totalLight(\n vec3 modelPosition,\n vec3 normal,\n float shininess,\n float metallic,\n out vec3 totalDiffuse,\n out vec3 totalSpecular\n) {\n\n totalSpecular = vec3(0.0);\n\n if (!uUseLighting) {\n totalDiffuse = vec3(1.0);\n return;\n }\n\n totalDiffuse = vec3(0.0);\n\n vec3 viewDirection = normalize(-modelPosition);\n\n for (int j = 0; j < 5; j++) {\n if (j < uDirectionalLightCount) {\n vec3 lightVector = (uViewMatrix * vec4(uLightingDirection[j], 0.0)).xyz;\n vec3 lightColor = uDirectionalDiffuseColors[j];\n vec3 specularColor = uDirectionalSpecularColors[j];\n LightResult result = _light(viewDirection, normal, lightVector, shininess, metallic);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if (j < uPointLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uPointLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n //calculate attenuation\n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n vec3 lightColor = lightFalloff * uPointLightDiffuseColors[j];\n vec3 specularColor = lightFalloff * uPointLightSpecularColors[j];\n\n LightResult result = _light(viewDirection, normal, lightVector, shininess, metallic);\n totalDiffuse += result.diffuse * lightColor;\n totalSpecular += result.specular * lightColor * specularColor;\n }\n\n if(j < uSpotLightCount) {\n vec3 lightPosition = (uViewMatrix * vec4(uSpotLightLocation[j], 1.0)).xyz;\n vec3 lightVector = modelPosition - lightPosition;\n \n float lightDistance = length(lightVector);\n float lightFalloff = 1.0 / (uConstantAttenuation + lightDistance * uLinearAttenuation + (lightDistance * lightDistance) * uQuadraticAttenuation);\n\n vec3 lightDirection = (uViewMatrix * vec4(uSpotLightDirection[j], 0.0)).xyz;\n float spotDot = dot(normalize(lightVector), normalize(lightDirection));\n float spotFalloff;\n if(spotDot < uSpotLightAngle[j]) {\n spotFalloff = 0.0;\n }\n else {\n spotFalloff = pow(spotDot, uSpotLightConc[j]);\n }\n lightFalloff *= spotFalloff;\n\n vec3 lightColor = uSpotLightDiffuseColors[j];\n vec3 specularColor = uSpotLightSpecularColors[j];\n \n LightResult result = _light(viewDirection, normal, lightVector, shininess, metallic);\n \n totalDiffuse += result.diffuse * lightColor * lightFalloff;\n totalSpecular += result.specular * lightColor * specularColor * lightFalloff;\n }\n }\n\n if( uUseImageLight ){\n totalDiffuse += calculateImageDiffuse(normal, modelPosition, metallic);\n totalSpecular += calculateImageSpecular(normal, modelPosition, shininess, metallic);\n }\n\n totalDiffuse *= diffuseFactor;\n totalSpecular *= specularFactor;\n}\n";
|
|
56
55
|
|
|
57
56
|
var normalVert = "IN vec3 aPosition;\nIN vec3 aNormal;\nIN vec2 aTexCoord;\nIN vec4 aVertexColor;\n\n#define HOOK_DEFINES\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\nuniform mat4 uModelMatrix;\nuniform mat4 uViewMatrix;\nuniform mat3 uModelNormalMatrix;\nuniform mat3 uCameraNormalMatrix;\n#else\nuniform mat4 uModelViewMatrix;\nuniform mat3 uNormalMatrix;\n#endif\nuniform mat4 uProjectionMatrix;\n\nuniform vec4 uMaterialColor;\nuniform bool uUseVertexColor;\n\nOUT vec3 vVertexNormal;\nOUT highp vec2 vVertTexCoord;\nOUT vec4 vColor;\n\nstruct Vertex {\n vec3 position;\n vec3 normal;\n vec2 texCoord;\n vec4 color;\n};\n\nvoid main(void) {\n HOOK_beforeVertex();\n\n Vertex inputs;\n inputs.position = aPosition;\n inputs.normal = aNormal;\n inputs.texCoord = aTexCoord;\n inputs.color = (uUseVertexColor && aVertexColor.x >= 0.0) ? aVertexColor : uMaterialColor;\n#ifdef AUGMENTED_HOOK_getObjectInputs\n inputs = HOOK_getObjectInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n inputs.position = (uModelMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uModelNormalMatrix * inputs.normal;\n inputs = HOOK_getWorldInputs(inputs);\n#endif\n\n#ifdef AUGMENTED_HOOK_getWorldInputs\n // Already multiplied by the model matrix, just apply view\n inputs.position = (uViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uCameraNormalMatrix * inputs.normal;\n#else\n // Apply both at once\n inputs.position = (uModelViewMatrix * vec4(inputs.position, 1.)).xyz;\n inputs.normal = uNormalMatrix * inputs.normal;\n#endif\n#ifdef AUGMENTED_HOOK_getCameraInputs\n inputs = HOOK_getCameraInputs(inputs);\n#endif\n\n // Pass varyings to fragment shader\n vVertTexCoord = inputs.texCoord;\n vVertexNormal = normalize(inputs.normal);\n vColor = inputs.color;\n\n gl_Position = uProjectionMatrix * vec4(inputs.position, 1.);\n\n HOOK_afterVertex();\n}\n";
|
|
58
57
|
|
|
@@ -2008,8 +2007,6 @@ function rendererGL(p5, fn) {
|
|
|
2008
2007
|
* @param {String} key Name of attribute
|
|
2009
2008
|
* @param {Boolean} value New value of named attribute
|
|
2010
2009
|
* @example
|
|
2011
|
-
* <div>
|
|
2012
|
-
* <code>
|
|
2013
2010
|
* function setup() {
|
|
2014
2011
|
* createCanvas(100, 100, WEBGL);
|
|
2015
2012
|
* }
|
|
@@ -2024,11 +2021,8 @@ function rendererGL(p5, fn) {
|
|
|
2024
2021
|
* box(50);
|
|
2025
2022
|
* pop();
|
|
2026
2023
|
* }
|
|
2027
|
-
* </code>
|
|
2028
|
-
* </div>
|
|
2029
2024
|
*
|
|
2030
|
-
*
|
|
2031
|
-
* <code>
|
|
2025
|
+
* @example
|
|
2032
2026
|
* // Now with the antialias attribute set to true.
|
|
2033
2027
|
* function setup() {
|
|
2034
2028
|
* setAttributes('antialias', true);
|
|
@@ -2045,11 +2039,8 @@ function rendererGL(p5, fn) {
|
|
|
2045
2039
|
* box(50);
|
|
2046
2040
|
* pop();
|
|
2047
2041
|
* }
|
|
2048
|
-
* </code>
|
|
2049
|
-
* </div>
|
|
2050
2042
|
*
|
|
2051
|
-
*
|
|
2052
|
-
* <code>
|
|
2043
|
+
* @example
|
|
2053
2044
|
* // press the mouse button to disable perPixelLighting
|
|
2054
2045
|
* function setup() {
|
|
2055
2046
|
* createCanvas(100, 100, WEBGL);
|
|
@@ -2098,8 +2089,6 @@ function rendererGL(p5, fn) {
|
|
|
2098
2089
|
* noStroke();
|
|
2099
2090
|
* fill(255);
|
|
2100
2091
|
* }
|
|
2101
|
-
* </code>
|
|
2102
|
-
* </div>
|
|
2103
2092
|
*
|
|
2104
2093
|
* @alt a rotating cube with smoother edges
|
|
2105
2094
|
*/
|
package/dist/webgl/p5.Shader.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @requires core
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
const TypedArray = Object.getPrototypeOf(Uint8Array);
|
|
9
10
|
class Shader {
|
|
10
11
|
constructor(renderer, vertSrc, fragSrc, options = {}) {
|
|
11
12
|
this._renderer = renderer;
|
|
@@ -256,7 +257,7 @@ class Shader {
|
|
|
256
257
|
* sketch.setup = function() {
|
|
257
258
|
* sketch.createCanvas(200, 200, sketch.WEBGL);
|
|
258
259
|
* myShader = sketch.baseMaterialShader().modify(({ sketch }) => {
|
|
259
|
-
* let b = uniformFloat('b');
|
|
260
|
+
* let b = sketch.uniformFloat('b');
|
|
260
261
|
* sketch.getPixelInputs((inputs) => {
|
|
261
262
|
* inputs.color = [inputs.texCoord, b, 1];
|
|
262
263
|
* return inputs;
|
|
@@ -488,8 +489,6 @@ class Shader {
|
|
|
488
489
|
* @returns {p5.Shader} new shader compiled for the target context.
|
|
489
490
|
*
|
|
490
491
|
* @example
|
|
491
|
-
* <div>
|
|
492
|
-
* <code>
|
|
493
492
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
494
493
|
*
|
|
495
494
|
* // Create a string with the vertex shader program.
|
|
@@ -560,11 +559,8 @@ class Shader {
|
|
|
560
559
|
* // Draw the p5.Graphics object to the main canvas.
|
|
561
560
|
* image(pg, -25, -25);
|
|
562
561
|
* }
|
|
563
|
-
* </code>
|
|
564
|
-
* </div>
|
|
565
562
|
*
|
|
566
|
-
*
|
|
567
|
-
* <code>
|
|
563
|
+
* @example
|
|
568
564
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
569
565
|
*
|
|
570
566
|
* // Create a string with the vertex shader program.
|
|
@@ -633,8 +629,6 @@ class Shader {
|
|
|
633
629
|
* // Draw the box.
|
|
634
630
|
* box(50);
|
|
635
631
|
* }
|
|
636
|
-
* </code>
|
|
637
|
-
* </div>
|
|
638
632
|
*/
|
|
639
633
|
copyToContext(context) {
|
|
640
634
|
const shader = new Shader(
|
|
@@ -660,7 +654,6 @@ class Shader {
|
|
|
660
654
|
}
|
|
661
655
|
}
|
|
662
656
|
|
|
663
|
-
|
|
664
657
|
/**
|
|
665
658
|
* Queries the active attributes for this shader and loads
|
|
666
659
|
* their names and locations into the attributes array.
|
|
@@ -812,8 +805,6 @@ class Shader {
|
|
|
812
805
|
* data value to assign to the uniform. Must match the uniform’s data type.
|
|
813
806
|
*
|
|
814
807
|
* @example
|
|
815
|
-
* <div>
|
|
816
|
-
* <code>
|
|
817
808
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
818
809
|
*
|
|
819
810
|
* // Create a string with the vertex shader program.
|
|
@@ -866,11 +857,8 @@ class Shader {
|
|
|
866
857
|
*
|
|
867
858
|
* describe('A cyan square.');
|
|
868
859
|
* }
|
|
869
|
-
* </code>
|
|
870
|
-
* </div>
|
|
871
860
|
*
|
|
872
|
-
*
|
|
873
|
-
* <code>
|
|
861
|
+
* @example
|
|
874
862
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
875
863
|
*
|
|
876
864
|
* // Create a string with the vertex shader program.
|
|
@@ -930,11 +918,8 @@ class Shader {
|
|
|
930
918
|
* // Add a plane as a drawing surface.
|
|
931
919
|
* plane(100, 100);
|
|
932
920
|
* }
|
|
933
|
-
* </code>
|
|
934
|
-
* </div>
|
|
935
921
|
*
|
|
936
|
-
*
|
|
937
|
-
* <code>
|
|
922
|
+
* @example
|
|
938
923
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
939
924
|
*
|
|
940
925
|
* // Create a string with the vertex shader program.
|
|
@@ -1018,10 +1003,8 @@ class Shader {
|
|
|
1018
1003
|
* // Add a plane as a drawing surface.
|
|
1019
1004
|
* plane(100, 100);
|
|
1020
1005
|
* }
|
|
1021
|
-
* </code>
|
|
1022
|
-
* </div>
|
|
1023
1006
|
*/
|
|
1024
|
-
setUniform(uniformName,
|
|
1007
|
+
setUniform(uniformName, data) {
|
|
1025
1008
|
this.init();
|
|
1026
1009
|
|
|
1027
1010
|
const uniform = this.uniforms[uniformName];
|
|
@@ -1029,10 +1012,6 @@ class Shader {
|
|
|
1029
1012
|
return;
|
|
1030
1013
|
}
|
|
1031
1014
|
|
|
1032
|
-
const data = this._renderer._mapUniformData
|
|
1033
|
-
? this._renderer._mapUniformData(uniform, rawData)
|
|
1034
|
-
: rawData;
|
|
1035
|
-
|
|
1036
1015
|
if (uniform.isArray) {
|
|
1037
1016
|
if (
|
|
1038
1017
|
uniform._cachedData &&
|
|
@@ -1045,9 +1024,13 @@ class Shader {
|
|
|
1045
1024
|
} else if (uniform._cachedData && uniform._cachedData === data) {
|
|
1046
1025
|
return;
|
|
1047
1026
|
} else {
|
|
1048
|
-
if (Array.isArray(data)) {
|
|
1027
|
+
if (Array.isArray(data) || data instanceof TypedArray) {
|
|
1028
|
+
if (uniform._cachedData && this._renderer._arraysEqual(uniform._cachedData, data)) {
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1049
1031
|
uniform._cachedData = data.slice(0);
|
|
1050
1032
|
} else {
|
|
1033
|
+
if (uniform._cachedData === data) return;
|
|
1051
1034
|
uniform._cachedData = data;
|
|
1052
1035
|
}
|
|
1053
1036
|
}
|
|
@@ -1136,8 +1119,6 @@ function shader(p5, fn){
|
|
|
1136
1119
|
* - `fragment`: An object describing the available frament shader hooks.
|
|
1137
1120
|
*
|
|
1138
1121
|
* @example
|
|
1139
|
-
* <div>
|
|
1140
|
-
* <code>
|
|
1141
1122
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
1142
1123
|
*
|
|
1143
1124
|
* // Create a string with the vertex shader program.
|
|
@@ -1186,11 +1167,8 @@ function shader(p5, fn){
|
|
|
1186
1167
|
*
|
|
1187
1168
|
* describe('A yellow square.');
|
|
1188
1169
|
* }
|
|
1189
|
-
* </code>
|
|
1190
|
-
* </div>
|
|
1191
1170
|
*
|
|
1192
|
-
*
|
|
1193
|
-
* <code>
|
|
1171
|
+
* @example
|
|
1194
1172
|
* // Note: A "uniform" is a global variable within a shader program.
|
|
1195
1173
|
*
|
|
1196
1174
|
* let mandelbrot;
|
|
@@ -1215,8 +1193,6 @@ function shader(p5, fn){
|
|
|
1215
1193
|
* // Add a quad as a display surface for the shader.
|
|
1216
1194
|
* quad(-1, -1, 1, -1, 1, 1, -1, 1);
|
|
1217
1195
|
* }
|
|
1218
|
-
* </code>
|
|
1219
|
-
* </div>
|
|
1220
1196
|
*/
|
|
1221
1197
|
p5.Shader = Shader;
|
|
1222
1198
|
}
|