question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Seams with normal map and mirrored uvs

See original GitHub issue
Description of the problem

I guess it may not be just a threejs issue but I ran into a problem when using a normal map with a mesh having mirrored uvs.

With the current code, my understanding is that the RGB value (128, 128, 255) which is supposed to represent a non perturbed normal by convention is read as (0.50196, 0.50196, 1.0) - in linear color space. When converted to [-1, 1] using the function map * 2.0 - 1.0 the vector encoded in the texture becomes (0.00392, 0.00392, 1.0) when it shall be (0.0, 0.0, 1.0). This is the reason why when using a mesh with mirrored uvs and a normal texture, the two normals at a seam have different directions creating the artifact.

It can be easily proven by modifying the perturbNormal2Arb function. Replace vec3 mapN = map * 2.0 - 1.0; by vec3 mapN = map * 2.0 - 1.00392; and the seams disappear. I attached two screenshots made using a fully metallic material and no roughness to make it very obvious:

seams

noseams

Not too sure how this problem is generally solved as this is not my area of expertise.

Three.js version
  • Dev
  • r113
Browser
  • All of them
OS
  • All of them

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:37 (14 by maintainers)

github_iconTop GitHub Comments

2reactions
donmccurdycommented, Feb 9, 2020

Can you share the model?

Some issues like this can be avoided by computing vertex tangents and setting material.vertexTangents = true. You can add tangents with an option in the Blender glTF exporter, or with BufferGeometryUtils.

1reaction
makccommented, Apr 1, 2020

Mugen, there were a couple of hacks discussed in the thread, but no PR so far. The simplest hack offered by @njarraud shifts normal map zero level to 128, thus causing to 0 and 255 to map incorrectly as a price. I posted fiddles for both this hack and 127-based hack I think. Then the more convoluted hack that maps all of (0,127,128,255) values “correctly” but not all the other values inbetween (and the expression is ugly).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Normal mapping seam on mirrored UVs - Polycount
After baking a normal for this mesh which has mirrored UVs down the middle I get a very visible seam in the location...
Read more >
Why does my normal map with mirrored UV's show seams?
You can't mirror normal maps. The reason they work is because the red and green channels are actually shadow information. If you mirror...
Read more >
[Help] Normal map seams and mirrored Uvs : r/Maya - Reddit
The problem is that one of the UV sets will be inverted, so when you make the normal map, you may get some...
Read more >
Creating and using mirrored normal maps on a character or ...
For best results, ensure that each side of your model has consistent UV winding. Otherwise, artifacts may appear. · To avoid seams when...
Read more >
Normal Map Seam Problem - Blender Stack Exchange
Other than that, check your UV Editor, the UV maps of the right and left sides of your objects are overlapping, it makes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found