Skip to content

fix: preserve vertex attributes with smooth normals - #9233

Open
Srinidhi444 wants to merge 4 commits into
processing:mainfrom
Srinidhi444:fix/smooth-normals-preserve-attributes
Open

Srinidhi444 wants to merge 4 commits into
processing:mainfrom
Srinidhi444:fix/smooth-normals-preserve-attributes

Conversation

@Srinidhi444

Copy link
Copy Markdown

Resolves #9205

Changes:

  • Fixed computeNormals(SMOOTH) so it no longer permanently deduplicates geometry vertices based only on position.
  • Smooth normals are calculated using temporary position-based vertex groups and then mapped back to the original vertices.
  • This preserves per-vertex attributes such as UVs while still allowing vertices at the same position to share smooth normals.
  • Added a unit test covering vertices with the same position but different UV coordinates.

Screenshots of the change:
image

PR Checklist

@p5-bot

p5-bot Bot commented Oct 4, 2026

Copy link
Copy Markdown

Continuous Release

CDN link

Published Packages

Commit hash: 4bae8cb

Previous deployments

This is an automated message.

@davepagurek davepagurek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic looks good! To confirm that the normals themselves haven't changed since before, would you be up for adding a visual test with maybe normalMaterial() on a shape with computeNormals(SMOOTH) applied so that we can more easily visually inspect it? If you need some example geometry, there's an example sketch in the "smooth shading" section of https://p5js.org/tutorials/custom-geometry/ that we could borrow.

Comment thread src/webgl/p5.Geometry.js
uniqueVertices.push(vertex);
}

originalToUnique[i] = vertexIndices[key];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@Srinidhi444

Copy link
Copy Markdown
Author

Logic looks good! To confirm that the normals themselves haven't changed since before, would you be up for adding a visual test with maybe normalMaterial() on a shape with computeNormals(SMOOTH) applied so that we can more easily visually inspect it? If you need some example geometry, there's an example sketch in the "smooth shading" section of https://p5js.org/tutorials/custom-geometry/ that we could borrow.

Logic looks good! To confirm that the normals themselves haven't changed since before, would you be up for adding a visual test with maybe normalMaterial() on a shape with computeNormals(SMOOTH) applied so that we can more easily visually inspect it? If you need some example geometry, there's an example sketch in the "smooth shading" section of https://p5js.org/tutorials/custom-geometry/ that we could borrow.

sure

@Srinidhi444

Copy link
Copy Markdown
Author

Logic looks good! To confirm that the normals themselves haven't changed since before, would you be up for adding a visual test with maybe normalMaterial() on a shape with computeNormals(SMOOTH) applied so that we can more easily visually inspect it? If you need some example geometry, there's an example sketch in the "smooth shading" section of https://p5js.org/tutorials/custom-geometry/ that we could borrow.

hey @davepagurek added the requested visual test for computeNormals(SMOOTH) using normalMaterial() on the warped tube geometry from the smooth shading example.
The visual test passes and the expected screenshot has been generated pls check it and let me know if any issues
image

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants