Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image light orientation inconsistent with panorama #7167

Closed
1 of 17 tasks
Martin-Lorentzon opened this issue Aug 12, 2024 · 5 comments · Fixed by #7169
Closed
1 of 17 tasks

Image light orientation inconsistent with panorama #7167

Martin-Lorentzon opened this issue Aug 12, 2024 · 5 comments · Fixed by #7169

Comments

@Martin-Lorentzon
Copy link

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

p5.js version

v1.10.0 July 31, 2024

Web browser and version

Microsoft Edge Version 127.0.2651.98 (Official build) (64-bit)

Operating system

Windows 10

Steps to reproduce this

Steps:

  1. Run the project
  2. Take note of the image light- and panorama orientation

Snippet:

let sceneScale;
let sceneTranslation;
let env

let img;
let teaport;

function preload() {
  img = loadImage("https://p5js.org/assets/outdoor_spheremap.jpg");
  teapot = loadModel("https://p5js.org/assets/teapot.obj");
}

function setup() {
  sceneScale = createVector(100, -100, 100);
  sceneTranslation = createVector(0, -1.5, 0);

  createCanvas(640, 360, WEBGL);
  noStroke(); // Disables the wireframe.
  
  const cnv = createGraphics(400, 200)
  cnv.background(0)
  cnv.noStroke()
  cnv.fill(255)
  cnv.rect(0, 0, 200, 200)
  env = cnv.get()
  cnv.remove()
}

function draw() {
  // Set the background colour.
  // background('white');

  // Set the background panorama.
  panorama(env);

  // Transform the scene.
  scale(sceneScale);
  translate(sceneTranslation);

  // Enable orbiting with the mouse.
  orbitControl();

  // Create an ambient light.
  // ambientLight(50);

  // Create a directional light.
  let c = color("white");
  let lightDir = createVector(0, 1, 0);
  directionalLight(c, lightDir);

  // Create an image light.
  imageLight(env);

  // Add a specular material.
  specularMaterial(255);
  shininess(100);
  metalness(300);
  fill(150)

  // Draw the model.
  model(teapot);
}
Copy link

welcome bot commented Aug 12, 2024

Welcome! 👋 Thanks for opening your first issue here! And to ensure the community is able to respond to your issue, please make sure to fill out the inputs in the issue forms. Thank you!

@davepagurek
Copy link
Contributor

Here's a live example: https://editor.p5js.org/davepagurek/sketches/0smDG7pB_

image image image

@perminder-17
Copy link
Contributor

perminder-17 commented Aug 12, 2024

Sorry for the oversight, as @davepagurek mentioned on discord there's a 90-degree rotation difference between imageLight() and panorama. This can be easily fixed by adding an offset to either one of them.

If someone is thinking of adding an offset to panorama, it's using the sphereMapping algorithm used here.

https://github.com/processing/p5.js/blob/main/src/webgl/shaders/sphereMapping.frag#L18

By fixing the y-axis and rotating other two axis, it could be solved I think.

Screenshot from 2024-08-12 23-35-52

Maybe we can add just these lines after line 18 to solve this

    float temp = rotatedNormal.z;
    rotatedNormal.z = rotatedNormal.x;
    rotatedNormal.x = -temp;

Hope this helps, thanks:)

@davepagurek
Copy link
Contributor

@all-contributors please add @Martin-Lorentzon for bug

Copy link
Contributor

@davepagurek

I've put up a pull request to add @Martin-Lorentzon! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants