Introduce KEEP_CONNECTIONS as a replacement for FLAT in computeNormals()
Increasing access
Introducing KEEP_CONNECTIONS would make the behavior of computeNormals() clearer and more intuitive, especially for beginners working with custom 3D geometry.
Currently, FLAT can be misleading because it does not always produce true flat shading when faces share vertices. The new name would better communicate what the mode actually does, helping users understand and choose the appropriate normal calculation behavior.
Keeping FLAT as a deprecated alias would also ensure that existing sketches continue to work without requiring immediate changes.
Most appropriate sub-area of p5.js?
- [ ] Accessibility
- [ ] Color
- [ ] Core/Environment/Rendering
- [ ] Data
- [ ] DOM
- [ ] Events
- [ ] Image
- [ ] IO
- [ ] Math
- [ ] Typography
- [ ] Utilities
- [x] WebGL
- [ ] Build process
- [ ] Unit testing
- [ ] Internationalization
- [ ] Friendly errors
- [ ] Other (specify if possible)
Feature enhancement details
Problem
Currently, computeNormals(FLAT) calculates vertex normals by accumulating face normals across connected vertices. Because vertices shared by multiple faces receive averaged normals, this does not always result in true flat shading.
The name FLAT can therefore be misleading, as discussed in #9205.
Proposed solution
Introduce a new shading constant, KEEP_CONNECTIONS, that represents the existing behavior of FLAT, while keeping FLAT as a deprecated alias for backward compatibility.
The proposed changes are:
- Introduce
KEEP_CONNECTIONSas a supported shading mode forcomputeNormals(). - Preserve the current normal calculation behavior without modifying vertex connections or geometry attributes.
- Keep
FLATworking as before throughout p5.js 2.x to avoid breaking existing sketches. - Mark
FLATas deprecated in the documentation and recommend usingKEEP_CONNECTIONSinstead. - Add or update tests to verify that both modes produce equivalent results.
As discussed with @davepagurek, FLAT could potentially be removed in the next major version (p5.js 3.0), rather than in a minor or patch release.
Related issues
- #9205 — Original discussion about
computeNormals()shading behavior. - #9233 — Previous PR addressing UV attribute preservation in
SMOOTH.
This issue focuses only on introducing KEEP_CONNECTIONS and deprecating FLAT. The proposed SEGMENTED mode for true flat shading will be tracked in a separate follow-up issue.
This issue has already been assigned to me as part of the follow-up work discussed in #9205. I'd appreciate it if others could avoid working on it simultaneously to prevent duplicate efforts. Thanks for understanding!