Bake Normal problem when adjoining faces have different UV orientation #96942

Closed
opened 11 months ago by MarkStead-2 · 15 comments

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: c77597cd0e
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.
Bake Normal problem when UV Island orientation changed.blend
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.)
image.png
Go to UV Editing. Select the Bake Active object only, then select this face from the UV Editor window.
image.png
Rotate the face 180 degrees.
Return to the UV Layout window, and observe the image (normal) has now changed for the centre face.
image.png
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.
image.png
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.
image.png
Also, the margin region beyond the top/bottom of the faces shows the opposite colour as expected.
image.png

Another symptom of this problem (in a real world scenario) is edges highlighted around the problem faces.
image.png
This is the normal map view of the same section.
image.png

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.
image.png
Standard UV Unwrap will also orient faces/islands differently.

**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: `c77597cd0e` 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. [Bake Normal problem when UV Island orientation changed.blend](https://archive.blender.org/developer/F12961314/Bake_Normal_problem_when_UV_Island_orientation_changed.blend) 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.) ![image.png](https://archive.blender.org/developer/F12961215/image.png) Go to UV Editing. Select the Bake Active object only, then select this face from the UV Editor window. ![image.png](https://archive.blender.org/developer/F12961221/image.png) Rotate the face 180 degrees. Return to the UV Layout window, and observe the image (normal) has now changed for the centre face. ![image.png](https://archive.blender.org/developer/F12961226/image.png) 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. ![image.png](https://archive.blender.org/developer/F12961241/image.png) 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. ![image.png](https://archive.blender.org/developer/F12961246/image.png) Also, the margin region beyond the top/bottom of the faces shows the opposite colour as expected. ![image.png](https://archive.blender.org/developer/F12961269/image.png) Another symptom of this problem (in a real world scenario) is edges highlighted around the problem faces. ![image.png](https://archive.blender.org/developer/F12961289/image.png) This is the normal map view of the same section. ![image.png](https://archive.blender.org/developer/F12961291/image.png) 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. ![image.png](https://archive.blender.org/developer/F12961300/image.png) Standard UV Unwrap will also orient faces/islands differently.
Poster

Added subscriber: @MarkStead-2

Added subscriber: @MarkStead-2
Collaborator

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Collaborator

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Collaborator

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 449db0a 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)?

