Maniphest T96977

TODO: set the default margin generation back to extend for the baking of normals in tangent space.
Closed, ResolvedBUG

Assigned To
Brecht Van Lommel (brecht)
Authored By
Martijn Versteegh (Baardaap)
Apr 2 2022, 12:41 PM
Tags
  • Render & Cycles
  • BF Blender (3.2)
Subscribers
Brecht Van Lommel (brecht)
Martijn Versteegh (Baardaap)

Description

See https://developer.blender.org/T96942

When baking normals in tangent space, the normals are relative to the UV map so you can't just copy color values across UV boundaries because it will lead to artifacts.

In this case it would be much better to set the default back to Extend. Or maybe even just disable the Adjacent faces option because it is just not applicable for this specific situation.

Revisions and Commits

rB Blender
D14572

Event Timeline

Martijn Versteegh (Baardaap) changed the task status from Needs Triage to Confirmed.Apr 2 2022, 12:41 PM
Martijn Versteegh (Baardaap) created this task.
Martijn Versteegh (Baardaap) added a subscriber: Brecht Van Lommel (brecht).Apr 2 2022, 12:43 PM

@Brecht Van Lommel (brecht) Do you have an opinion on this?

I think it's best to just always use 'extend' in the specific case of normal baking in tangent space. But I'm not really sure how to communicate that in the UI.

Is there a way to disable one of the options depending on the rest of the settings?

Brecht Van Lommel (brecht) added a comment.Apr 4 2022, 5:14 PM

In the Python UI code you would just hide the option depending if tangent normal maps are selected, and then match the same behavior internally.

Can we make tangent normal maps work with Adjacent Faces? At least in principle we can write the same normal to both pixels but encode it in a different tangent space.

Martijn Versteegh (Baardaap) added a comment.Apr 4 2022, 10:51 PM

Technically probably yes. Though I don't really know enough/ have enough experience with tangent space to really know how. I can sort of imagine what would need to be done (probably rotate the x and y (?) components the same amount as the angle between the corresponding edges? Something like that).

I'd need some help/docs about how *exactly* tangent space works as I have a global conceptual understanding of what it is, but no actual experience with the math.

It would probably be something like:

  • look up pixel from adjacent face (Which can actually search through multiple faces for very narrow faces)
  • determine the difference in angle between the original edge the margin pixel belongs to and the edge of the polygon it lands in.
  • interpret the rgb values as xyz. rotate (around (0,0,1)?) with that angle difference (or the negative), recode in rgb
Brecht Van Lommel (brecht) added a comment.Apr 5 2022, 9:21 PM

The normals are baked in world space, and then transformed to tangent space with RE_bake_normal_world_to_tangent.

I don't think you would try to rotate the normal, rather you'd figure out which triangle and barycentric coordinate to use for encoding the tangent space in, and then use that to transform from world to tangent space like any other pixel.

The problem is that the code is structured to first do the tangent space conversion and then do the margin. One way to make this work would be to do the margin first, and ensure it writes an appropriate triangle id + barycentric coordinate for the tangent conversion to work.

Not sure how difficult this is, just disabling this margin method for tangent space is also ok if you don't have the time.

Martijn Versteegh (Baardaap) added a comment.Apr 5 2022, 10:11 PM

But the adjacent faces margin generation algorithm is purely a pixel-based post processing step after the baking itself.

So I don't really understand what you mean here.

You mean the baking happens in world space and the conversion to tangent space is also a post processing step? If that is true it would probably not be very hard to move the converting to tangent space to after the margin generation. The margin generation code already looks up the 'owning' triangle for each margin pixel.

I can look into it a bit and see if I think it's manageable. I don't think I could do it before 3.2 though, so maybe best to (temporarily) disable it for 3.2 ?

Brecht Van Lommel (brecht) added a comment.Apr 5 2022, 10:19 PM

The conversion to tangent space is also a post processing step, yes. And it would be best to have this fixed for 3.2, so temporarily disabling this for tangent bakes may be best then.

Martijn Versteegh (Baardaap) added a project: BF Blender (3.2).Apr 7 2022, 10:03 AM
Martijn Versteegh (Baardaap) moved this task from Backlog to bcon3: Bugs on the BF Blender (3.2) board.
Martijn Versteegh (Baardaap) added a comment.Apr 7 2022, 10:12 PM

I added a diff to disable for now. Doing it properly is not exactly trivial I think. I'll look into that in more detail later.

I also disabled Adjacent Faces mode for UV baking , as it was nonsensical there.

Brecht Van Lommel (brecht) added a commit: rB811371a6bddd: Fix T96942: disable Adjacent Faces margin for UVs and tangent space bake.Apr 10 2022, 4:32 PM
Brecht Van Lommel (brecht) changed the subtype of this task from "Report" to "Bug".Apr 28 2022, 5:48 PM
Martijn Versteegh (Baardaap) added a comment.May 7 2022, 10:20 PM

Shall I mark this as resolved?

I'd like a way to keep in mind that the extend method *could* support normal baking if we refactor the code to do the extending first and the converting to adjacent space later. But just keeping this open seems incorrect?

Brecht Van Lommel (brecht) closed this task as Resolved.May 9 2022, 8:13 PM
Brecht Van Lommel (brecht) claimed this task.

We can indeed close this.