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
Discontinuous normals in ppm files #43
Comments
Thanks. Can you upload the mesh or point set for the subregion you've shown so I have a small dataset to test with? Going off memory, the shading is interpolating normals for barycentric coordinates |
As a side note, the cell map PPM sidecar file tells you the original triangle ID for each pixel. You can use that to color each normal/point according to its triangle association. Might help your visualization. |
OK, I'll have to think about the best way to get you the pointset. I have a python script that reads in a full ppm file, computes the xyzs and normals everywhere, and then creates a mesh (an obj file for visualization in meshlab) over a small subset for visualization. If you want, I can send that script along, once I am sure it is readable. But it sounds like you want a subset of the obj mesh that was fed into PPMGenerator; if that is what you want, I would have to figure out how to create it. I never ran the VC code to generate a ppm file, I just used ppm files I found on the server. So I don't really have a starting mesh/pointset of the kind that I think you are requesting. |
Ahh yes, good eye. It probably should be 1 - uvw[2] - uvw[1]. You can just point me to the PPM you're using and the ROI you're cropping to for your mesh. I'm not actually sure that this isn't also connected to aliasing of the normals along the boundary of two (original) triangles. But we'll need to look at more than just the one row of normals that you're showing. |
The ppm file is 20230827161846.ppm (I think you can figure out the rest of the path from that). The corners of the ROI are (I think, the code may have been modified a little): (3500, 1896), (4100, 1904). So its width is much greater than its height. |
I can't seem to replicate this. We have a developer utility You can kind of see what looks to be a discontinuity a little up and to the right from the center, but if you zoom in on that region, you can see that the normals actually appear pretty continuous, but the points themselves are slightly "discontinuous" with respect to the row: That row discontinuity doesn't surprise me and just looks like rasterization to me. All of that said, I did make the barycentric coordinate change, and it also doesn't really change much with the normals: And a diff of the two showing the only major differences are in vertex positions (less than half a pixel): I still need to investigate how this affects the sharkbite, but I'm anticipating it won't change much. |
Oh, and here are the extracted strips as PLY files. The |
Thanks for looking at this! |
Okay, so extending the normals does show me the effect: But it also appears to occur across triangle boundaries, which makes sense to me. Here's a top-down view. The biggest orange lines are the vertex normals of the original mesh (what we're interpolating from), and the green lines are the face normal that MeshLab creates from the vertex normals: And here's one with orthographic projection: That all seems fairly normal to me given the interpolation method, though: everything within the triangle is smooth, but it's not necessarily so across triangle boundaries. |
Alright, I've also confirmed that this doesn't affect the sharkbite example you referenced. Before (layer 64): After (layer 64): Before (normal map): After (normal map): I think this particular sharkbite is actually explained by the 3D geometry. Here's the above region in 3D: Since it's a trough, you have convexity and the normals start crossing each other the further you get from the surface points. So by 32 pixels off of the surface (layer 64, ~0.25mm), the volumetric space we're sampling across adjacent triangles is just nowhere close to the same. This doesn't show that exactly, but it illustrates the point, I think: Anyway, I think I've decided that we found a small bug in the interpolation, so we'll get that fixed (#46). The remaining discontinuity is a limitation of the shading method and not a bug per se. I think you could make a case that we should have a method that produces smoother normals at the boundaries of triangles, and I'd happily review PRs implementing something like that. |
OK, sounds good, thanks for the thorough check. I'm closing the issue now. |
Oops, sorry to reopen this again just after closing it. |
Bah, you're right! That invalidates all of the testing above. 🙃 Anyway, easy enough to fix and redo. I really should get rid of the double implementation. I'll do this sometime next week. |
Well, we got there in the end. Using Using And you'll be happy to know that it does, in fact, fix the sharkbite! Original: And fixed: Thanks for looking over my shoulder on this! The fix is in #53. |
You're welcome! Thanks for the kind words! |
What happened?
I was testing some code to read ppm files. This code would read the ppm file, use the xyz information in the file to create a mesh in xyz space, and use the normal information in the file to create lines in xyz space extending from the mesh. After hiding most of the mesh and most of the normals (in order to create a picture I could make sense of), I got this:
I noticed there were a number of discontinuities, which seemed to be located at the boundaries of the triangles from the original obj mesh that was used to create the ppm file.
I dug into the VC code, and in PPMGenerator.cpp came across the PhongNormal function, which contains the following lines:
This formula seems odd to me; I would have expected:
I'm not currently in a position to compile and run the VC code, so I cannot test whether my version would solve the discontinuous-normal problem. But in any case, I believe the discontinuous normals could be the cause of the "sharkbite" problem that was previously reported (bug #33).
Steps to reproduce
No response
Version
No response
How did you install the software?
None
On which operating systems have you experienced this issue?
Relevant log output
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: