FBX Normals export issue (IndexToDirect interpreted wrong in Unity) #123088

Open
opened 2024-06-11 18:25:55 +02:00 by Lucas-Brown-SSTK · 8 comments

System Information
Operating system: Windows 10

Blender Version
Broken: 4.1.1
Worked: 4.0.2

Short description of error
Normals are exported incorrectly to FBX files, artifacts show up when imported into Unity. It seems like normal smoothing information may be lost. I've confirmed this issue is in fact Blender, not Unity. Also confirmed it is still an issue on 4.3.0 Alpha.

Exact steps for others to reproduce the error

  1. See attached scene
  2. Open in Blender 4.1.1
  3. Export as FBX
  4. Import into Unity, broken normals (see attached images).

Tested attached FBX files in the following Unity version, all with the same results pictured.

  • 6000.0.4f1
  • 2022.3.20f1
  • 2021.3.24f1
**System Information** Operating system: Windows 10 **Blender Version** Broken: 4.1.1 Worked: 4.0.2 **Short description of error** Normals are exported incorrectly to FBX files, artifacts show up when imported into Unity. It seems like normal smoothing information may be lost. I've confirmed this issue is in fact Blender, not Unity. Also confirmed it is still an issue on 4.3.0 Alpha. **Exact steps for others to reproduce the error** 1. See attached scene 2. Open in Blender 4.1.1 3. Export as FBX 4. Import into Unity, broken normals (see attached images). Tested attached FBX files in the following Unity version, all with the same results pictured. - 6000.0.4f1 - 2022.3.20f1 - 2021.3.24f1
Lucas-Brown-SSTK added the
Severity
Normal
Type
Report
Status
Needs Triage
labels 2024-06-11 18:25:56 +02:00
Member

Recently there had been a few reports on possible FBX exporting errors indeed. @Mysteryem Could you take a look?

Recently there had been a few reports on possible FBX exporting errors indeed. @Mysteryem Could you take a look?
YimingWu added the
Interest
Pipeline, Assets & IO
label 2024-06-12 04:52:56 +02:00
Member

To get this out of the way first:

  • test_4-0.fbx seems to have no texture associated with the normal map node
  • test_4-1.fbx seems to have a texture associated (HS_AK12_Forearm_Normal.png)

(at least this is what happens when you import them into blender)

When I open test.blend in Blender 4.1.1 and export as FBX, I dont get the texture associated when re-importing into Blender.

Not sure if this is responsible for the issue, just wanted to ask if both FBXes have really been exported from the exact same file?

To get this out of the way first: - `test_4-0.fbx` seems to have no texture associated with the normal map node - `test_4-1.fbx` seems to have a texture associated (`HS_AK12_Forearm_Normal.png`) (at least this is what happens when you import them into blender) When I open `test.blend` in Blender 4.1.1 and export as FBX, I dont get the texture associated when re-importing into Blender. Not sure if this is responsible for the issue, just wanted to ask if **both** FBXes have really been exported from the **exact** same file?
Philipp Oeser added
Status
Needs Information from User
and removed
Status
Needs Triage
labels 2024-06-12 15:27:49 +02:00

Whoops, I think I zipped up the wrong FBX files, there shouldn't be any reference to a normal map. I uploaded the correct FBXs now.
Originally I thought the normal map might be causing the problem so I created a flat normal map, same issue.
In the end I removed the normal map as it has no impact on this bug. I think it's something with the mesh data in the FBX.

Whoops, I think I zipped up the wrong FBX files, there shouldn't be any reference to a normal map. I uploaded the correct FBXs now. Originally I thought the normal map might be causing the problem so I created a flat normal map, same issue. In the end I removed the normal map as it has no impact on this bug. I think it's something with the mesh data in the FBX.
Philipp Oeser added
Status
Needs Triage
and removed
Status
Needs Information from User
labels 2024-06-12 16:42:54 +02:00
Member

From my investigation, this seems to be a Unity bug specifically with per-vertex normals exported with the IndexToDirect FBX reference mode, where Unity considers normals belonging to only a single face normals used by more than one vertex to be invalid and then throws out all the normals in the mesh and recalculates the normals itself. Unreal and FBX Review have no issues importing these normals (unreal will complain about no smoothing information in this case, but that can be remedied by exporting with FACE smoothing enabled).
image

I think this is a Unity bug because changing these normals to export with the Direct FBX reference mode works without issue and the only difference between Direct and IndexToDirect is how the data is stored in the FBX file: IndexToDirect can be used to remove duplicates and adds a second array of indices into the deduplicated array of normals that allows the full array, like would be exported with the Direct reference mode, to be reconstructed. Notably, the FBX SDK Documentation specifically states that normals should be exported as IndexToDirect.

Attached are two FBX models of a plane with per-vertex normals, one using the Direct reference mode and the other IndexToDirect.

Unfortunately, none of the models I tested with when testing the export of per-vertex normals had multiple vertices with exactly the same normals, so this wasn't noticed sooner.