> 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 449db0a 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`)?
Collaborator

Added subscriber: @Baardaap

Added subscriber: @Baardaap
Collaborator

@Baardaap: opinions?

@Baardaap: opinions?
Collaborator

Added subscriber: @mano-wii

Added subscriber: @mano-wii
Collaborator

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

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
Collaborator

Hm. That is a situation where I can see 'Adjacent faces' screw up indeed. I think @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.

Hm. That is a situation where I can see 'Adjacent faces' screw up indeed. I think @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.
Poster

@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.

@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):
#96942 Cycles Render of Plane with normal map.jpg
Warped plane without normal (cycles):
#96942 Cycles Render of Warped Plane.jpg

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.

@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. @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): ![#96942 Cycles Render of Plane with normal map.jpg](https://archive.blender.org/developer/F12963116/T96942_Cycles_Render_of_Plane_with_normal_map.jpg) Warped plane without normal (cycles): ![#96942 Cycles Render of Warped Plane.jpg](https://archive.blender.org/developer/F12963130/T96942_Cycles_Render_of_Warped_Plane.jpg) 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.
Poster

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.

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.
Collaborator

Changed status from 'Needs User Info' to: 'Archived'

Changed status from 'Needs User Info' to: 'Archived'
lichtwerk closed this issue 10 months ago
Collaborator

In #96942#1333663, @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), @Baardaap feel free to create a TODO task for this and check with #render_cycles devs on how to proceed.

In #96942#1333997, @MarkStead-2 wrote:
I'm all good.

Will close then.

> In #96942#1333663, @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), @Baardaap feel free to create a TODO task for this and check with #render_cycles devs on how to proceed. > In #96942#1333997, @MarkStead-2 wrote: > I'm all good. Will close then.
Collaborator

This issue was referenced by 811371a6bd

This issue was referenced by 811371a6bddd5c3d7ea33fa8a5ccb7d3d36baf43
Owner

Changed status from 'Archived' to: 'Resolved'

Changed status from 'Archived' to: 'Resolved'
Sign in to join this conversation.
No Label
Interest/Alembic
Interest/Animation & Rigging
Interest/Asset Browser
Interest/Asset Browser Project Overview
Interest/Audio
Interest/Automated Testing
Interest/Blender Asset Bundle
Interest/Collada
Interest/Compositing
Interest/Core
Interest/Cycles
Interest/Dependency Graph
Interest/Development Management
Interest/Eevee & Viewport
Interest/Freestyle
Interest/Geometry Nodes
Interest/Grease Pencil
Interest/ID Management
Interest/Images & Movies
Interest/Import/Export
Interest/Line Art
Interest/Masking
Interest/Modeling
Interest/Modifiers
Interest/Motion Tracking
Interest/Nodes & Physics
Interest/Overrides
Interest/Performance
Interest/Performance
Interest/Physics
Interest/Pipeline, Assets & I/O
Interest/Platforms, Builds, Tests & Devices
Interest/Python API
Interest/Render & Cycles
Interest/Render Pipeline
Interest/Sculpt, Paint & Texture
Interest/Text Editor
Interest/Translations
Interest/Triaging
Interest/Undo
Interest/USD
Interest/User Interface
Interest/UV Editing
Interest/VFX & Video
Interest/Video Sequencer
Interest/Virtual Reality
legacy module/Animation & Rigging
legacy module/Core
legacy module/Development Management
legacy module/Eevee & Viewport
legacy module/Grease Pencil
legacy module/Modeling
legacy module/Nodes & Physics
legacy module/Pipeline, Assets & IO
legacy module/Platforms, Builds, Tests & Devices
legacy module/Python API
legacy module/Rendering & Cycles
legacy module/Sculpt, Paint & Texture
legacy module/Triaging
legacy module/User Interface
legacy module/VFX & Video
legacy project/1.0.0-beta.2
legacy project/Asset Browser (Archived)
legacy project/BF Blender: 2.8
legacy project/BF Blender: After Release
legacy project/BF Blender: Next
legacy project/BF Blender: Regressions
legacy project/BF Blender: Unconfirmed
legacy project/Blender 2.70
legacy project/Code Quest
legacy project/Datablocks and Libraries
legacy project/Eevee
legacy project/Game Animation
legacy project/Game Audio
legacy project/Game Data Conversion
legacy project/Game Engine
legacy project/Game Logic
legacy project/Game Physics
legacy project/Game Python
legacy project/Game Rendering
legacy project/Game UI
legacy project/GPU / Viewport
legacy project/GSoC
legacy project/Infrastructure: Websites
legacy project/LibOverrides - Usability and UX
legacy project/Milestone 1: Basic, Local Asset Browser
legacy project/Nodes
legacy project/OpenGL Error
legacy project/Papercut
legacy project/Pose Library Basics
legacy project/Retrospective
legacy project/Tracker Curfew
legacy project/Wintab High Frequency
Meta/Good First Issue
Meta/Papercut
migration/requires-manual-verification
Module › Animation & Rigging
Module › Core
Module › Development Management
Module › Eevee & Viewport
Module › Grease Pencil
Module › Modeling
Module › Nodes & Physics
Module › Pipeline, Assets & IO
Module › Platforms, Builds, Tests & Devices
Module › Python API
Module › Render & Cycles
Module › Sculpt, Paint & Texture
Module › Triaging
Module › User Interface
Module › VFX & Video
Platform/FreeBSD
Platform/Linux
Platform/macOS
Platform/Windows
Priority › High
Priority › Low
Priority › Normal
Priority › Unbreak Now!
Status › Archived
Status › Confirmed
Status › Duplicate
Status › Needs Information from Developers
Status › Needs Information from User
Status › Needs Triage
Status › Resolved
Type › Bug
Type › Design
Type › Known Issue
Type › Patch
Type › Report
Type › To Do
No Milestone
No project
No Assignees
6 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#96942
Loading…
There is no content yet.