Maniphest T96942

Bake Normal problem when adjoining faces have different UV orientation
Closed, Resolved

Assigned To
None
Authored By
Mark Stead (Scumbag)
Apr 1 2022, 10:46 AM
Tags
  • BF Blender
Subscribers
Germano Cavalcante (mano-wii)
Mark Stead (Scumbag)
Martijn Versteegh (Baardaap)
Philipp Oeser (lichtwerk)

Description

System Information
Operating system: Windows-10-10.0.19043-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 970/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 497.09

Blender Version
Broken: version: 3.1.0, branch: master, commit date: 2022-03-08 18:16, hash: rBc77597cd0e15
Worked: None. Tested with 2.83 LTS and 2.93 LTS and I get the same behaviour.

Short description of error
Baking normals from a high-poly mesh and some faces have completely weird normals generated.
I created the low-poly UV Map using Smart UV Project.
Some faces on the mesh were at a high enough angle that Smart UV Project put them into separate UV islands.
When the islands have a different face orientation (e.g. rotated) this causes the normal calculation problem.

Exact steps for others to reproduce the error
I have reproduced the problem in a simple test file attached here.


Open the file and click on Bake. The normals from the warped plane underneath the flat object will be baked. (The normal map is displayed as the surface colour.)

Go to UV Editing. Select the Bake Active object only, then select this face from the UV Editor window.

Rotate the face 180 degrees.
Return to the UV Layout window, and observe the image (normal) has now changed for the centre face.

Select "Bake Selected", then Ctrl click on "Bake Active", and click on Bake again.
The generated normal is still back-to-front (rotated 180 degrees) on the active object.
Switching to the Shading editor, you can view the UV map with more detail.

The section that was rotated still shows a cyan to magenta transition (from top-to-bottom) suggesting that the code generating the UV is not aware of the UV island orientation.
However the code to extract data from the UV map (either for image display, or for use as a normal) must be UV island orientation aware.

Also, the margin region beyond the top/bottom of the faces shows the opposite colour as expected.

Another symptom of this problem (in a real world scenario) is edges highlighted around the problem faces.


This is the normal map view of the same section.

There is no difference observed whether using Bake from MultiRes or Bake from Selected to Active.
I tried Lightmap Pack but it appears to have the same problem where random faces have non blending UVs.


Standard UV Unwrap will also orient faces/islands differently.

Revisions and Commits

rB Blender
D14572

Related Objects

Mentioned In
T96977: TODO: set the default margin generation back to extend for the baking of normals in tangent space.
Mentioned Here
rB449db0ab1e34: Baking: new method to generate margin, based on adjacent faces

Event Timeline

Mark Stead (Scumbag) created this task.Apr 1 2022, 10:46 AM
Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Needs Information from User.EditedApr 1 2022, 3:50 PM
Philipp Oeser (lichtwerk) added a subscriber: Philipp Oeser (lichtwerk).

The section that was rotated still shows a cyan to magenta transition (from top-to-bottom) suggesting that the code generating the UV is not aware of the UV island orientation.

Not sure about this. Since this is tangent space, it might actually be OK if this looks inverted (if looked at in color) for the island, the result [when used as a normal map in the Normal Map node] might still be correct (your "real world example" also suggest this, the faces themselves seem to shade correctly, it is at the borders where we see the problems.

Also, the margin region beyond the top/bottom of the faces shows the opposite colour as expected.

This is where the real "problem" is.
In 2.93 (3.0, too) for example, the margin was always extended, you dont get the problem there the margin regions just extend, no borders/seams when used as a normalmap.
There was a new margin method introduced in 3.1, see rB449db0ab1e34: Baking: new method to generate margin, based on adjacent faces which uses adjacent faces, you can run into the situation where this does not work well, like in this report with rotated UV islands.

So, do you still get the seams/edges around problem faces when you bake with margin type Extend (instead of Adjacent Faces)?

Philipp Oeser (lichtwerk) added a subscriber: Martijn Versteegh (Baardaap).Apr 1 2022, 3:52 PM

@Martijn Versteegh (Baardaap): opinions?

Germano Cavalcante (mano-wii) added a subscriber: Germano Cavalcante (mano-wii).Apr 1 2022, 4:03 PM

I don't think it's a bug.

Note that normals need an orientation space to indicate which is up (Y) and which is right (X).
In this case, the orientation is defined by the "Tangent" of the face. See https://docs.blender.org/manual/en/3.2/render/cycles/baking.html#bpy-types-bakesettings-normal-space

Tangent Space is calculated based on the UV.
This is the same space calculated and used when you use the Normal Map node with the Tangent Space.

So even though the normal is weird, it works correctly with the Tangent Space settings.


The glitch noted is because the margin is set to Adjacent Faces while Extend seems to be more appropriate in this case.
https://docs.blender.org/manual/en/3.2/render/cycles/baking.html#margin

Martijn Versteegh (Baardaap) added a comment.Apr 1 2022, 4:25 PM

Hm. That is a situation where I can see 'Adjacent faces' screw up indeed. I think @Germano Cavalcante (mano-wii) hits the nail on the head.

Maybe we should set the default back to 'Extend' for normal baking. Fixing this in the "Adjacent Faces' margin generation would be quite hairy I think.

Mark Stead (Scumbag) added a comment.Apr 2 2022, 5:30 AM

@Philipp Oeser (lichtwerk)

So, do you still get the seams/edges around problem faces when you bake with margin type Extend (instead of Adjacent Faces)?

No, using margin type Extend does not cause those edge halos.

@Germano Cavalcante (mano-wii)

So even though the normal is weird, it works correctly with the Tangent Space settings.

I've done testing the results are comparable between an actual warped object and a flat plane with the normal map applied. The normal map is interpreted correctly in both Eevee and Cycles.
Flat plane with normal map applied (cycles):


Warped plane without normal (cycles):

Anyway this got me thinking about how the rotation/transformation in UV space was handled, and I will do some follow-up testing of irregular polygons.
Just heading out to grab some lunch - will post my findings soon.

Mark Stead (Scumbag) added a comment.Apr 2 2022, 10:44 AM

I'm all good. As discussed the only problem is the edge halos that sometimes show when bake Margin Type is set to Adjacent Faces.
I can work around this by using Extend mode.

Thanks for your great work guys.

Philipp Oeser (lichtwerk) closed this task as Archived.Apr 2 2022, 11:42 AM
In T96942#1333663, @Martijn Versteegh (Baardaap) wrote:

Maybe we should set the default back to 'Extend' for normal baking. Fixing this in the "Adjacent Faces' margin generation would be quite hairy I think.

It would only be tangent space, object space would not have this problem.
We could keep this in mind (and I would agree that this sounds like the better default for this kind of baking), @Martijn Versteegh (Baardaap) feel free to create a TODO task for this and check with Render & Cycles devs on how to proceed.

In T96942#1333997, @Mark Stead (Scumbag) wrote:

I'm all good.

Will close then.

Brecht Van Lommel (brecht) changed the task status from Archived to Resolved by committing rB811371a6bddd: Fix T96942: disable Adjacent Faces margin for UVs and tangent space bake.Apr 10 2022, 4:32 PM
Brecht Van Lommel (brecht) added a commit: rB811371a6bddd: Fix T96942: disable Adjacent Faces margin for UVs and tangent space bake.