In this case, it looks like Unity is recalculating of the normals is using an Area Weighted normal calculation which does not work well for this model. As a workaround for this issue, changing the normal mode in the FBX's import settings in Unity to Angle Weighted gives a much better result: image

From my investigation, this seems to be a Unity bug specifically with per-vertex normals exported with the `IndexToDirect` FBX reference mode, where Unity considers ~~normals belonging to only a single face~~ normals used by more than one vertex to be invalid and then throws out all the normals in the mesh and recalculates the normals itself. Unreal and FBX Review have no issues importing these normals (unreal will complain about no smoothing information in this case, but that can be remedied by exporting with FACE smoothing enabled). ![image](/attachments/57ddabb1-c563-436e-8c03-81ef38fc0b01) I think this is a Unity bug because changing these normals to export with the `Direct` FBX reference mode works without issue and the only difference between `Direct` and `IndexToDirect` is how the data is stored in the FBX file: `IndexToDirect` can be used to remove duplicates and adds a second array of indices into the deduplicated array of normals that allows the full array, like would be exported with the `Direct` reference mode, to be reconstructed. Notably, the FBX SDK Documentation specifically states that normals should be exported as `IndexToDirect`. Attached are two FBX models of a plane with per-vertex normals, one using the `Direct` reference mode and the other `IndexToDirect`. Unfortunately, none of the models I tested with when testing the export of per-vertex normals had multiple vertices with exactly the same normals, so this wasn't noticed sooner. In this case, it looks like Unity is recalculating of the normals is using an `Area Weighted` normal calculation which does not work well for this model. As a workaround for this issue, changing the normal mode in the FBX's import settings in Unity to `Angle Weighted` gives a much better result: ![image](/attachments/3b8c72a8-4b58-4175-a431-555214c43c85)
Member

Thx a lot for the info @Mysteryem !

How did you change it from IndexToDirect to Direct? Change the exporter code here?

# FBX SDK documentation says that normals should use IndexToDirect.
 elem_data_single_string(lay_nor, b"ReferenceInformationType", b"IndexToDirect")
Thx a lot for the info @Mysteryem ! How did you change it from `IndexToDirect` to `Direct`? Change the exporter code here? ```python # FBX SDK documentation says that normals should use IndexToDirect. elem_data_single_string(lay_nor, b"ReferenceInformationType", b"IndexToDirect") ```
Member

I've updated my findings because it seems that what Unity doesn't like is any normals being used by more than one vertex, which somewhat defeats the purpose of the IndexToDirect reference mode. Unity does not complain if I use IndexToDirect without deduplicating the normals, so the indices array is just [0, 1, 2, 3, 4, ...].

Thx a lot for the info @Mysteryem !

How did you change it from IndexToDirect to Direct? Change the exporter code here?

# FBX SDK documentation says that normals should use IndexToDirect.
 elem_data_single_string(lay_nor, b"ReferenceInformationType", b"IndexToDirect")

In this case I modified the file manually by converting it to json with the fbx2json.py script, adjusted the normals in a text editor and then converted back with the json2fbx.py script.

Here's a commit with changes to make the exporter use Direct instead of IndexToDirect: dc7c1add1d

I've updated my findings because it seems that what Unity doesn't like is any normals being used by more than one vertex, which somewhat defeats the purpose of the `IndexToDirect` reference mode. Unity does not complain if I use `IndexToDirect` without deduplicating the normals, so the indices array is just `[0, 1, 2, 3, 4, ...]`. > Thx a lot for the info @Mysteryem ! > > How did you change it from `IndexToDirect` to `Direct`? Change the exporter code here? > > ```python > # FBX SDK documentation says that normals should use IndexToDirect. > elem_data_single_string(lay_nor, b"ReferenceInformationType", b"IndexToDirect") > ``` In this case I modified the file manually by converting it to json with the fbx2json.py script, adjusted the normals in a text editor and then converted back with the json2fbx.py script. Here's a commit with changes to make the exporter use `Direct` instead of `IndexToDirect`: https://projects.blender.org/Mysteryem/blender/commit/dc7c1add1d2734e3f62120d5d46fbf7593e7bbee
Member

@Mysteryem : do we have an explanation why this worked in 4.0.2? (that might be interesting to mention in !123186)

@Mysteryem : do we have an explanation why this worked in 4.0.2? (that might be interesting to mention in !123186)
Philipp Oeser changed title from Normals export incorrectly to FBX to FBX Normals export issue (IndexToDirect interpreted wrong in Unity) 2024-06-14 08:59:04 +02:00
Member

Will confirm for now

Will confirm for now
Philipp Oeser added
Status
Confirmed
Interest
Import Export
and removed
Status
Needs Triage
labels 2024-06-14 08:59:42 +02:00
Philipp Oeser added the
Module
Pipeline, Assets & IO
label 2024-06-21 08:59:54 +02:00
Bart van der Braak added
Type
Bug
and removed
Type
Report
labels 2024-08-14 12:59:13 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info 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
4 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#123088
No description provided.