Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions src/webgl/light.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ var p5 = require('../core/core');
* background(0);
* ambientLight(150);
* ambientMaterial(250);
* sphere(50);
* noStroke();
* sphere(25);
* }
* </code>
* </div>
*
* @alt
* nothing displayed
* evenly distributed light across a sphere
*
*/

Expand Down Expand Up @@ -98,6 +99,28 @@ p5.prototype.ambientLight = function(v1, v2, v3, a) {
* @param {Number} v3 blue or brightness value
* @param {p5.Vector} position the direction of the light
* @chainable
* @example
* <div>
* <code>
* function setup() {
* createCanvas(100, 100, WEBGL);
* }
* function draw() {
* background(0);
* //move your mouse to change light direction
* var dirX = (mouseX / width - 0.5) * 2;
* var dirY = (mouseY / height - 0.5) * 2;
* directionalLight(250, 250, 250, -dirX, -dirY, 0.25);
* ambientMaterial(250);
* noStroke();
* sphere(25);
* }
* </code>
* </div>
*
* @alt
* light source on canvas changeable with mouse position
*
*/

/**
Expand Down Expand Up @@ -126,28 +149,6 @@ p5.prototype.ambientLight = function(v1, v2, v3, a) {
* @param {Number} y
* @param {Number} z
* @chainable
*
* @example
* <div>
* <code>
* function setup() {
* createCanvas(100, 100, WEBGL);
* }
* function draw() {
* background(0);
* //move your mouse to change light direction
* var dirX = (mouseX / width - 0.5) * 2;
* var dirY = (mouseY / height - 0.5) * 2;
* directionalLight(250, 250, 250, -dirX, -dirY, 0.25);
* ambientMaterial(250);
* sphere(50);
* }
* </code>
* </div>
*
* @alt
* light source on canvas changeable with mouse position
*
*/
p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
var shader = this._renderer._useLightShader();
Expand Down Expand Up @@ -213,18 +214,19 @@ p5.prototype.directionalLight = function(v1, v2, v3, x, y, z) {
* function draw() {
* background(0);
* //move your mouse to change light position
* var locY = (mouseY / height - 0.5) * -2;
* var locX = (mouseX / width - 0.5) * 2;
* //to set the light position,
* //think of the world's coordinate as:
* // -1,1 -------- 1,1
* // | |
* // | |
* // | |
* // -1,-1---------1,-1
* pointLight(250, 250, 250, locX, locY, 0);
* var locX = mouseX - width / 2;
* var locY = mouseY - height / 2;
* // to set the light position,
* // think of the world's coordinate as:
* // -width/2,-height/2 -------- width/2,-height/2
* // | |
* // | 0,0 |
* // | |
* // -width/2,height/2--------width/2,height/2
* pointLight(250, 250, 250, locX, locY, 50);
* ambientMaterial(250);
* sphere(50);
* noStroke();
* sphere(25);
* }
* </code>
* </div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function draw(){
background(0);

ambientLight(50);
pointLight(250, 250, 250, mouseX - width / 2, mouseY - height / 2, 0);
pointLight(250, 250, 250, mouseX - width / 2, mouseY - height / 2, 100);

ambientMaterial(250);
sphere(50, 64);
Expand Down