Repository navigation
feat(webgl): add SEGMENTED mode for true flat shading - #9288
Conversation
|
Hey @davepagurek, I've updated the I've also handled the associated per-vertex attributes, including UVs, colors, tangents, and custom vertex attributes, and added the relevant unit tests. All tests are passing. |
|
Hey @Srinidhi444, found one thing while testing this with a small
A pair-style UV / tiny OBJ regression test should cover it. Also noticed @davepagurek does flattening at this point sound like the right direction? |
|
Hey @bhabishnu, yeah, I checked it and I think you're right about the I'll address both issues and push the fixes soon. Really appreciate you catching this and taking the time to test it. Thanks! |
|
Thanks, I’m glad it was useful |
|
Hey @davepagurek, I've addressed the UV handling issue in
I also reproduced the issue using an OBJ model and verified the fix. The unit tests are passing. Please let me know if anything else needs to be changed! |
|
Thanks everyone, this is looking good! @Srinidhi444 it would be great to add a visual test or two in here (maybe with and without strokes?) to confirm visually how it looks.
@bhabishnu good catch! it would be good to understand in what circumstances it's in this format. I see that we collapse them here before passing it into a buffer: p5.js/src/core/p5.Renderer3D.js Lines 302 to 304 in 24a68d5 ...but it's definitely more to manage internally if it can be in either format. It looks like some 3D primitives in our codebase use nested uvs and others use flat uvs. I wonder how feasible it'd be, in a follow-up issue, to have a clear separation of user inputs from internal representation so that we can e.g. always use flat uvs internally without having to handle multiple types everywhere. I'm not sure if there's a clear point where we could convert them though, since you can make a |
|
Thanks @davepagurek! I'll add visual tests for Regarding UVs, I agree that having a consistent internal representation would simplify things across the codebase. Once I've finished this PR, I might raise a follow-up issue and explore the problem in more depth to see how we could approach it.
|
|
hey @davepagurek i have added the visual tests please check |
@davepagurek I dug into this a bit more. Nested UVs seem to come from only a few p5-owned paths ( The renderer mostly hides this because it flattens UVs before upload, but not every consumer does. I also couldn't find a reliable point where p5 can say a Changing the producers themselves to always store flat UVs looks trickier since there is existing user code that relies on nested UV access like @Srinidhi444 happy to add the repros/details to the follow-up issue if you end up opening one. |
Hey, really appreciate the help, man! It would be great if you could add the repros and details. I'll open a follow-up issue once this PR is closed and tag you there. Thanks again! |
|
Sounds good, happy to add the repros/details there once it's open! |
Description
Fixes #9285
This PR introduces a new
SEGMENTEDmode forcomputeNormals()to support true flat shading.Unlike
KEEP_CONNECTIONS, which averages normals across connected vertices,SEGMENTEDassigns independent face normals to each triangle by selectively duplicating shared vertices.Related to #9205.
Changes
SEGMENTEDconstant.Tests
Added and updated unit tests covering:
computeNormals(SEGMENTED).Validation:
npx vitest run test/unit/webgl/p5.Geometry.js— all tests passed.