-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
Normals flipped on some parts of the mesh that have double sided materials #17804
Comments
@pushmatrix Can you confirm if this model does or does not supply its own tangents? I'm curious if this may be related to #11438. |
I don't believe it specifies its own tangents |
Using a different test case, git bisect points to #17586 as the PR that initiated the problem if the mesh is double-sided and has negative scale X. That was in r.109, not r.108, however. This was not tested on the model from this PR because that model is not available. |
Here's the test glb |
From 3 years ago: #10331 (comment)
Is this still an issue that we need to accommodate? // This model appears to render correctly on my machine if we remove the Adreno workaround in #ifdef DOUBLE_SIDED
// Workaround for Adreno GPUs gl_FrontFacing bug. See #15850 and #10331
bool frontFacing = dot( cross( S, T ), N ) > 0.0;
mapN.xy *= ( float( frontFacing ) * 2.0 - 1.0 );
#else
mapN.xy *= ( float( gl_FrontFacing ) * 2.0 - 1.0 );
#endif |
Hmm, I remember reading that comment too; I think I came across it while looking at this bug, which was apparently fixed in r108 (at least upgrading fixed it for us): google/model-viewer#740 Maybe it's related? FWIW, I have gotten some feedback about old Adreno GPUs, so apparently they're still fairly common. |
Right. But not if you remove the Adreno bug workaround. |
How about removing the workaround for now and then search for a different solution? The current implementation leads to wrong visuals no matter what platform you are using. |
@Mugen87 In this particular case, I believe the geometries are mirrors of each other, but they share the same normal map. I agree with you. I have invested many hours trying to find an Adreno-compatible workaround that is correct in every use case. |
@pushmatrix can you compare with Unity or Blender? |
Blender 2.8UnitySketchfab |
Unity is hard to see because the light is in the same direction the camera is, but looks like Unity is wrong too? 🤔 |
Yeah it does depend a bit on the lighting it ends up being an illusion and looking like it's popped up in some places. But when you rotate around, it disappears. |
@mrdoob Front-faces have counter-clockwise winding order in three.js. Typically, the UVs of the 3 vertices of each face also have counter-clockwise winding order on the UV map. In this example, my conjecture is the model on the left has counter-clockwise UVs and the model on the right has clockwise UVs. The model the right is rendering incorrectly in three.js when AFAIK, removing the Adreno-workaround fixes the problem for non-Adreno GPUs. |
@pushmatrix Your Unity example appears to have directional lights from two directions. That makes it difficult to discern what is going on. A single light may be preferable. |
@WestLangley I am using the same environment map the model-viewer is using, but likely it doesn't have the same rotation. I will try with a single light. |
@WestLangley Single directional light rotating around. I feel like I'm looking at an optical illusion |
I feel like there is something wrong in the Unity one... |
Thanks, that makes sense. I think it still deserves more investigation though. If Sketchfab looks correct in all devices we may have to look at their shaders. |
I had a look at the respective shader code today and it seems they are not using "Per-Pixel Tangent Space Normal Mapping". According to this post, Sketchfab expects tangent definitions in assets or these data are generate based on uv coordinates. That corresponds to what I've seen in the GLSL code. If I add tangents to the model via |
For consistency, here is Sketchfab with 1 directional light moving back and forth: Yeah one thing to keep in mind is Sketchfab does do processing on their end when you upload a model, so very likely they could be generating things / changing things. What you're viewing is not a glTF but a glTF file converted to their own format. |
@pushmatrix Can you please demonstrate that #17958 works for your model? |
three.js computes tangents in the fragment shader. I believe it works correctly if a hack to accommodate certain buggy Adreno GPUs is removed. See #17958. // Sketchfab computes tangents on the CPU when tangents are required and are not provided by the model. (@donmccurdy This is what the glTF spec requires.) three.js can do that too, but it will mean adding correct tangents to all built-in geometries. three.js will also have to implement the MIKKTSpace algorithm to replace |
Another solution is to call |
|
@WestLangley wrote:
Changing my mind... Tangents are not necessarily required. Instead, I would restore the method //
That sounds right to me.
I think that is easily fixed. And it will have to be fixed to support #17804 (comment). |
I don't know if MikkTSpace should necessarily replace the fragment shader computation. The shader has almost no performance cost, and works fine for a majority of models. Precomputing tangents has a per-vertex upfront cost every time, and no benefit except in these specific cases. 😕 Despite what the glTF spec says, I'm having a hard time justifying doing that by default. It would be nice if |
But, say... in the Should |
Haha, I've just realized where these wheels are from 😁 |
@mrdoob 🕵 |
Okay then, lets revert the workaround for now. |
Description of the problem
Upgrading from 107 to 108, I've noticed that parts of my model now look like they have flipped normals. This only occurs with double sided materials.
See here: https://vaulted-jonquil.glitch.me/
This is what it should look like, with the pattern being indented on both wheels. That's how it was in 107
In 108 though one of the wheels has the pattern looking like it's popping out:
Three.js version
Browser
OS
The text was updated successfully, but these errors were encountered: