processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.2k stars 3.23k forks source link

Broken example in the reference page for `lightFalloff()` #6789

Closed sudhanshuv1 closed 5 months ago

sudhanshuv1 commented 5 months ago

Most appropriate sub-area of p5.js?

p5.js version

1.9.1

Web browser and version

Google Chrome 121.0.6167.139 (Official Build) (64-bit)

Operating system

Ubuntu 22.04 LTS

Steps to reproduce this

Steps:

  1. Visit the reference page for lightFalloff() - https://p5js.org/reference/#/p5/lightFalloff
  2. Output of the example is a black canvas. No 3D Primitives are rendered on the black background.

Snippet:

function setup() {
  createCanvas(100, 100, WEBGL);
  noStroke();
  describe(
    'Two spheres with different falloff values show different intensity of light'
  );
}
function draw() {
  ortho();
  background(0);

  let locX = mouseX - width / 2;
  let locY = mouseY - height / 2;
  locX /= 2; // half scale

  lightFalloff(1, 0, 0);
  push();
  translate(-25, 0, 0);
  pointLight(250, 250, 250, locX - 25, locY, 50);
  sphere(20);
  pop();

  lightFalloff(0.97, 0.03, 0);
  push();
  translate(25, 0, 0);
  pointLight(250, 250, 250, locX + 25, locY, 50);
  sphere(20);
  pop();
}

Removing otho() from the example code above seems to rectify the issue : https://editor.p5js.org/sudhanshuv1/sketches/n6Ue-T109 The output of this example should render 2 spheres :

download

Both spheres are at same distance from the camera, however the sphere on the right appears to be further behind. This is probably due to an optical illusion caused by low intensity of pointLight() falling on the right sphere. Therefore using ortho() wouldn't make the spheres appear at the same distance from the camera and it causes a glitch in the example. @davepagurek please advise if this is the right way to fix this issue!

sudhanshuv1 commented 5 months ago

@all-contributors please add @sudhanshuv3 for bug

allcontributors[bot] commented 5 months ago

@sudhanshuv3

I've put up a pull request to add @sudhanshuv3! :tada: