p5 1.11.11 → 1.11.13
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/README.md +13 -1090
- package/lib/p5.js +432 -93
- package/lib/p5.min.js +2 -2
- package/package.json +1 -1
package/lib/p5.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! p5.js v1.11.
|
|
1
|
+
/*! p5.js v1.11.13 April 08, 2026 */
|
|
2
2
|
(function (f) {
|
|
3
3
|
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
4
4
|
module.exports = f()
|
|
@@ -54995,7 +54995,7 @@
|
|
|
54995
54995
|
* a CSS color string.
|
|
54996
54996
|
*
|
|
54997
54997
|
* By default, `blue()` returns a color's blue value in the range 0
|
|
54998
|
-
* to 255. If the <a href="#/colorMode">colorMode()</a> is set to RGB, it
|
|
54998
|
+
* to 255. If the <a href="#/p5/colorMode">colorMode()</a> is set to RGB, it
|
|
54999
54999
|
* returns the blue value in the given range.
|
|
55000
55000
|
*
|
|
55001
55001
|
* @method blue
|
|
@@ -55130,7 +55130,7 @@
|
|
|
55130
55130
|
* a CSS color string.
|
|
55131
55131
|
*
|
|
55132
55132
|
* By default, `brightness()` returns a color's HSB brightness in the range 0
|
|
55133
|
-
* to 100. If the <a href="#/colorMode">colorMode()</a> is set to HSB, it
|
|
55133
|
+
* to 100. If the <a href="#/p5/colorMode">colorMode()</a> is set to HSB, it
|
|
55134
55134
|
* returns the brightness value in the given range.
|
|
55135
55135
|
*
|
|
55136
55136
|
* @method brightness
|
|
@@ -55565,7 +55565,7 @@
|
|
|
55565
55565
|
* a CSS color string.
|
|
55566
55566
|
*
|
|
55567
55567
|
* By default, `green()` returns a color's green value in the range 0
|
|
55568
|
-
* to 255. If the <a href="#/colorMode">colorMode()</a> is set to RGB, it
|
|
55568
|
+
* to 255. If the <a href="#/p5/colorMode">colorMode()</a> is set to RGB, it
|
|
55569
55569
|
* returns the green value in the given range.
|
|
55570
55570
|
*
|
|
55571
55571
|
* @method green
|
|
@@ -55701,7 +55701,7 @@
|
|
|
55701
55701
|
*
|
|
55702
55702
|
* Hue describes a color's position on the color wheel. By default, `hue()`
|
|
55703
55703
|
* returns a color's HSL hue in the range 0 to 360. If the
|
|
55704
|
-
* <a href="#/colorMode">colorMode()</a> is set to HSB or HSL, it returns the hue
|
|
55704
|
+
* <a href="#/p5/colorMode">colorMode()</a> is set to HSB or HSL, it returns the hue
|
|
55705
55705
|
* value in the given mode.
|
|
55706
55706
|
*
|
|
55707
55707
|
* @method hue
|
|
@@ -55953,7 +55953,7 @@
|
|
|
55953
55953
|
* distance to both.
|
|
55954
55954
|
*
|
|
55955
55955
|
* The way that colors are interpolated depends on the current
|
|
55956
|
-
* <a href="#/colorMode">colorMode()</a>.
|
|
55956
|
+
* <a href="#/p5/colorMode">colorMode()</a>.
|
|
55957
55957
|
*
|
|
55958
55958
|
* @method paletteLerp
|
|
55959
55959
|
* @param {[p5.Color, Number][]} colors_stops color stops to interpolate from
|
|
@@ -55999,7 +55999,7 @@
|
|
|
55999
55999
|
* a CSS color string.
|
|
56000
56000
|
*
|
|
56001
56001
|
* By default, `lightness()` returns a color's HSL lightness in the range 0
|
|
56002
|
-
* to 100. If the <a href="#/colorMode">colorMode()</a> is set to HSL, it
|
|
56002
|
+
* to 100. If the <a href="#/p5/colorMode">colorMode()</a> is set to HSL, it
|
|
56003
56003
|
* returns the lightness value in the given range.
|
|
56004
56004
|
*
|
|
56005
56005
|
* @method lightness
|
|
@@ -56143,7 +56143,7 @@
|
|
|
56143
56143
|
* a CSS color string.
|
|
56144
56144
|
*
|
|
56145
56145
|
* By default, `red()` returns a color's red value in the range 0
|
|
56146
|
-
* to 255. If the <a href="#/colorMode">colorMode()</a> is set to RGB, it
|
|
56146
|
+
* to 255. If the <a href="#/p5/colorMode">colorMode()</a> is set to RGB, it
|
|
56147
56147
|
* returns the red value in the given range.
|
|
56148
56148
|
*
|
|
56149
56149
|
* @method red
|
|
@@ -56279,7 +56279,7 @@
|
|
|
56279
56279
|
*
|
|
56280
56280
|
* Saturation is scaled differently in HSB and HSL. By default, `saturation()`
|
|
56281
56281
|
* returns a color's HSL saturation in the range 0 to 100. If the
|
|
56282
|
-
* <a href="#/colorMode">colorMode()</a> is set to HSB or HSL, it returns the
|
|
56282
|
+
* <a href="#/p5/colorMode">colorMode()</a> is set to HSB or HSL, it returns the
|
|
56283
56283
|
* saturation value in the given mode.
|
|
56284
56284
|
*
|
|
56285
56285
|
* @method saturation
|
|
@@ -59397,7 +59397,7 @@
|
|
|
59397
59397
|
* @property {String} VERSION
|
|
59398
59398
|
* @final
|
|
59399
59399
|
*/
|
|
59400
|
-
var VERSION = '1.11.
|
|
59400
|
+
var VERSION = '1.11.13';
|
|
59401
59401
|
// GRAPHICS RENDERER
|
|
59402
59402
|
/**
|
|
59403
59403
|
* The default, two-dimensional renderer.
|
|
@@ -68544,6 +68544,11 @@
|
|
|
68544
68544
|
{
|
|
68545
68545
|
key: 'remove',
|
|
68546
68546
|
value: function remove() {
|
|
68547
|
+
// Clean up WebGL resources if the renderer has a remove method
|
|
68548
|
+
// (WebGL renderers need to free GPU resources like shaders and textures)
|
|
68549
|
+
if (this._renderer && typeof this._renderer.remove === 'function') {
|
|
68550
|
+
this._renderer.remove();
|
|
68551
|
+
}
|
|
68547
68552
|
if (this.elt.parentNode) {
|
|
68548
68553
|
this.elt.parentNode.removeChild(this.elt);
|
|
68549
68554
|
}
|
|
@@ -71409,7 +71414,7 @@
|
|
|
71409
71414
|
* <div>
|
|
71410
71415
|
* <code>
|
|
71411
71416
|
* function setup() {
|
|
71412
|
-
* // Create a p5.
|
|
71417
|
+
* // Create a p5.Renderer object.
|
|
71413
71418
|
* let cnv = createCanvas(50, 50);
|
|
71414
71419
|
*
|
|
71415
71420
|
* // Position the canvas.
|
|
@@ -73406,6 +73411,11 @@
|
|
|
73406
73411
|
*
|
|
73407
73412
|
* background(200);
|
|
73408
73413
|
*
|
|
73414
|
+
*
|
|
73415
|
+
* // Making point to 5 pixels
|
|
73416
|
+
* strokeWeight(5);
|
|
73417
|
+
*
|
|
73418
|
+
*
|
|
73409
73419
|
* // Top-left.
|
|
73410
73420
|
* point(30, 20);
|
|
73411
73421
|
*
|
|
@@ -73432,6 +73442,11 @@
|
|
|
73432
73442
|
*
|
|
73433
73443
|
* background(200);
|
|
73434
73444
|
*
|
|
73445
|
+
*
|
|
73446
|
+
* // Making point to 5 pixels.
|
|
73447
|
+
* strokeWeight(5);
|
|
73448
|
+
*
|
|
73449
|
+
*
|
|
73435
73450
|
* // Top-left.
|
|
73436
73451
|
* point(30, 20);
|
|
73437
73452
|
*
|
|
@@ -73462,6 +73477,11 @@
|
|
|
73462
73477
|
*
|
|
73463
73478
|
* background(200);
|
|
73464
73479
|
*
|
|
73480
|
+
*
|
|
73481
|
+
* // Making point to 5 pixels.
|
|
73482
|
+
* strokeWeight(5);
|
|
73483
|
+
*
|
|
73484
|
+
*
|
|
73465
73485
|
* // Top-left.
|
|
73466
73486
|
* let a = createVector(30, 20);
|
|
73467
73487
|
* point(a);
|
|
@@ -111048,7 +111068,7 @@
|
|
|
111048
111068
|
* @static
|
|
111049
111069
|
* @param {p5.Vector} v1 first <a href="#/p5.Vector">p5.Vector</a>.
|
|
111050
111070
|
* @param {p5.Vector} v2 second <a href="#/p5.Vector">p5.Vector</a>.
|
|
111051
|
-
* @return {
|
|
111071
|
+
* @return {p5.Vector} cross product.
|
|
111052
111072
|
*/
|
|
111053
111073
|
|
|
111054
111074
|
},
|
|
@@ -119486,7 +119506,7 @@
|
|
|
119486
119506
|
planeGeom.computeFaces().computeNormals();
|
|
119487
119507
|
if (detailX <= 1 && detailY <= 1) {
|
|
119488
119508
|
planeGeom._makeTriangleEdges()._edgesToVertices();
|
|
119489
|
-
} else if (this._renderer._doStroke) {
|
|
119509
|
+
} else if (this._renderer._doStroke && !this._renderer.geometryBuilder) {
|
|
119490
119510
|
console.log('Cannot draw stroke on plane objects with more' + ' than 1 detailX or 1 detailY');
|
|
119491
119511
|
}
|
|
119492
119512
|
this._renderer.createBuffers(gId, planeGeom);
|
|
@@ -119760,7 +119780,7 @@
|
|
|
119760
119780
|
boxGeom.computeNormals();
|
|
119761
119781
|
if (detailX <= 4 && detailY <= 4) {
|
|
119762
119782
|
boxGeom._edgesToVertices();
|
|
119763
|
-
} else if (this._renderer._doStroke) {
|
|
119783
|
+
} else if (this._renderer._doStroke && !this._renderer.geometryBuilder) {
|
|
119764
119784
|
console.log('Cannot draw stroke on box objects with more' + ' than 4 detailX or 4 detailY');
|
|
119765
119785
|
} //initialize our geometry buffer with
|
|
119766
119786
|
//the key val pair:
|
|
@@ -120230,7 +120250,7 @@
|
|
|
120230
120250
|
// normals are computed in call to _truncatedCone
|
|
120231
120251
|
if (detailX <= 24 && detailY <= 16) {
|
|
120232
120252
|
cylinderGeom._makeTriangleEdges()._edgesToVertices();
|
|
120233
|
-
} else if (this._renderer._doStroke) {
|
|
120253
|
+
} else if (this._renderer._doStroke && !this._renderer.geometryBuilder) {
|
|
120234
120254
|
console.log('Cannot draw stroke on cylinder objects with more' + ' than 24 detailX or 16 detailY');
|
|
120235
120255
|
}
|
|
120236
120256
|
this._renderer.createBuffers(gId, cylinderGeom);
|
|
@@ -120457,7 +120477,7 @@
|
|
|
120457
120477
|
_truncatedCone.call(coneGeom, 1, 0, 1, detailX, detailY, cap, false);
|
|
120458
120478
|
if (detailX <= 24 && detailY <= 16) {
|
|
120459
120479
|
coneGeom._makeTriangleEdges()._edgesToVertices();
|
|
120460
|
-
} else if (this._renderer._doStroke) {
|
|
120480
|
+
} else if (this._renderer._doStroke && !this._renderer.geometryBuilder) {
|
|
120461
120481
|
console.log('Cannot draw stroke on cone objects with more' + ' than 24 detailX or 16 detailY');
|
|
120462
120482
|
}
|
|
120463
120483
|
this._renderer.createBuffers(gId, coneGeom);
|
|
@@ -120665,7 +120685,7 @@
|
|
|
120665
120685
|
ellipsoidGeom.computeFaces();
|
|
120666
120686
|
if (detailX <= 24 && detailY <= 24) {
|
|
120667
120687
|
ellipsoidGeom._makeTriangleEdges()._edgesToVertices();
|
|
120668
|
-
} else if (this._renderer._doStroke) {
|
|
120688
|
+
} else if (this._renderer._doStroke && !this._renderer.geometryBuilder) {
|
|
120669
120689
|
console.log('Cannot draw stroke on ellipsoids with more' + ' than 24 detailX or 24 detailY');
|
|
120670
120690
|
}
|
|
120671
120691
|
this._renderer.createBuffers(gId, ellipsoidGeom);
|
|
@@ -120869,7 +120889,7 @@
|
|
|
120869
120889
|
torusGeom.computeFaces();
|
|
120870
120890
|
if (detailX <= 24 && detailY <= 16) {
|
|
120871
120891
|
torusGeom._makeTriangleEdges()._edgesToVertices();
|
|
120872
|
-
} else if (this._renderer._doStroke) {
|
|
120892
|
+
} else if (this._renderer._doStroke && !this._renderer.geometryBuilder) {
|
|
120873
120893
|
console.log('Cannot draw strokes on torus object with more' + ' than 24 detailX or 16 detailY');
|
|
120874
120894
|
}
|
|
120875
120895
|
this._renderer.createBuffers(gId, torusGeom);
|
|
@@ -125664,11 +125684,10 @@
|
|
|
125664
125684
|
// Now, convert the given token into an index
|
|
125665
125685
|
var vertString = tokens[vertexTokens[tokenInd]];
|
|
125666
125686
|
var vertParts = vertString.split('/');
|
|
125667
|
-
// TODO: Faces can technically use negative numbers to refer to the
|
|
125668
|
-
// previous nth vertex. I haven't seen this used in practice, but
|
|
125669
|
-
// it might be good to implement this in the future.
|
|
125670
125687
|
for (var i = 0; i < vertParts.length; i++) {
|
|
125671
|
-
|
|
125688
|
+
var index = parseInt(vertParts[i]);
|
|
125689
|
+
if (index > 0) index -= 1; // OBJ uses 1-based indexing
|
|
125690
|
+
vertParts[i] = index;
|
|
125672
125691
|
}
|
|
125673
125692
|
if (!usedVerts[vertString]) {
|
|
125674
125693
|
usedVerts[vertString] = {
|
|
@@ -125676,17 +125695,17 @@
|
|
|
125676
125695
|
}
|
|
125677
125696
|
if (usedVerts[vertString][currentMaterial] === undefined) {
|
|
125678
125697
|
var vertIndex = model.vertices.length;
|
|
125679
|
-
model.vertices.push(loadedVerts.v
|
|
125680
|
-
model.uvs.push(loadedVerts.vt
|
|
125698
|
+
model.vertices.push(loadedVerts.v.at(vertParts[0]).copy());
|
|
125699
|
+
model.uvs.push(loadedVerts.vt.at(vertParts[1]) ? loadedVerts.vt.at(vertParts[1]).slice() : [
|
|
125681
125700
|
0,
|
|
125682
125701
|
0
|
|
125683
125702
|
]);
|
|
125684
|
-
model.vertexNormals.push(loadedVerts.vn
|
|
125703
|
+
model.vertexNormals.push(loadedVerts.vn.at(vertParts[2]) ? loadedVerts.vn.at(vertParts[2]).copy() : new _main.default.Vector());
|
|
125685
125704
|
usedVerts[vertString][currentMaterial] = vertIndex;
|
|
125686
125705
|
face.push(vertIndex);
|
|
125687
125706
|
if (currentMaterial && materials[currentMaterial] && materials[currentMaterial].diffuseColor) {
|
|
125688
125707
|
// Mark this vertex as colored
|
|
125689
|
-
coloredVerts.add(loadedVerts.v
|
|
125708
|
+
coloredVerts.add(loadedVerts.v.at(vertParts[0])); //since a set would only push unique values
|
|
125690
125709
|
}
|
|
125691
125710
|
} else {
|
|
125692
125711
|
face.push(usedVerts[vertString][currentMaterial]);
|
|
@@ -140980,14 +140999,49 @@
|
|
|
140980
140999
|
gl.drawArrays(drawMode || gl.TRIANGLES, 0, buffers.vertexCount);
|
|
140981
141000
|
}
|
|
140982
141001
|
};
|
|
140983
|
-
_main.default.RendererGL.prototype._drawPoints = function (vertices,
|
|
141002
|
+
_main.default.RendererGL.prototype._drawPoints = function (vertices, pointBuffers) {
|
|
140984
141003
|
var gl = this.GL;
|
|
140985
141004
|
var pointShader = this._getImmediatePointShader();
|
|
140986
|
-
|
|
140987
|
-
|
|
140988
|
-
|
|
141005
|
+
if (Array.isArray(pointBuffers)) {
|
|
141006
|
+
var geom = this.immediateMode.geometry;
|
|
141007
|
+
if (geom.vertices !== vertices) {
|
|
141008
|
+
geom.vertices = vertices;
|
|
141009
|
+
geom.dirtyFlags.vertices = true;
|
|
141010
|
+
if (geom.vertexStrokeColors.length > 0) {
|
|
141011
|
+
geom.vertexStrokeColors.length = 0;
|
|
141012
|
+
geom.dirtyFlags.vertexStrokeColors = true;
|
|
141013
|
+
}
|
|
141014
|
+
}
|
|
141015
|
+
this._setPointUniforms(pointShader);
|
|
141016
|
+
var _iteratorNormalCompletion4 = true;
|
|
141017
|
+
var _didIteratorError4 = false;
|
|
141018
|
+
var _iteratorError4 = undefined;
|
|
141019
|
+
try {
|
|
141020
|
+
for (var _iterator4 = pointBuffers[Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
141021
|
+
var buff = _step4.value;
|
|
141022
|
+
buff._prepareBuffer(geom, pointShader);
|
|
141023
|
+
}
|
|
141024
|
+
} catch (err) {
|
|
141025
|
+
_didIteratorError4 = true;
|
|
141026
|
+
_iteratorError4 = err;
|
|
141027
|
+
} finally {
|
|
141028
|
+
try {
|
|
141029
|
+
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
141030
|
+
_iterator4.return();
|
|
141031
|
+
}
|
|
141032
|
+
} finally {
|
|
141033
|
+
if (_didIteratorError4) {
|
|
141034
|
+
throw _iteratorError4;
|
|
141035
|
+
}
|
|
141036
|
+
}
|
|
141037
|
+
}
|
|
141038
|
+
} else {
|
|
141039
|
+
this._setPointUniforms(pointShader);
|
|
141040
|
+
this._bindBuffer(pointBuffers, gl.ARRAY_BUFFER, this._vToNArray(vertices), Float32Array, gl.STATIC_DRAW);
|
|
141041
|
+
pointShader.enableAttrib(pointShader.attributes.aPosition, 3);
|
|
141042
|
+
}
|
|
140989
141043
|
this._applyColorBlend(this.curStrokeColor);
|
|
140990
|
-
gl.drawArrays(gl.
|
|
141044
|
+
gl.drawArrays(gl.POINTS, 0, vertices.length);
|
|
140991
141045
|
pointShader.unbindShader();
|
|
140992
141046
|
};
|
|
140993
141047
|
var _default = _main.default.RendererGL;
|
|
@@ -141417,8 +141471,8 @@
|
|
|
141417
141471
|
fontFrag: '#ifndef WEBGL2\n#extension GL_OES_standard_derivatives : enable\n#endif\n\n#if 0\n // simulate integer math using floats\n\t#define int float\n\t#define ivec2 vec2\n\t#define INT(x) float(x)\n\n\tint ifloor(float v) { return floor(v); }\n\tivec2 ifloor(vec2 v) { return floor(v); }\n\n#else\n // use native integer math\n\tprecision highp int;\n\t#define INT(x) x\n\n\tint ifloor(float v) { return int(v); }\n\tint ifloor(int v) { return v; }\n\tivec2 ifloor(vec2 v) { return ivec2(v); }\n\n#endif\n\nuniform sampler2D uSamplerStrokes;\nuniform sampler2D uSamplerRowStrokes;\nuniform sampler2D uSamplerRows;\nuniform sampler2D uSamplerColStrokes;\nuniform sampler2D uSamplerCols;\n\nuniform ivec2 uStrokeImageSize;\nuniform ivec2 uCellsImageSize;\nuniform ivec2 uGridImageSize;\n\nuniform ivec2 uGridOffset;\nuniform ivec2 uGridSize;\nuniform vec4 uMaterialColor;\n\nIN vec2 vTexCoord;\n\n// some helper functions\nint ROUND(float v) { return ifloor(v + 0.5); }\nivec2 ROUND(vec2 v) { return ifloor(v + 0.5); }\nfloat saturate(float v) { return clamp(v, 0.0, 1.0); }\nvec2 saturate(vec2 v) { return clamp(v, 0.0, 1.0); }\n\nint mul(float v1, int v2) {\n return ifloor(v1 * float(v2));\n}\n\nivec2 mul(vec2 v1, ivec2 v2) {\n return ifloor(v1 * vec2(v2) + 0.5);\n}\n\n// unpack a 16-bit integer from a float vec2\nint getInt16(vec2 v) {\n ivec2 iv = ROUND(v * 255.0);\n return iv.x * INT(128) + iv.y;\n}\n\nvec2 pixelScale;\nvec2 coverage = vec2(0.0);\nvec2 weight = vec2(0.5);\nconst float minDistance = 1.0/8192.0;\nconst float hardness = 1.05; // amount of antialias\n\n// the maximum number of curves in a glyph\nconst int N = INT(250);\n\n// retrieves an indexed pixel from a sampler\nvec4 getTexel(sampler2D sampler, int pos, ivec2 size) {\n int width = size.x;\n int y = ifloor(pos / width);\n int x = pos - y * width; // pos % width\n\n return TEXTURE(sampler, (vec2(x, y) + 0.5) / vec2(size));\n}\n\nvoid calulateCrossings(vec2 p0, vec2 p1, vec2 p2, out vec2 C1, out vec2 C2) {\n\n // get the coefficients of the quadratic in t\n vec2 a = p0 - p1 * 2.0 + p2;\n vec2 b = p0 - p1;\n vec2 c = p0 - vTexCoord;\n\n // found out which values of \'t\' it crosses the axes\n vec2 surd = sqrt(max(vec2(0.0), b * b - a * c));\n vec2 t1 = ((b - surd) / a).yx;\n vec2 t2 = ((b + surd) / a).yx;\n\n // approximate straight lines to avoid rounding errors\n if (abs(a.y) < 0.001)\n t1.x = t2.x = c.y / (2.0 * b.y);\n\n if (abs(a.x) < 0.001)\n t1.y = t2.y = c.x / (2.0 * b.x);\n\n // plug into quadratic formula to find the corrdinates of the crossings\n C1 = ((a * t1 - b * 2.0) * t1 + c) * pixelScale;\n C2 = ((a * t2 - b * 2.0) * t2 + c) * pixelScale;\n}\n\nvoid coverageX(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n // determine on which side of the x-axis the points lie\n bool y0 = p0.y > vTexCoord.y;\n bool y1 = p1.y > vTexCoord.y;\n bool y2 = p2.y > vTexCoord.y;\n\n // could web be under the curve (after t1)?\n if (y1 ? !y2 : y0) {\n // add the coverage for t1\n coverage.x += saturate(C1.x + 0.5);\n // calculate the anti-aliasing for t1\n weight.x = min(weight.x, abs(C1.x));\n }\n\n // are we outside the curve (after t2)?\n if (y1 ? !y0 : y2) {\n // subtract the coverage for t2\n coverage.x -= saturate(C2.x + 0.5);\n // calculate the anti-aliasing for t2\n weight.x = min(weight.x, abs(C2.x));\n }\n}\n\n// this is essentially the same as coverageX, but with the axes swapped\nvoid coverageY(vec2 p0, vec2 p1, vec2 p2) {\n\n vec2 C1, C2;\n calulateCrossings(p0, p1, p2, C1, C2);\n\n bool x0 = p0.x > vTexCoord.x;\n bool x1 = p1.x > vTexCoord.x;\n bool x2 = p2.x > vTexCoord.x;\n\n if (x1 ? !x2 : x0) {\n coverage.y -= saturate(C1.y + 0.5);\n weight.y = min(weight.y, abs(C1.y));\n }\n\n if (x1 ? !x0 : x2) {\n coverage.y += saturate(C2.y + 0.5);\n weight.y = min(weight.y, abs(C2.y));\n }\n}\n\nvoid main() {\n\n // calculate the pixel scale based on screen-coordinates\n pixelScale = hardness / fwidth(vTexCoord);\n\n // which grid cell is this pixel in?\n ivec2 gridCoord = ifloor(vTexCoord * vec2(uGridSize));\n\n // intersect curves in this row\n {\n // the index into the row info bitmap\n int rowIndex = gridCoord.y + uGridOffset.y;\n // fetch the info texel\n vec4 rowInfo = getTexel(uSamplerRows, rowIndex, uGridImageSize);\n // unpack the rowInfo\n int rowStrokeIndex = getInt16(rowInfo.xy);\n int rowStrokeCount = getInt16(rowInfo.zw);\n\n for (int iRowStroke = INT(0); iRowStroke < N; iRowStroke++) {\n if (iRowStroke >= rowStrokeCount)\n break;\n\n // each stroke is made up of 3 points: the start and control point\n // and the start of the next curve.\n // fetch the indices of this pair of strokes:\n vec4 strokeIndices = getTexel(uSamplerRowStrokes, rowStrokeIndex++, uCellsImageSize);\n\n // unpack the stroke index\n int strokePos = getInt16(strokeIndices.xy);\n\n // fetch the two strokes\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n\n // calculate the coverage\n coverageX(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n // intersect curves in this column\n {\n int colIndex = gridCoord.x + uGridOffset.x;\n vec4 colInfo = getTexel(uSamplerCols, colIndex, uGridImageSize);\n int colStrokeIndex = getInt16(colInfo.xy);\n int colStrokeCount = getInt16(colInfo.zw);\n \n for (int iColStroke = INT(0); iColStroke < N; iColStroke++) {\n if (iColStroke >= colStrokeCount)\n break;\n\n vec4 strokeIndices = getTexel(uSamplerColStrokes, colStrokeIndex++, uCellsImageSize);\n\n int strokePos = getInt16(strokeIndices.xy);\n vec4 stroke0 = getTexel(uSamplerStrokes, strokePos + INT(0), uStrokeImageSize);\n vec4 stroke1 = getTexel(uSamplerStrokes, strokePos + INT(1), uStrokeImageSize);\n coverageY(stroke0.xy, stroke0.zw, stroke1.xy);\n }\n }\n\n weight = saturate(1.0 - weight * 2.0);\n float distance = max(weight.x + weight.y, minDistance); // manhattan approx.\n float antialias = abs(dot(coverage, weight) / distance);\n float cover = min(abs(coverage.x), abs(coverage.y));\n OUT_COLOR = vec4(uMaterialColor.rgb, 1.) * uMaterialColor.a;\n OUT_COLOR *= saturate(max(antialias, cover));\n}\n',
|
|
141418
141472
|
lineVert: lineDefs + '/*\n Part of the Processing project - http://processing.org\n Copyright (c) 2012-15 The Processing Foundation\n Copyright (c) 2004-12 Ben Fry and Casey Reas\n Copyright (c) 2001-04 Massachusetts Institute of Technology\n This library is free software; you can redistribute it and/or\n modify it under the terms of the GNU Lesser General Public\n License as published by the Free Software Foundation, version 2.1.\n This library is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n Lesser General Public License for more details.\n You should have received a copy of the GNU Lesser General\n Public License along with this library; if not, write to the\n Free Software Foundation, Inc., 59 Temple Place, Suite 330,\n Boston, MA 02111-1307 USA\n*/\n\n#define PROCESSING_LINE_SHADER\n\nprecision highp int;\nprecision highp float;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform float uStrokeWeight;\n\nuniform bool uUseLineColor;\nuniform vec4 uMaterialColor;\n\nuniform vec4 uViewport;\nuniform int uPerspective;\nuniform int uStrokeJoin;\n\nIN vec4 aPosition;\nIN vec3 aTangentIn;\nIN vec3 aTangentOut;\nIN float aSide;\nIN vec4 aVertexColor;\n\nOUT vec4 vColor;\nOUT vec2 vTangent;\nOUT vec2 vCenter;\nOUT vec2 vPosition;\nOUT float vMaxDist;\nOUT float vCap;\nOUT float vJoin;\nOUT float vStrokeWeight;\n\nvec2 lineIntersection(vec2 aPoint, vec2 aDir, vec2 bPoint, vec2 bDir) {\n // Rotate and translate so a starts at the origin and goes out to the right\n bPoint -= aPoint;\n vec2 rotatedBFrom = vec2(\n bPoint.x*aDir.x + bPoint.y*aDir.y,\n bPoint.y*aDir.x - bPoint.x*aDir.y\n );\n vec2 bTo = bPoint + bDir;\n vec2 rotatedBTo = vec2(\n bTo.x*aDir.x + bTo.y*aDir.y,\n bTo.y*aDir.x - bTo.x*aDir.y\n );\n float intersectionDistance =\n rotatedBTo.x + (rotatedBFrom.x - rotatedBTo.x) * rotatedBTo.y /\n (rotatedBTo.y - rotatedBFrom.y);\n return aPoint + aDir * intersectionDistance;\n}\n\nvoid main() {\n HOOK_beforeVertex();\n // Caps have one of either the in or out tangent set to 0\n vCap = (aTangentIn == vec3(0.)) != (aTangentOut == (vec3(0.)))\n ? 1. : 0.;\n\n // Joins have two unique, defined tangents\n vJoin = (\n aTangentIn != vec3(0.) &&\n aTangentOut != vec3(0.) &&\n aTangentIn != aTangentOut\n ) ? 1. : 0.;\n\n vec4 localPosition = vec4(HOOK_getLocalPosition(aPosition.xyz), 1.);\n vec4 posp = vec4(HOOK_getWorldPosition((uModelViewMatrix * localPosition).xyz), 1.);\n vec4 posqIn = posp + uModelViewMatrix * vec4(aTangentIn, 0);\n vec4 posqOut = posp + uModelViewMatrix * vec4(aTangentOut, 0);\n float strokeWeight = HOOK_getStrokeWeight(uStrokeWeight);\n vStrokeWeight = strokeWeight;\n\n float facingCamera = pow(\n // The word space tangent\'s z value is 0 if it\'s facing the camera\n abs(normalize(posqIn-posp).z),\n\n // Using pow() here to ramp `facingCamera` up from 0 to 1 really quickly\n // so most lines get scaled and don\'t get clipped\n 0.25\n );\n\n // Moving vertices slightly toward the camera\n // to avoid depth-fighting with the fill triangles.\n // A mix of scaling and offsetting is used based on distance\n // Discussion here:\n // https://github.com/processing/p5.js/issues/7200 \n\n // using a scale <1 moves the lines towards nearby camera\n // in order to prevent popping effects due to half of\n // the line disappearing behind the geometry faces.\n float zDistance = -posp.z; \n float distanceFactor = smoothstep(0.0, 800.0, zDistance); \n \n // Discussed here:\n // http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=252848 \n float scale = mix(1., 0.995, facingCamera);\n float dynamicScale = mix(scale, 1.0, distanceFactor); // Closer = more scale, farther = less\n\n posp.xyz = posp.xyz * dynamicScale;\n posqIn.xyz = posqIn.xyz * dynamicScale;\n posqOut.xyz = posqOut.xyz * dynamicScale;\n\n // Moving vertices slightly toward camera when far away \n // https://github.com/processing/p5.js/issues/6956 \n float zOffset = mix(0., -1., facingCamera);\n float dynamicZAdjustment = mix(0.0, zOffset, distanceFactor); // Closer = less zAdjustment, farther = more\n\n posp.z -= dynamicZAdjustment;\n posqIn.z -= dynamicZAdjustment;\n posqOut.z -= dynamicZAdjustment;\n \n vec4 p = uProjectionMatrix * posp;\n vec4 qIn = uProjectionMatrix * posqIn;\n vec4 qOut = uProjectionMatrix * posqOut;\n vCenter = HOOK_getLineCenter(p.xy);\n\n // formula to convert from clip space (range -1..1) to screen space (range 0..[width or height])\n // screen_p = (p.xy/p.w + <1,1>) * 0.5 * uViewport.zw\n\n // prevent division by W by transforming the tangent formula (div by 0 causes\n // the line to disappear, see https://github.com/processing/processing/issues/5183)\n // t = screen_q - screen_p\n //\n // tangent is normalized and we don\'t care which aDirection it points to (+-)\n // t = +- normalize( screen_q - screen_p )\n // t = +- normalize( (q.xy/q.w+<1,1>)*0.5*uViewport.zw - (p.xy/p.w+<1,1>)*0.5*uViewport.zw )\n //\n // extract common factor, <1,1> - <1,1> cancels out\n // t = +- normalize( (q.xy/q.w - p.xy/p.w) * 0.5 * uViewport.zw )\n //\n // convert to common divisor\n // t = +- normalize( ((q.xy*p.w - p.xy*q.w) / (p.w*q.w)) * 0.5 * uViewport.zw )\n //\n // remove the common scalar divisor/factor, not needed due to normalize and +-\n // (keep uViewport - can\'t remove because it has different components for x and y\n // and corrects for aspect ratio, see https://github.com/processing/processing/issues/5181)\n // t = +- normalize( (q.xy*p.w - p.xy*q.w) * uViewport.zw )\n\n vec2 tangentIn = normalize((qIn.xy*p.w - p.xy*qIn.w) * uViewport.zw);\n vec2 tangentOut = normalize((qOut.xy*p.w - p.xy*qOut.w) * uViewport.zw);\n\n vec2 curPerspScale;\n if(uPerspective == 1) {\n // Perspective ---\n // convert from world to clip by multiplying with projection scaling factor\n // to get the right thickness (see https://github.com/processing/processing/issues/5182)\n\n // The y value of the projection matrix may be flipped if rendering to a Framebuffer.\n // Multiplying again by its sign here negates the flip to get just the scale.\n curPerspScale = (uProjectionMatrix * vec4(1, sign(uProjectionMatrix[1][1]), 0, 0)).xy;\n } else {\n // No Perspective ---\n // multiply by W (to cancel out division by W later in the pipeline) and\n // convert from screen to clip (derived from clip to screen above)\n curPerspScale = p.w / (0.5 * uViewport.zw);\n }\n\n vec2 offset;\n if (vJoin == 1.) {\n vTangent = normalize(tangentIn + tangentOut);\n vec2 normalIn = vec2(-tangentIn.y, tangentIn.x);\n vec2 normalOut = vec2(-tangentOut.y, tangentOut.x);\n float side = sign(aSide);\n float sideEnum = abs(aSide);\n\n // We generate vertices for joins on either side of the centerline, but\n // the "elbow" side is the only one needing a join. By not setting the\n // offset for the other side, all its vertices will end up in the same\n // spot and not render, effectively discarding it.\n if (sign(dot(tangentOut, vec2(-tangentIn.y, tangentIn.x))) != side) {\n // Side enums:\n // 1: the side going into the join\n // 2: the middle of the join\n // 3: the side going out of the join\n if (sideEnum == 2.) {\n // Calculate the position + tangent on either side of the join, and\n // find where the lines intersect to find the elbow of the join\n vec2 c = (posp.xy/posp.w + vec2(1.,1.)) * 0.5 * uViewport.zw;\n vec2 intersection = lineIntersection(\n c + (side * normalIn * strokeWeight / 2.),\n tangentIn,\n c + (side * normalOut * strokeWeight / 2.),\n tangentOut\n );\n offset = (intersection - c);\n\n // When lines are thick and the angle of the join approaches 180, the\n // elbow might be really far from the center. We\'ll apply a limit to\n // the magnitude to avoid lines going across the whole screen when this\n // happens.\n float mag = length(offset);\n float maxMag = 3. * strokeWeight;\n if (mag > maxMag) {\n offset *= maxMag / mag;\n }\n } else if (sideEnum == 1.) {\n offset = side * normalIn * strokeWeight / 2.;\n } else if (sideEnum == 3.) {\n offset = side * normalOut * strokeWeight / 2.;\n }\n }\n if (uStrokeJoin == STROKE_JOIN_BEVEL) {\n vec2 avgNormal = vec2(-vTangent.y, vTangent.x);\n vMaxDist = abs(dot(avgNormal, normalIn * strokeWeight / 2.));\n } else {\n vMaxDist = strokeWeight / 2.;\n }\n } else {\n vec2 tangent = aTangentIn == vec3(0.) ? tangentOut : tangentIn;\n vTangent = tangent;\n vec2 normal = vec2(-tangent.y, tangent.x);\n\n float normalOffset = sign(aSide);\n // Caps will have side values of -2 or 2 on the edge of the cap that\n // extends out from the line\n float tangentOffset = abs(aSide) - 1.;\n offset = (normal * normalOffset + tangent * tangentOffset) *\n strokeWeight * 0.5;\n vMaxDist = strokeWeight / 2.;\n }\n vPosition = HOOK_getLinePosition(vCenter + offset);\n\n gl_Position.xy = p.xy + offset.xy * curPerspScale;\n gl_Position.zw = p.zw;\n \n vColor = HOOK_getVertexColor(uUseLineColor ? aVertexColor : uMaterialColor);\n HOOK_afterVertex();\n}\n',
|
|
141419
141473
|
lineFrag: lineDefs + 'precision highp int;\nprecision highp float;\n\nuniform vec4 uMaterialColor;\nuniform int uStrokeCap;\nuniform int uStrokeJoin;\n\nIN vec4 vColor;\nIN vec2 vTangent;\nIN vec2 vCenter;\nIN vec2 vPosition;\nIN float vStrokeWeight;\nIN float vMaxDist;\nIN float vCap;\nIN float vJoin;\n\nfloat distSquared(vec2 a, vec2 b) {\n vec2 aToB = b - a;\n return dot(aToB, aToB);\n}\n\nstruct Inputs {\n vec4 color;\n vec2 tangent;\n vec2 center;\n vec2 position;\n float strokeWeight;\n};\n\nvoid main() {\n HOOK_beforeFragment();\n\n Inputs inputs;\n inputs.color = vColor;\n inputs.tangent = vTangent;\n inputs.center = vCenter;\n inputs.position = vPosition;\n inputs.strokeWeight = vStrokeWeight;\n inputs = HOOK_getPixelInputs(inputs);\n\n if (vCap > 0.) {\n if (\n uStrokeCap == STROKE_CAP_ROUND &&\n HOOK_shouldDiscard(distSquared(inputs.position, inputs.center) > inputs.strokeWeight * inputs.strokeWeight * 0.25)\n ) {\n discard;\n } else if (\n uStrokeCap == STROKE_CAP_SQUARE &&\n HOOK_shouldDiscard(dot(inputs.position - inputs.center, inputs.tangent) > 0.)\n ) {\n discard;\n // Use full area for PROJECT\n } else if (HOOK_shouldDiscard(false)) {\n discard;\n }\n } else if (vJoin > 0.) {\n if (\n uStrokeJoin == STROKE_JOIN_ROUND &&\n HOOK_shouldDiscard(distSquared(inputs.position, inputs.center) > inputs.strokeWeight * inputs.strokeWeight * 0.25)\n ) {\n discard;\n } else if (uStrokeJoin == STROKE_JOIN_BEVEL) {\n vec2 normal = vec2(-inputs.tangent.y, inputs.tangent.x);\n if (HOOK_shouldDiscard(abs(dot(inputs.position - inputs.center, normal)) > vMaxDist)) {\n discard;\n }\n // Use full area for MITER\n } else if (HOOK_shouldDiscard(false)) {\n discard;\n }\n }\n OUT_COLOR = HOOK_getFinalColor(vec4(inputs.color.rgb, 1.) * inputs.color.a);\n HOOK_afterFragment();\n}\n',
|
|
141420
|
-
pointVert: 'IN vec3 aPosition;\nuniform float uPointSize;\nOUT float vStrokeWeight;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvoid main() {\n HOOK_beforeVertex();\n vec4 viewModelPosition = vec4(HOOK_getWorldPosition(\n (uModelViewMatrix * vec4(HOOK_getLocalPosition(aPosition), 1.0)).xyz\n ), 1.);\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n float pointSize = HOOK_getPointSize(uPointSize);\n\n\tgl_PointSize = pointSize;\n\tvStrokeWeight = pointSize;\n HOOK_afterVertex();\n}\n',
|
|
141421
|
-
pointFrag: 'precision mediump int;\nuniform vec4 uMaterialColor;\nIN float vStrokeWeight;\n\nvoid main(){\n HOOK_beforeFragment();\n float mask = 0.0;\n\n // make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n mask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n // if strokeWeight is 1 or less lets just draw a square\n // this prevents weird artifacting from carving circles when our points are really small\n // if strokeWeight is larger than 1, we just use it as is\n\n mask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n // throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n if(HOOK_shouldDiscard(mask > 0.98)){\n discard;\n }\n\n OUT_COLOR = HOOK_getFinalColor(vec4(
|
|
141474
|
+
pointVert: 'IN vec3 aPosition;\nIN vec4 aVertexColor;\nuniform float uPointSize;\nuniform bool uUseVertexColor;\nuniform vec4 uMaterialColor;\nOUT float vStrokeWeight;\nOUT vec4 vColor;\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\n\nvoid main() {\n HOOK_beforeVertex();\n vec4 viewModelPosition = vec4(HOOK_getWorldPosition(\n (uModelViewMatrix * vec4(HOOK_getLocalPosition(aPosition), 1.0)).xyz\n ), 1.);\n gl_Position = uProjectionMatrix * viewModelPosition; \n\n float pointSize = HOOK_getPointSize(uPointSize);\n\n\tgl_PointSize = pointSize;\n\tvStrokeWeight = pointSize;\n\n // Choose per-vertex stroke color when available; otherwise use uniform stroke color\n vec4 baseColor = uUseVertexColor ? aVertexColor : uMaterialColor;\n vColor = HOOK_getVertexColor(baseColor);\n HOOK_afterVertex();\n}\n',
|
|
141475
|
+
pointFrag: 'precision mediump int;\nuniform vec4 uMaterialColor;\nIN float vStrokeWeight;\nIN vec4 vColor;\n\nvoid main(){\n HOOK_beforeFragment();\n float mask = 0.0;\n\n // make a circular mask using the gl_PointCoord (goes from 0 - 1 on a point)\n // might be able to get a nicer edge on big strokeweights with smoothstep but slightly less performant\n\n mask = step(0.98, length(gl_PointCoord * 2.0 - 1.0));\n\n // if strokeWeight is 1 or less lets just draw a square\n // this prevents weird artifacting from carving circles when our points are really small\n // if strokeWeight is larger than 1, we just use it as is\n\n mask = mix(0.0, mask, clamp(floor(vStrokeWeight - 0.5),0.0,1.0));\n\n // throw away the borders of the mask\n // otherwise we get weird alpha blending issues\n\n if(HOOK_shouldDiscard(mask > 0.98)){\n discard;\n }\n\n // Use the interpolated vertex color (set in vertex shader)\n vec4 baseColor = vColor;\n OUT_COLOR = HOOK_getFinalColor(vec4(baseColor.rgb, 1.) * baseColor.a);\n HOOK_afterFragment();\n}\n',
|
|
141422
141476
|
imageLightVert: 'precision highp float;\nattribute vec3 aPosition;\nattribute vec3 aNormal;\nattribute vec2 aTexCoord;\n\nvarying vec3 localPos;\nvarying vec3 vWorldNormal;\nvarying vec3 vWorldPosition;\nvarying vec2 vTexCoord;\n\nuniform mat4 uModelViewMatrix;\nuniform mat4 uProjectionMatrix;\nuniform mat3 uNormalMatrix;\n\nvoid main() {\n // Multiply the position by the matrix.\n vec4 viewModelPosition = uModelViewMatrix * vec4(aPosition, 1.0);\n gl_Position = uProjectionMatrix * viewModelPosition; \n \n // orient the normals and pass to the fragment shader\n vWorldNormal = uNormalMatrix * aNormal;\n \n // send the view position to the fragment shader\n vWorldPosition = (uModelViewMatrix * vec4(aPosition, 1.0)).xyz;\n \n localPos = vWorldPosition;\n vTexCoord = aTexCoord;\n}\n\n\n/*\nin 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.\n*/\n',
|
|
141423
141477
|
imageLightDiffusedFrag: 'precision highp float;\nvarying vec3 localPos;\n\n// the HDR cubemap converted (can be from an equirectangular environment map.)\nuniform sampler2D environmentMap;\nvarying vec2 vTexCoord;\n\nconst float PI = 3.14159265359;\n\nvec2 nTOE( 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( phi, theta );\n return angles;\n}\n\nfloat random(vec2 p) {\n vec3 p3 = fract(vec3(p.xyx) * .1031);\n p3 += dot(p3, p3.yzx + 33.33);\n return fract((p3.x + p3.y) * p3.z);\n}\n\nvoid main()\n{ \t \n\t// the sample direction equals the hemisphere\'s orientation\n float phi = vTexCoord.x * 2.0 * PI;\n float theta = vTexCoord.y * PI;\n float x = sin(theta) * cos(phi);\n float y = sin(theta) * sin(phi);\n float z = cos(theta);\n vec3 normal = vec3( x, y, z);\n\n\t// Discretely sampling the hemisphere given the integral\'s\n // spherical coordinates translates to the following fragment code:\n\tvec3 irradiance = vec3(0.0); \n\tvec3 up\t= vec3(0.0, 1.0, 0.0);\n\tvec3 right = normalize(cross(up, normal));\n\tup = normalize(cross(normal, right));\n\n\t// We specify a fixed sampleDelta delta value to traverse\n // the hemisphere; decreasing or increasing the sample delta\n // will increase or decrease the accuracy respectively.\n\tconst float sampleDelta = 0.100;\n\tfloat nrSamples = 0.0;\n float randomOffset = random(gl_FragCoord.xy) * sampleDelta;\n\tfor(float rawPhi = 0.0; rawPhi < 2.0 * PI; rawPhi += sampleDelta)\n\t{\n float phi = rawPhi + randomOffset;\n for(float rawTheta = 0.0; rawTheta < ( 0.5 ) * PI; rawTheta += sampleDelta)\n {\n float theta = rawTheta + randomOffset;\n // spherical to cartesian (in tangent space) // tangent space to world // add each sample result to irradiance\n float x = sin(theta) * cos(phi);\n float y = sin(theta) * sin(phi);\n float z = cos(theta);\n vec3 tangentSample = vec3( x, y, z);\n \n vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal;\n irradiance += (texture2D(environmentMap, nTOE(sampleVec)).xyz) * cos(theta) * sin(theta);\n nrSamples++;\n }\n\t}\n\t// divide by the total number of samples taken, giving us the average sampled irradiance.\n\tirradiance = PI * irradiance * (1.0 / float(nrSamples )) ;\n \n \n\tgl_FragColor = vec4(irradiance, 1.0);\n}',
|
|
141424
141478
|
imageLightSpecularFrag: 'precision highp float;\r\nvarying vec3 localPos;\r\nvarying vec2 vTexCoord;\r\n\r\n// our texture\r\nuniform sampler2D environmentMap;\r\nuniform float roughness;\r\n\r\nconst float PI = 3.14159265359;\r\n\r\nfloat VanDerCorput(int bits);\r\nvec2 HammersleyNoBitOps(int i, int N);\r\nvec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness);\r\n\r\n\r\nvec2 nTOE( vec3 v ){\r\n // x = r sin(phi) cos(theta) \r\n // y = r cos(phi) \r\n // z = r sin(phi) sin(theta)\r\n float phi = acos( v.y );\r\n // if phi is 0, then there are no x, z components\r\n float theta = 0.0;\r\n // else \r\n theta = acos(v.x / sin(phi));\r\n float sinTheta = v.z / sin(phi);\r\n if (sinTheta < 0.0) {\r\n // Turn it into -theta, but in the 0-2PI range\r\n theta = 2.0 * PI - theta;\r\n }\r\n theta = theta / (2.0 * 3.14159);\r\n phi = phi / 3.14159 ;\r\n \r\n vec2 angles = vec2( phi, theta );\r\n return angles;\r\n}\r\n\r\n\r\nvoid main(){\r\n const int SAMPLE_COUNT = 400; // 4096\r\n int lowRoughnessLimit = int(pow(2.0,(roughness+0.1)*20.0));\r\n float totalWeight = 0.0;\r\n vec3 prefilteredColor = vec3(0.0);\r\n float phi = vTexCoord.x * 2.0 * PI;\r\n float theta = vTexCoord.y * PI;\r\n float x = sin(theta) * cos(phi);\r\n float y = sin(theta) * sin(phi);\r\n float z = cos(theta);\r\n vec3 N = vec3(x,y,z);\r\n vec3 V = N;\r\n for (int i = 0; i < SAMPLE_COUNT; ++i)\r\n {\r\n // break at smaller sample numbers for low roughness levels\r\n if(i == lowRoughnessLimit)\r\n {\r\n break;\r\n }\r\n vec2 Xi = HammersleyNoBitOps(i, SAMPLE_COUNT);\r\n vec3 H = ImportanceSampleGGX(Xi, N, roughness);\r\n vec3 L = normalize(2.0 * dot(V, H) * H - V);\r\n\r\n float NdotL = max(dot(N, L), 0.0);\r\n if (NdotL > 0.0)\r\n {\r\n prefilteredColor += texture2D(environmentMap, nTOE(L)).xyz * NdotL;\r\n totalWeight += NdotL;\r\n }\r\n }\r\n prefilteredColor = prefilteredColor / totalWeight;\r\n\r\n gl_FragColor = vec4(prefilteredColor, 1.0);\r\n}\r\n\r\nvec3 ImportanceSampleGGX(vec2 Xi, vec3 N, float roughness){\r\n float a = roughness * roughness;\r\n\r\n float phi = 2.0 * PI * Xi.x;\r\n float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (a * a - 1.0) * Xi.y));\r\n float sinTheta = sqrt(1.0 - cosTheta * cosTheta);\r\n // from spherical coordinates to cartesian coordinates\r\n vec3 H;\r\n H.x = cos(phi) * sinTheta;\r\n H.y = sin(phi) * sinTheta;\r\n H.z = cosTheta;\r\n\r\n // from tangent-space vector to world-space sample vector\r\n vec3 up = abs(N.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);\r\n vec3 tangent = normalize(cross(up, N));\r\n vec3 bitangent = cross(N, tangent);\r\n\r\n vec3 sampleVec = tangent * H.x + bitangent * H.y + N * H.z;\r\n return normalize(sampleVec);\r\n}\r\n\r\n\r\nfloat VanDerCorput(int n, int base)\r\n{\r\n#ifdef WEBGL2\r\n\r\n uint bits = uint(n);\r\n bits = (bits << 16u) | (bits >> 16u);\r\n bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);\r\n bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);\r\n bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);\r\n bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);\r\n return float(bits) * 2.3283064365386963e-10; // / 0x100000000\r\n\r\n#else\r\n\r\n float invBase = 1.0 / float(base);\r\n float denom = 1.0;\r\n float result = 0.0;\r\n\r\n\r\n for (int i = 0; i < 32; ++i)\r\n {\r\n if (n > 0)\r\n {\r\n denom = mod(float(n), 2.0);\r\n result += denom * invBase;\r\n invBase = invBase / 2.0;\r\n n = int(float(n) / 2.0);\r\n }\r\n }\r\n\r\n\r\n return result;\r\n\r\n#endif\r\n}\r\n\r\nvec2 HammersleyNoBitOps(int i, int N)\r\n{\r\n return vec2(float(i) / float(N), VanDerCorput(i, 2));\r\n}\r\n'
|
|
@@ -141933,11 +141987,14 @@
|
|
|
141933
141987
|
new _main.default.RenderBuffer(3, 'lineTangentsOut', 'lineTangentsOutBuffer', 'aTangentOut', _assertThisInitialized(_this)),
|
|
141934
141988
|
new _main.default.RenderBuffer(1, 'lineSides', 'lineSidesBuffer', 'aSide', _assertThisInitialized(_this))
|
|
141935
141989
|
],
|
|
141936
|
-
point:
|
|
141990
|
+
point: [
|
|
141991
|
+
new _main.default.RenderBuffer(3, 'vertices', 'pointVertexBuffer', 'aPosition', _assertThisInitialized(_this), _this._vToNArray),
|
|
141992
|
+
new _main.default.RenderBuffer(4, 'vertexStrokeColors', 'pointColorBuffer', 'aVertexColor', _assertThisInitialized(_this))
|
|
141993
|
+
]
|
|
141937
141994
|
}
|
|
141938
141995
|
};
|
|
141939
|
-
_this.pointSize = 5; //default point size
|
|
141940
141996
|
_this.curStrokeWeight = 1;
|
|
141997
|
+
_this.pointSize = _this.curStrokeWeight;
|
|
141941
141998
|
_this.curStrokeCap = constants.ROUND;
|
|
141942
141999
|
_this.curStrokeJoin = constants.ROUND;
|
|
141943
142000
|
// map of texture sources to textures created in this gl context via this.getTexture(src)
|
|
@@ -141975,22 +142032,218 @@
|
|
|
141975
142032
|
_this.fontInfos = {
|
|
141976
142033
|
};
|
|
141977
142034
|
_this._curShader = undefined;
|
|
142035
|
+
// Register cleanup hook to free WebGL resources when sketch is removed
|
|
142036
|
+
// Only register if this is the main p5 instance (not a p5.Graphics)
|
|
142037
|
+
// For p5.Graphics, cleanup is called directly from p5.Graphics.remove()
|
|
142038
|
+
var isPGraphics = _this._pInst instanceof _main.default.Graphics;
|
|
142039
|
+
if (!isPGraphics && _this._pInst && typeof _this._pInst.registerMethod === 'function') {
|
|
142040
|
+
_this._pInst.registerMethod('remove', _this.remove.bind(_assertThisInitialized(_this)));
|
|
142041
|
+
}
|
|
141978
142042
|
return _this;
|
|
141979
142043
|
} /**
|
|
141980
|
-
|
|
141981
|
-
|
|
141982
|
-
|
|
141983
|
-
|
|
141984
|
-
|
|
141985
|
-
|
|
141986
|
-
* If you need to draw complex shapes every frame which don't change over time,
|
|
141987
|
-
* combining them upfront with `beginGeometry()` and `endGeometry()` and then
|
|
141988
|
-
* drawing that will run faster than repeatedly drawing the individual pieces.
|
|
141989
|
-
*
|
|
141990
|
-
* @method beginGeometry
|
|
142044
|
+
* Frees all WebGL resources (shaders, textures, buffers) associated with
|
|
142045
|
+
* this renderer. Called automatically when the p5 instance is removed,
|
|
142046
|
+
* or when a p5.Graphics object is removed.
|
|
142047
|
+
*
|
|
142048
|
+
* @method remove
|
|
142049
|
+
* @private
|
|
141991
142050
|
*/
|
|
141992
142051
|
|
|
141993
142052
|
_createClass(RendererGL, [
|
|
142053
|
+
{
|
|
142054
|
+
key: 'remove',
|
|
142055
|
+
value: function remove() {
|
|
142056
|
+
// Remove all cached shaders
|
|
142057
|
+
var shadersToRemove = [
|
|
142058
|
+
this._defaultLightShader,
|
|
142059
|
+
this._defaultImmediateModeShader,
|
|
142060
|
+
this._defaultNormalShader,
|
|
142061
|
+
this._defaultColorShader,
|
|
142062
|
+
this._defaultPointShader,
|
|
142063
|
+
this.userFillShader,
|
|
142064
|
+
this.userStrokeShader,
|
|
142065
|
+
this.userPointShader,
|
|
142066
|
+
this._curShader,
|
|
142067
|
+
this.specularShader,
|
|
142068
|
+
this.diffusedShader,
|
|
142069
|
+
this.filterShader
|
|
142070
|
+
];
|
|
142071
|
+
// Also add filter shaders
|
|
142072
|
+
if (this.defaultFilterShaders) {
|
|
142073
|
+
for (var _key in this.defaultFilterShaders) {
|
|
142074
|
+
shadersToRemove.push(this.defaultFilterShaders[_key]);
|
|
142075
|
+
}
|
|
142076
|
+
} // Remove each shader
|
|
142077
|
+
|
|
142078
|
+
for (var _i = 0, _shadersToRemove = shadersToRemove; _i < _shadersToRemove.length; _i++) {
|
|
142079
|
+
var shader = _shadersToRemove[_i];
|
|
142080
|
+
if (shader && typeof shader.remove === 'function') {
|
|
142081
|
+
shader.remove();
|
|
142082
|
+
}
|
|
142083
|
+
} // Remove all cached textures
|
|
142084
|
+
|
|
142085
|
+
if (this.textures) {
|
|
142086
|
+
var _iteratorNormalCompletion = true;
|
|
142087
|
+
var _didIteratorError = false;
|
|
142088
|
+
var _iteratorError = undefined;
|
|
142089
|
+
try {
|
|
142090
|
+
for (var _iterator = this.textures.values() [Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
142091
|
+
var texture = _step.value;
|
|
142092
|
+
if (texture && typeof texture.remove === 'function') {
|
|
142093
|
+
texture.remove();
|
|
142094
|
+
}
|
|
142095
|
+
}
|
|
142096
|
+
} catch (err) {
|
|
142097
|
+
_didIteratorError = true;
|
|
142098
|
+
_iteratorError = err;
|
|
142099
|
+
} finally {
|
|
142100
|
+
try {
|
|
142101
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
142102
|
+
_iterator.return();
|
|
142103
|
+
}
|
|
142104
|
+
} finally {
|
|
142105
|
+
if (_didIteratorError) {
|
|
142106
|
+
throw _iteratorError;
|
|
142107
|
+
}
|
|
142108
|
+
}
|
|
142109
|
+
}
|
|
142110
|
+
this.textures.clear();
|
|
142111
|
+
} // Remove all framebuffers (they have their own remove() method)
|
|
142112
|
+
|
|
142113
|
+
if (this.framebuffers) {
|
|
142114
|
+
var _iteratorNormalCompletion2 = true;
|
|
142115
|
+
var _didIteratorError2 = false;
|
|
142116
|
+
var _iteratorError2 = undefined;
|
|
142117
|
+
try {
|
|
142118
|
+
for (var _iterator2 = this.framebuffers[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
142119
|
+
var fb = _step2.value;
|
|
142120
|
+
if (fb && typeof fb.remove === 'function') {
|
|
142121
|
+
fb.remove();
|
|
142122
|
+
}
|
|
142123
|
+
}
|
|
142124
|
+
} catch (err) {
|
|
142125
|
+
_didIteratorError2 = true;
|
|
142126
|
+
_iteratorError2 = err;
|
|
142127
|
+
} finally {
|
|
142128
|
+
try {
|
|
142129
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
|
142130
|
+
_iterator2.return();
|
|
142131
|
+
}
|
|
142132
|
+
} finally {
|
|
142133
|
+
if (_didIteratorError2) {
|
|
142134
|
+
throw _iteratorError2;
|
|
142135
|
+
}
|
|
142136
|
+
}
|
|
142137
|
+
}
|
|
142138
|
+
this.framebuffers.clear();
|
|
142139
|
+
} // Clean up diffused and specular texture caches (these store framebuffers)
|
|
142140
|
+
|
|
142141
|
+
if (this.diffusedTextures) {
|
|
142142
|
+
var _iteratorNormalCompletion3 = true;
|
|
142143
|
+
var _didIteratorError3 = false;
|
|
142144
|
+
var _iteratorError3 = undefined;
|
|
142145
|
+
try {
|
|
142146
|
+
for (var _iterator3 = this.diffusedTextures.values() [Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
142147
|
+
var _fb = _step3.value;
|
|
142148
|
+
if (_fb && typeof _fb.remove === 'function') {
|
|
142149
|
+
_fb.remove();
|
|
142150
|
+
}
|
|
142151
|
+
}
|
|
142152
|
+
} catch (err) {
|
|
142153
|
+
_didIteratorError3 = true;
|
|
142154
|
+
_iteratorError3 = err;
|
|
142155
|
+
} finally {
|
|
142156
|
+
try {
|
|
142157
|
+
if (!_iteratorNormalCompletion3 && _iterator3.return != null) {
|
|
142158
|
+
_iterator3.return();
|
|
142159
|
+
}
|
|
142160
|
+
} finally {
|
|
142161
|
+
if (_didIteratorError3) {
|
|
142162
|
+
throw _iteratorError3;
|
|
142163
|
+
}
|
|
142164
|
+
}
|
|
142165
|
+
}
|
|
142166
|
+
this.diffusedTextures.clear();
|
|
142167
|
+
}
|
|
142168
|
+
if (this.specularTextures) {
|
|
142169
|
+
var _iteratorNormalCompletion4 = true;
|
|
142170
|
+
var _didIteratorError4 = false;
|
|
142171
|
+
var _iteratorError4 = undefined;
|
|
142172
|
+
try {
|
|
142173
|
+
for (var _iterator4 = this.specularTextures.values() [Symbol.iterator](), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
|
|
142174
|
+
var _fb2 = _step4.value;
|
|
142175
|
+
if (_fb2 && typeof _fb2.remove === 'function') {
|
|
142176
|
+
_fb2.remove();
|
|
142177
|
+
}
|
|
142178
|
+
}
|
|
142179
|
+
} catch (err) {
|
|
142180
|
+
_didIteratorError4 = true;
|
|
142181
|
+
_iteratorError4 = err;
|
|
142182
|
+
} finally {
|
|
142183
|
+
try {
|
|
142184
|
+
if (!_iteratorNormalCompletion4 && _iterator4.return != null) {
|
|
142185
|
+
_iterator4.return();
|
|
142186
|
+
}
|
|
142187
|
+
} finally {
|
|
142188
|
+
if (_didIteratorError4) {
|
|
142189
|
+
throw _iteratorError4;
|
|
142190
|
+
}
|
|
142191
|
+
}
|
|
142192
|
+
}
|
|
142193
|
+
this.specularTextures.clear();
|
|
142194
|
+
} // Remove empty texture singleton
|
|
142195
|
+
|
|
142196
|
+
if (this._emptyTexture) {
|
|
142197
|
+
if (typeof this._emptyTexture.remove === 'function') {
|
|
142198
|
+
this._emptyTexture.remove();
|
|
142199
|
+
}
|
|
142200
|
+
this._emptyTexture = null;
|
|
142201
|
+
} // Free all retained mode geometry buffers
|
|
142202
|
+
|
|
142203
|
+
if (this.retainedMode && this.retainedMode.geometry) {
|
|
142204
|
+
for (var gId in this.retainedMode.geometry) {
|
|
142205
|
+
this._freeBuffers(gId);
|
|
142206
|
+
}
|
|
142207
|
+
} // Clean up filter layers
|
|
142208
|
+
|
|
142209
|
+
if (this.filterLayer && typeof this.filterLayer.remove === 'function') {
|
|
142210
|
+
this.filterLayer.remove();
|
|
142211
|
+
this.filterLayer = undefined;
|
|
142212
|
+
}
|
|
142213
|
+
if (this.filterLayerTemp && typeof this.filterLayerTemp.remove === 'function') {
|
|
142214
|
+
this.filterLayerTemp.remove();
|
|
142215
|
+
this.filterLayerTemp = undefined;
|
|
142216
|
+
} // Clear shader references
|
|
142217
|
+
|
|
142218
|
+
this._defaultLightShader = undefined;
|
|
142219
|
+
this._defaultImmediateModeShader = undefined;
|
|
142220
|
+
this._defaultNormalShader = undefined;
|
|
142221
|
+
this._defaultColorShader = undefined;
|
|
142222
|
+
this._defaultPointShader = undefined;
|
|
142223
|
+
this.userFillShader = undefined;
|
|
142224
|
+
this.userStrokeShader = undefined;
|
|
142225
|
+
this.userPointShader = undefined;
|
|
142226
|
+
this._curShader = undefined;
|
|
142227
|
+
this.specularShader = undefined;
|
|
142228
|
+
this.diffusedShader = undefined;
|
|
142229
|
+
this.filterShader = undefined;
|
|
142230
|
+
this.defaultFilterShaders = {
|
|
142231
|
+
};
|
|
142232
|
+
} /**
|
|
142233
|
+
* Starts creating a new p5.Geometry. Subsequent shapes drawn will be added
|
|
142234
|
+
* to the geometry and then returned when
|
|
142235
|
+
* <a href="#/p5/endGeometry">endGeometry()</a> is called. One can also use
|
|
142236
|
+
* <a href="#/p5/buildGeometry">buildGeometry()</a> to pass a function that
|
|
142237
|
+
* draws shapes.
|
|
142238
|
+
*
|
|
142239
|
+
* If you need to draw complex shapes every frame which don't change over time,
|
|
142240
|
+
* combining them upfront with `beginGeometry()` and `endGeometry()` and then
|
|
142241
|
+
* drawing that will run faster than repeatedly drawing the individual pieces.
|
|
142242
|
+
*
|
|
142243
|
+
* @method beginGeometry
|
|
142244
|
+
*/
|
|
142245
|
+
|
|
142246
|
+
},
|
|
141994
142247
|
{
|
|
141995
142248
|
key: 'beginGeometry',
|
|
141996
142249
|
value: function beginGeometry() {
|
|
@@ -142229,6 +142482,21 @@
|
|
|
142229
142482
|
key: 'background',
|
|
142230
142483
|
value: function background() {
|
|
142231
142484
|
var _this$_pInst;
|
|
142485
|
+
var a0 = arguments.length <= 0 ? undefined : arguments[0];
|
|
142486
|
+
var isImageLike = a0 instanceof _main.default.Image || a0 instanceof _main.default.Graphics || typeof HTMLImageElement !== 'undefined' && a0 instanceof HTMLImageElement || typeof HTMLVideoElement !== 'undefined' && a0 instanceof HTMLVideoElement || typeof _main.default.MediaElement !== 'undefined' && a0 instanceof _main.default.MediaElement;
|
|
142487
|
+
// WEBGL: support background(image)
|
|
142488
|
+
if (arguments.length > 0 && isImageLike) {
|
|
142489
|
+
// Clear WebGL buffers (color + depth)
|
|
142490
|
+
this._pInst.clear();
|
|
142491
|
+
// Draw background image in screen space (ignore camera)
|
|
142492
|
+
this._pInst.push();
|
|
142493
|
+
this._pInst.resetMatrix();
|
|
142494
|
+
this._pInst.imageMode(this._pInst.CENTER);
|
|
142495
|
+
this._pInst.image(a0, 0, 0, this._pInst.width, this._pInst.height);
|
|
142496
|
+
this._pInst.pop();
|
|
142497
|
+
return;
|
|
142498
|
+
} // Default WEBGL background(color)
|
|
142499
|
+
|
|
142232
142500
|
var _col = (_this$_pInst = this._pInst).color.apply(_this$_pInst, arguments);
|
|
142233
142501
|
var _r = _col.levels[0] / 255;
|
|
142234
142502
|
var _g = _col.levels[1] / 255;
|
|
@@ -142756,27 +143024,27 @@
|
|
|
142756
143024
|
if (typeof pixelsState.pixels !== 'undefined') {
|
|
142757
143025
|
pixelsState._setProperty('pixels', new Uint8Array(this.GL.drawingBufferWidth * this.GL.drawingBufferHeight * 4));
|
|
142758
143026
|
}
|
|
142759
|
-
var
|
|
142760
|
-
var
|
|
142761
|
-
var
|
|
143027
|
+
var _iteratorNormalCompletion5 = true;
|
|
143028
|
+
var _didIteratorError5 = false;
|
|
143029
|
+
var _iteratorError5 = undefined;
|
|
142762
143030
|
try {
|
|
142763
|
-
for (var
|
|
142764
|
-
var framebuffer =
|
|
143031
|
+
for (var _iterator5 = this.framebuffers[Symbol.iterator](), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
|
|
143032
|
+
var framebuffer = _step5.value;
|
|
142765
143033
|
// Notify framebuffers of the resize so that any auto-sized framebuffers
|
|
142766
143034
|
// can also update their size
|
|
142767
143035
|
framebuffer._canvasSizeChanged();
|
|
142768
143036
|
}
|
|
142769
143037
|
} catch (err) {
|
|
142770
|
-
|
|
142771
|
-
|
|
143038
|
+
_didIteratorError5 = true;
|
|
143039
|
+
_iteratorError5 = err;
|
|
142772
143040
|
} finally {
|
|
142773
143041
|
try {
|
|
142774
|
-
if (!
|
|
142775
|
-
|
|
143042
|
+
if (!_iteratorNormalCompletion5 && _iterator5.return != null) {
|
|
143043
|
+
_iterator5.return();
|
|
142776
143044
|
}
|
|
142777
143045
|
} finally {
|
|
142778
|
-
if (
|
|
142779
|
-
throw
|
|
143046
|
+
if (_didIteratorError5) {
|
|
143047
|
+
throw _iteratorError5;
|
|
142780
143048
|
}
|
|
142781
143049
|
}
|
|
142782
143050
|
}
|
|
@@ -142983,8 +143251,8 @@
|
|
|
142983
143251
|
if (this._clipDepths.length > 0 && this._pushPopDepth === this._clipDepths[this._clipDepths.length - 1]) {
|
|
142984
143252
|
this._clearClip();
|
|
142985
143253
|
}
|
|
142986
|
-
for (var _len = arguments.length, args = new Array(_len),
|
|
142987
|
-
args[
|
|
143254
|
+
for (var _len = arguments.length, args = new Array(_len), _key2 = 0; _key2 < _len; _key2++) {
|
|
143255
|
+
args[_key2] = arguments[_key2];
|
|
142988
143256
|
}(_get2 = _get(_getPrototypeOf(RendererGL.prototype), 'pop', this)).call.apply(_get2, [
|
|
142989
143257
|
this
|
|
142990
143258
|
].concat(args));
|
|
@@ -143274,6 +143542,7 @@
|
|
|
143274
143542
|
'vec3 getLocalPosition': '(vec3 position) { return position; }',
|
|
143275
143543
|
'vec3 getWorldPosition': '(vec3 position) { return position; }',
|
|
143276
143544
|
'float getPointSize': '(float size) { return size; }',
|
|
143545
|
+
'vec4 getVertexColor': '(vec4 color) { return color; }',
|
|
143277
143546
|
'void afterVertex': '() {}'
|
|
143278
143547
|
},
|
|
143279
143548
|
fragment: {
|
|
@@ -143604,6 +143873,9 @@
|
|
|
143604
143873
|
// @todo is there an instance where this isn't stroke weight?
|
|
143605
143874
|
// should be they be same var?
|
|
143606
143875
|
pointShader.setUniform('uPointSize', this.pointSize * this._pInst._pixelDensity);
|
|
143876
|
+
// Enable per-vertex color for POINTS when available
|
|
143877
|
+
var useVertexColor = this.immediateMode && this.immediateMode.geometry && this.immediateMode.geometry.vertexStrokeColors && this.immediateMode.geometry.vertexStrokeColors.length > 0;
|
|
143878
|
+
pointShader.setUniform('uUseVertexColor', !!useVertexColor);
|
|
143607
143879
|
} /* Binds a buffer to the drawing context
|
|
143608
143880
|
* when passed more than two arguments it also updates or initializes
|
|
143609
143881
|
* the data associated with the buffer
|
|
@@ -143731,25 +144003,25 @@
|
|
|
143731
144003
|
value: function _initTessy() {
|
|
143732
144004
|
// function called for each vertex of tesselator output
|
|
143733
144005
|
function vertexCallback(data, polyVertArray) {
|
|
143734
|
-
var
|
|
143735
|
-
var
|
|
143736
|
-
var
|
|
144006
|
+
var _iteratorNormalCompletion6 = true;
|
|
144007
|
+
var _didIteratorError6 = false;
|
|
144008
|
+
var _iteratorError6 = undefined;
|
|
143737
144009
|
try {
|
|
143738
|
-
for (var
|
|
143739
|
-
var element =
|
|
144010
|
+
for (var _iterator6 = data[Symbol.iterator](), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
|
|
144011
|
+
var element = _step6.value;
|
|
143740
144012
|
polyVertArray.push(element);
|
|
143741
144013
|
}
|
|
143742
144014
|
} catch (err) {
|
|
143743
|
-
|
|
143744
|
-
|
|
144015
|
+
_didIteratorError6 = true;
|
|
144016
|
+
_iteratorError6 = err;
|
|
143745
144017
|
} finally {
|
|
143746
144018
|
try {
|
|
143747
|
-
if (!
|
|
143748
|
-
|
|
144019
|
+
if (!_iteratorNormalCompletion6 && _iterator6.return != null) {
|
|
144020
|
+
_iterator6.return();
|
|
143749
144021
|
}
|
|
143750
144022
|
} finally {
|
|
143751
|
-
if (
|
|
143752
|
-
throw
|
|
144023
|
+
if (_didIteratorError6) {
|
|
144024
|
+
throw _iteratorError6;
|
|
143753
144025
|
}
|
|
143754
144026
|
}
|
|
143755
144027
|
}
|
|
@@ -143797,12 +144069,12 @@
|
|
|
143797
144069
|
// issues or bugs in libtess's automatic calculation.
|
|
143798
144070
|
var z = contours[0] ? contours[0][2] : undefined;
|
|
143799
144071
|
var allSameZ = true;
|
|
143800
|
-
var
|
|
143801
|
-
var
|
|
143802
|
-
var
|
|
144072
|
+
var _iteratorNormalCompletion7 = true;
|
|
144073
|
+
var _didIteratorError7 = false;
|
|
144074
|
+
var _iteratorError7 = undefined;
|
|
143803
144075
|
try {
|
|
143804
|
-
for (var
|
|
143805
|
-
var contour =
|
|
144076
|
+
for (var _iterator7 = contours[Symbol.iterator](), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
|
|
144077
|
+
var contour = _step7.value;
|
|
143806
144078
|
for (var j = 0; j < contour.length; j += _main.default.RendererGL.prototype.tessyVertexSize) {
|
|
143807
144079
|
if (contour[j + 2] !== z) {
|
|
143808
144080
|
allSameZ = false;
|
|
@@ -143811,16 +144083,16 @@
|
|
|
143811
144083
|
}
|
|
143812
144084
|
}
|
|
143813
144085
|
} catch (err) {
|
|
143814
|
-
|
|
143815
|
-
|
|
144086
|
+
_didIteratorError7 = true;
|
|
144087
|
+
_iteratorError7 = err;
|
|
143816
144088
|
} finally {
|
|
143817
144089
|
try {
|
|
143818
|
-
if (!
|
|
143819
|
-
|
|
144090
|
+
if (!_iteratorNormalCompletion7 && _iterator7.return != null) {
|
|
144091
|
+
_iterator7.return();
|
|
143820
144092
|
}
|
|
143821
144093
|
} finally {
|
|
143822
|
-
if (
|
|
143823
|
-
throw
|
|
144094
|
+
if (_didIteratorError7) {
|
|
144095
|
+
throw _iteratorError7;
|
|
143824
144096
|
}
|
|
143825
144097
|
}
|
|
143826
144098
|
}
|
|
@@ -143833,12 +144105,12 @@
|
|
|
143833
144105
|
var triangleVerts = [
|
|
143834
144106
|
];
|
|
143835
144107
|
this._tessy.gluTessBeginPolygon(triangleVerts);
|
|
143836
|
-
var
|
|
143837
|
-
var
|
|
143838
|
-
var
|
|
144108
|
+
var _iteratorNormalCompletion8 = true;
|
|
144109
|
+
var _didIteratorError8 = false;
|
|
144110
|
+
var _iteratorError8 = undefined;
|
|
143839
144111
|
try {
|
|
143840
|
-
for (var
|
|
143841
|
-
var _contour =
|
|
144112
|
+
for (var _iterator8 = contours[Symbol.iterator](), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
|
|
144113
|
+
var _contour = _step8.value;
|
|
143842
144114
|
this._tessy.gluTessBeginContour();
|
|
143843
144115
|
for (var _j = 0; _j < _contour.length; _j += _main.default.RendererGL.prototype.tessyVertexSize) {
|
|
143844
144116
|
var coords = _contour.slice(_j, _j + _main.default.RendererGL.prototype.tessyVertexSize);
|
|
@@ -143848,16 +144120,16 @@
|
|
|
143848
144120
|
} // finish polygon
|
|
143849
144121
|
|
|
143850
144122
|
} catch (err) {
|
|
143851
|
-
|
|
143852
|
-
|
|
144123
|
+
_didIteratorError8 = true;
|
|
144124
|
+
_iteratorError8 = err;
|
|
143853
144125
|
} finally {
|
|
143854
144126
|
try {
|
|
143855
|
-
if (!
|
|
143856
|
-
|
|
144127
|
+
if (!_iteratorNormalCompletion8 && _iterator8.return != null) {
|
|
144128
|
+
_iterator8.return();
|
|
143857
144129
|
}
|
|
143858
144130
|
} finally {
|
|
143859
|
-
if (
|
|
143860
|
-
throw
|
|
144131
|
+
if (_didIteratorError8) {
|
|
144132
|
+
throw _iteratorError8;
|
|
143861
144133
|
}
|
|
143862
144134
|
}
|
|
143863
144135
|
}
|
|
@@ -145596,6 +145868,52 @@
|
|
|
145596
145868
|
}
|
|
145597
145869
|
}
|
|
145598
145870
|
}
|
|
145871
|
+
} /**
|
|
145872
|
+
* Frees the GPU resources associated with this shader.
|
|
145873
|
+
*
|
|
145874
|
+
* This method deletes the vertex shader, fragment shader, and shader program
|
|
145875
|
+
* from GPU memory. Call this when you no longer need the shader to prevent
|
|
145876
|
+
* memory leaks, especially when creating and destroying multiple p5 instances.
|
|
145877
|
+
*
|
|
145878
|
+
* @method remove
|
|
145879
|
+
* @private
|
|
145880
|
+
*/
|
|
145881
|
+
|
|
145882
|
+
},
|
|
145883
|
+
{
|
|
145884
|
+
key: 'remove',
|
|
145885
|
+
value: function remove() {
|
|
145886
|
+
if (this._glProgram === 0) {
|
|
145887
|
+
return; // Already removed or never initialized
|
|
145888
|
+
}
|
|
145889
|
+
var gl = this._renderer.GL;
|
|
145890
|
+
// Unbind if currently bound
|
|
145891
|
+
if (this._bound) {
|
|
145892
|
+
this.unbindShader();
|
|
145893
|
+
} // Detach shaders from program before deletion
|
|
145894
|
+
|
|
145895
|
+
if (this._vertShader !== - 1) {
|
|
145896
|
+
gl.detachShader(this._glProgram, this._vertShader);
|
|
145897
|
+
gl.deleteShader(this._vertShader);
|
|
145898
|
+
this._vertShader = - 1;
|
|
145899
|
+
}
|
|
145900
|
+
if (this._fragShader !== - 1) {
|
|
145901
|
+
gl.detachShader(this._glProgram, this._fragShader);
|
|
145902
|
+
gl.deleteShader(this._fragShader);
|
|
145903
|
+
this._fragShader = - 1;
|
|
145904
|
+
} // Delete the program
|
|
145905
|
+
|
|
145906
|
+
gl.deleteProgram(this._glProgram);
|
|
145907
|
+
this._glProgram = 0;
|
|
145908
|
+
// Clear cached data
|
|
145909
|
+
this._loadedAttributes = false;
|
|
145910
|
+
this._loadedUniforms = false;
|
|
145911
|
+
this.attributes = {
|
|
145912
|
+
};
|
|
145913
|
+
this.uniforms = {
|
|
145914
|
+
};
|
|
145915
|
+
this.samplers = [
|
|
145916
|
+
];
|
|
145599
145917
|
}
|
|
145600
145918
|
}
|
|
145601
145919
|
]);
|
|
@@ -146228,6 +146546,27 @@
|
|
|
146228
146546
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, this.glWrapS);
|
|
146229
146547
|
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, this.glWrapT);
|
|
146230
146548
|
this.unbindTexture();
|
|
146549
|
+
} /**
|
|
146550
|
+
* Frees the GPU resources associated with this texture.
|
|
146551
|
+
*
|
|
146552
|
+
* This method deletes the WebGL texture from GPU memory. Call this when
|
|
146553
|
+
* you no longer need the texture to prevent memory leaks.
|
|
146554
|
+
*
|
|
146555
|
+
* @method remove
|
|
146556
|
+
* @private
|
|
146557
|
+
*/
|
|
146558
|
+
|
|
146559
|
+
},
|
|
146560
|
+
{
|
|
146561
|
+
key: 'remove',
|
|
146562
|
+
value: function remove() {
|
|
146563
|
+
// FramebufferTextures are managed by their parent Framebuffer
|
|
146564
|
+
if (this.isFramebufferTexture || this.glTex === undefined) {
|
|
146565
|
+
return;
|
|
146566
|
+
}
|
|
146567
|
+
var gl = this._renderer.GL;
|
|
146568
|
+
gl.deleteTexture(this.glTex);
|
|
146569
|
+
this.glTex = undefined;
|
|
146231
146570
|
}
|
|
146232
146571
|
}
|
|
146233
146572
|
]);
|
|
@@ -147161,7 +147500,7 @@
|
|
|
147161
147500
|
return; // don't render lines beyond our maxY position
|
|
147162
147501
|
}
|
|
147163
147502
|
if (!this._isOpenType()) {
|
|
147164
|
-
console.log('WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts are supported');
|
|
147503
|
+
console.log('WEBGL: only Opentype (.otf) and Truetype (.ttf) fonts are supported. Make sure to set the font using textFont() before drawing text.');
|
|
147165
147504
|
return p;
|
|
147166
147505
|
}
|
|
147167
147506
|
p.push(); // fix to #803
|