Page MenuHome

Mesh normals handling in Alembic
Closed, ResolvedPublic

Tokens
"Yellow Medal" token, awarded by Tetone."Love" token, awarded by dbystedt."Love" token, awarded by jayrajkharvadi."Love" token, awarded by ajohnson223."Love" token, awarded by thiagodesul."Love" token, awarded by Yegor."Love" token, awarded by zyzzxander."Love" token, awarded by lopoIsaac."Love" token, awarded by mooopstar."Love" token, awarded by craig_jones."Love" token, awarded by g-lul."Love" token, awarded by juang3d."Love" token, awarded by zeirus."Love" token, awarded by mistajuliax.
Authored By

Description

How Blender currently handles normals in the Alembic import/export causes various issues and confusion. Examples of previous issues are T56792: Alembic doesn't export custom normals correctly, T69182: Auto-Smooth does not work on Alembic meshes without normals, and T71130: Alembic split normal export issue. The goal of this design task is to document the current behaviour, describe issues, and propose a new approach.

Current behaviour

Current behaviour on export:

  • Exporting normals can be globally turned off by an exporter option.
  • Per mesh
    • Auto Smooth is turned on → loop normals are exported.
    • One or more polys are marked smooth → loop normals are exported.
    • Otherwise, vertex normals are exported.

Current behaviour on import:

An Alembic mesh can contain various kinds of normals, but only one at a time. So it only contains loop normals, or vertex normals (or other normals that Blender completely ignores).

  • The Alembic mesh contains vertex normals → mark mesh as smooth.
  • The Alembic mesh contains loop normals → use as custom loop normals, and enble Auto Smooth to have Blender actually use them.
  • The Alembic mesh contains no normals → mark mesh as flat.

Issues with the Current Behaviour

The current behaviour is hard to handle, mostly due to the fairly hidden and unintuitive use of the Auto Smooth checkbox. Furthermore, the handling of absent normals differs between Blender and other software; for example, the Alembic plugin for Maya assumes "no normals" means "smooth shaded", whereas Blender does the opposite.

Exporting normals can also have a significant effect on the file size. Even though Alembic is not aiming to be the smallest file format ever, it's still beneficial when Blender avoids producing overly large files when this can be avoided. I'm assuming that smooth shading is more common than flat shading.

Proposed Behaviour

The proposed behaviour aims to be easier to understand, produce smaller files in general cases, and be more compatible with other DCC suites.

Proposed behaviour on export:

  • Exporting normals can be globally turned off by an exporter option.
  • Per mesh
    • Custom loop normals are defined → loop normals are exported.
    • One or more polys are marked flat → loop normals are exported.
    • Otherwise, no normals are exported.

Proposed behaviour on import:

An Alembic mesh can contain various kinds of normals, but only one at a time. So it only contains loop normals, or vertex normals (or other normals that Blender completely ignores).

  • The Alembic mesh contains loop normals → use as custom loop normals, and enble Auto Smooth to have Blender actually use them.
  • The Alembic mesh contains vertex normals → convert to loop normals, and handle as above.
  • The Alembic mesh contains no normals → mark mesh as smooth.

Changes & Issues

The major changes in behaviour are:

  • "No normals" used to be interpreted as "flat", and I propose to change this to "smooth". This of course is a backward-incompatible change.
  • Assuming smooth shading is more common (it is in exporting animated characters), exporting will be faster and use less disk space.
  • Vertex normals are never written to Alembic any more.

To Be Discusses

