Skip to content

[p5.js 2.0+ Bug Report]: computeNormals(SMOOTH) destroys uv attribute #9205

Description

@inaridarkfox4231

Most appropriate sub-area of p5.js?

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

p5.js version

2.3.3

Web browser and version

Chrome

Operating system

Windows

Steps to reproduce this

Steps:

  1. create cylinder with buildGeometry().
  2. use computeNormals(SMOOTH).
  3. add texture and display this geometry by directional lighting.
  4. texture broken.

Snippet:

function setup() {
  createCanvas(600,600,WEBGL);

  noStroke();
  const geom=buildGeometry(()=>{
    cylinder(160,400,24,24,0,0);
  });
  geom.computeNormals(SMOOTH);

  const gr = createGraphics(600,600);
  gr.textSize(200);
  gr.background('red');
  gr.fill(255);
  gr.textAlign(CENTER,CENTER);
  gr.text('龍',300,300);
	
  draw=()=>{
    orbitControl();
    background(0);
    lights();
    texture(gr);
    model(geom);
  }
}

computeNormals(FLAT)

Image

computeNormals(SMOOTH)

Image

As shown, using computeNormals() makes it impossible to combine texture-based rendering with lighting.

The point that "using computeNormals() is the problem" is valid. In this example, it is entirely correct.

But what if you want to deform the geometry you have created? For example, you might vary the radius based on the angle from the center to shape the outer edge into a star.
In that case, since calculating the normals directly is difficult, you have to rely on computeNormals(), which leads to this kind of problem.

"the right way is Giving up on rendering using lights" is a valid point. That way, the UVs wouldn't break, and rendering could proceed normally. However, the right to make that decision belongs to the user. Currently, the library holds that right.

Another issue—visible in the console at the bottom left—is the frequent occurrence of errors during computeNormals(); however, as this warrants separate discussion, I will not address it here.

It is possible that this has already been discussed, or that I am simply unaware of a way to resolve it within the current specifications. In that case, I will withdraw this issue. Regardless, I felt it was necessary to raise the point, so I am submitting it here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions