diff --git a/src/webgl/light.js b/src/webgl/light.js
index f50b0c0787..ee3061d363 100644
--- a/src/webgl/light.js
+++ b/src/webgl/light.js
@@ -542,7 +542,7 @@ p5.prototype.lightFalloff = function(
*
*
* @alt
- * Something
+ * Spot light on a sphere which changes position with mouse
*/
/**
* @method spotLight
@@ -832,4 +832,68 @@ p5.prototype.spotLight = function(
return this;
};
+/**
+ * This function will remove all the lights from the sketch for the
+ * subsequent materials rendered. It affects all the subsequent methods.
+ * Calls to lighting methods made after noLights() will re-enable lights
+ * in the sketch.
+ * @method noLights
+ * @chainable
+ * @example
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ * function draw() {
+ * background(0);
+ * noStroke();
+ *
+ * ambientLight(150, 0, 0);
+ * translate(-25, 0, 0);
+ * ambientMaterial(250);
+ * sphere(20);
+ *
+ * noLights();
+ * ambientLight(0, 150, 0);
+ * translate(50, 0, 0);
+ * ambientMaterial(250);
+ * sphere(20);
+ * }
+ *
+ *
+ *
+ * @alt
+ * Two spheres showing different colors
+ */
+p5.prototype.noLights = function() {
+ this._assert3d('noLights');
+ p5._validateParameters('noLights', arguments);
+
+ this._renderer.ambientLightColors.length = 0;
+ this._renderer.specularColors = [1, 1, 1];
+
+ this._renderer.directionalLightDirections.length = 0;
+ this._renderer.directionalLightDiffuseColors.length = 0;
+ this._renderer.directionalLightSpecularColors.length = 0;
+
+ this._renderer.pointLightPositions.length = 0;
+ this._renderer.pointLightDiffuseColors.length = 0;
+ this._renderer.pointLightSpecularColors.length = 0;
+
+ this._renderer.spotLightPositions.length = 0;
+ this._renderer.spotLightDirections.length = 0;
+ this._renderer.spotLightDiffuseColors.length = 0;
+ this._renderer.spotLightSpecularColors.length = 0;
+ this._renderer.spotLightAngle.length = 0;
+ this._renderer.spotLightConc.length = 0;
+
+ this._renderer.constantAttenuation = 1;
+ this._renderer.linearAttenuation = 0;
+ this._renderer.quadraticAttenuation = 0;
+ this._renderer._useShininess = 1;
+
+ return this;
+};
+
export default p5;
diff --git a/test/manual-test-examples/webgl/lights/noLights/index.html b/test/manual-test-examples/webgl/lights/noLights/index.html
new file mode 100644
index 0000000000..ef2cf9f556
--- /dev/null
+++ b/test/manual-test-examples/webgl/lights/noLights/index.html
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test/manual-test-examples/webgl/lights/noLights/sketch.js b/test/manual-test-examples/webgl/lights/noLights/sketch.js
new file mode 100644
index 0000000000..ab8523f924
--- /dev/null
+++ b/test/manual-test-examples/webgl/lights/noLights/sketch.js
@@ -0,0 +1,18 @@
+function setup() {
+ createCanvas(windowWidth, windowHeight, WEBGL);
+}
+
+function draw() {
+ background(0);
+
+ ambientLight(150, 0, 0);
+ translate(-200, 0, 0);
+ ambientMaterial(250);
+ sphere(50, 64);
+
+ noLights();
+ ambientLight(0, 150, 0);
+ translate(400, 0, 0);
+ ambientMaterial(250);
+ sphere(50, 64);
+}
diff --git a/test/unit/webgl/light.js b/test/unit/webgl/light.js
index e09e6416c8..bf14889d2e 100644
--- a/test/unit/webgl/light.js
+++ b/test/unit/webgl/light.js
@@ -43,6 +43,29 @@ suite('light', function() {
0
]);
});
+ test('noLights works', function() {
+ myp5.ambientLight(200, 0, 0);
+ myp5.pointLight(255, 0, 0, 0, 0, 0);
+ myp5.directionalLight(255, 0, 0, 0, 0, 0);
+ myp5.specularColor(255, 0, 0);
+ myp5.spotLight(255, 0, 255, 1, 2, 3, 0, 1, 0, Math.PI / 4, 7);
+ myp5.shininess(50);
+
+ myp5.noLights();
+ assert.deepEqual([], myp5._renderer.ambientLightColors);
+ assert.deepEqual([], myp5._renderer.pointLightDiffuseColors);
+ assert.deepEqual([], myp5._renderer.pointLightSpecularColors);
+ assert.deepEqual([], myp5._renderer.pointLightPositions);
+ assert.deepEqual([], myp5._renderer.directionalLightDiffuseColors);
+ assert.deepEqual([], myp5._renderer.directionalLightSpecularColors);
+ assert.deepEqual([], myp5._renderer.directionalLightDirections);
+ assert.deepEqual([1, 1, 1], myp5._renderer.specularColors);
+ assert.deepEqual([], myp5._renderer.spotLightDiffuseColors);
+ assert.deepEqual([], myp5._renderer.spotLightSpecularColors);
+ assert.deepEqual([], myp5._renderer.spotLightPositions);
+ assert.deepEqual([], myp5._renderer.spotLightDirections);
+ assert.deepEqual(1, myp5._renderer._useShininess);
+ });
});
suite('spotlight inputs', function() {
diff --git a/test/unit/webgl/p5.RendererGL.js b/test/unit/webgl/p5.RendererGL.js
index e8e0019e1e..82599db9a4 100644
--- a/test/unit/webgl/p5.RendererGL.js
+++ b/test/unit/webgl/p5.RendererGL.js
@@ -191,6 +191,21 @@ suite('p5.RendererGL', function() {
done();
});
+ test('push/pop and noLights() works', function(done) {
+ myp5.createCanvas(100, 100, myp5.WEBGL);
+ myp5.ambientLight(0, 0, 200);
+ var ambColors = myp5._renderer.ambientLightColors.slice();
+ myp5.push();
+ myp5.ambientLight(0, 200, 0);
+ var ambPopColors = myp5._renderer.ambientLightColors.slice();
+ myp5.noLights();
+ assert.notEqual(ambColors, myp5._renderer.ambientLightColors);
+ assert.notEqual(ambPopColors, myp5._renderer.ambientLightColors);
+ myp5.pop();
+ assert.deepEqual(ambColors, myp5._renderer.ambientLightColors);
+ done();
+ });
+
test('push/pop and texture() works', function(done) {
myp5.createCanvas(100, 100, myp5.WEBGL);
var tex1 = myp5.createGraphics(1, 1);