Please let me know what you think of this proposal, mostly whether this is indeed as nice as I think it is (I think it's rather splendid) or whether there are downsides that I haven't seen/described yet.

Details

Type
Design

Event Timeline

would it be hard to make blender handle normals like vertex groups? So in the tab where we have normals. we simply choose the set? same like it is with UV.. and other stuff? and we simply have multiple flags where we can.. toggle what normal set is for viewport and what for rendering as defult... and also would be awesome if you could read those in shader useing.. attrbiute node for example.

would it be hard to make blender handle normals like vertex groups?

Yes, that would require much more work in Blender itself, and is beyond the scope of saving Blender meshes (as they are currently) to Alembic.

I would change that point on new import behavior:

The Alembic mesh contains vertex normals → mark mesh as smooth.

… to The Alembic mesh contains vertex normals → use as custom loop normals, and enble Auto Smooth to have Blender actually use them.

Think you will find some cases where custom normals (e.g. for toon shading effects) have been stored as vertex normals, because no 'hard edge' was desired, but normal directions others than default ones were used. Note that BKE has an API to set custom normals from per-vertex values as well. That’s what FBX is doing at least.

I would change that point on new import behavior:

The Alembic mesh contains vertex normals → mark mesh as smooth.

… to The Alembic mesh contains vertex normals → use as custom loop normals, and enble Auto Smooth to have Blender actually use them.
Think you will find some cases where custom normals (e.g. for toon shading effects) have been stored as vertex normals, because no 'hard edge' was desired, but normal directions others than default ones were used. Note that BKE has an API to set custom normals from per-vertex values as well. That’s what FBX is doing at least.

Another alternative:
Change:
The Alembic mesh contains vertex normals → mark mesh as smooth.
To:
The Alembic mesh contains vertex normals → determine if the provided vertex normals are identical to automatically calculated "smooth" mesh normals, and if they are, mark mesh as smooth. Otherwise, use as custom vertex normals, and enble Auto Smooth to have Blender actually use them.

However, this leads me to a question: Does blender have a concept of "custom vertex normals", or must any kind of custom normals be loop normals?

Blender has no concept of custom vertex normals, only loops (aka face corners) ones. Checking for 'equal to auto normals' might be possible, but won't be a cheap process, and not so sure it would be worth is… If you export your normals, even as vnors, then one can expect them to have some importance?

Blender has no concept of custom vertex normals, only loops (aka face corners) ones. Checking for 'equal to auto normals' might be possible, but won't be a cheap process, and not so sure it would be worth is… If you export your normals, even as vnors, then one can expect them to have some importance?

As to whether there's always importance, it's difficult for me to say without having surveyed all of the DCC exporters, but I think your approach is a good one in the near term especially since the comparison method can always be added later without harming backward compatibility if it's found that other many exporters unnecessarily include vertex normals.

FWIW, so far Blender has had the "vertex normals → shade smooth" approach, and I haven't seen any bug report about this behaviour as of yet.

@Bastien Montagne (mont29) How expensive/cheap is your proposed behaviour? If it's relatively cheap (compared to loading loop normals when they are stored in Alembic) I don't see any reason we shouldn't do this. Of course meshes can be deforming, so this process would happen every frame in such a case.

FWIW, so far Blender has had the "vertex normals → shade smooth" approach, and I haven't seen any bug report about this behaviour as of yet.

I can probably construct a failing testcase for this, if it's useful.

Reading vnors into custom lnors is about as expensive as reading real lnors.

Reading vnors into custom lnors is about as expensive as reading real lnors.

Ok. Let's just do that then.

FWIW, so far Blender has had the "vertex normals → shade smooth" approach, and I haven't seen any bug report about this behaviour as of yet.

I can probably construct a failing testcase for this, if it's useful.

Thanks, but with the change @Bastien Montagne (mont29) suggests we won't have that behaviour anyway.
Having a test case where custom loop normals are stored as vertex normals, that would be handy.

I've added an implementation in D6197, but I need an Alembic file to test it. If someone could share with me an Alembic mesh that contains explicit vertex normals + a screenshot so that I can verify that they're loaded correctly, that would be great.

Hi Sybren!

I did a quick setup in Houdini and exported 2 alembics. One where normals are assigned to vertecies and one on points. There is also a csv spreadsheet with point positions and normals per vertex

Thanks @Daniel Bystedt (dbystedt) , your files confirmed the code is doing its thing properly.

It's indeed a bit confusing how different applications name things:

AlembicBlenderHoudini
kFacevaryingScopeLoop NormalsVertex Normals
kVaryingScopeVertex NormalsPoint Normals
Andrew (ajohnson223) added a comment.EditedNov 6 2019, 10:29 AM

@Sybren A. Stüvel (sybren) Hmm, I actually thought Alembic kVertexScope == Blender Vertex Normals, rather than kVaryingScope.

Do you know offhand the difference between kVaryingScope and kVertexScope in alembic-world?

*edit* for reference, here's the Geometry Scope enum from Blender:
https://github.com/alembic/alembic/blob/a9efabe336b707f7f0b326bc1d9fb1e7a38d922d/lib/Alembic/AbcGeom/GeometryScope.h#L120

@Sybren A. Stüvel (sybren) Hmm, I actually thought Alembic kVertexScope == Blender Vertex Normals, rather than kVaryingScope.

Both are interpreted by Blender as vertex scope, see process_normals() in abc_mesh.cc: https://developer.blender.org/diffusion/B/browse/master/source/blender/alembic/intern/abc_mesh.cc$902

Do you know offhand the difference between kVaryingScope and kVertexScope in alembic-world?

Nope.

I got some clarification on kVaryingScope vs. kVertexScope here:

https://groups.google.com/d/msg/alembic-discussion/m6mVeR90bZY/iBPX6it2AboJ

quote:

kVertexScope = (for a mesh, this is a synonym of kVaryingScope. For other primitives, it can mean something distinct)

Thanks @Andrew (ajohnson223)

The changes in this task were implemented in rBb0e7a1d4b492, and as such will be part of Blender 2.82.

Thanks again @Sybren A. Stüvel (sybren), I'm sure it's working nicely but i'll put it through its paces soon.