[Bf-blender-cvs] [811371a6bdd] master: Fix T96942: disable Adjacent Faces margin for UVs and tangent space bake

Martijn Versteegh noreply at git.blender.org
Sun Apr 10 16:31:23 CEST 2022


Commit: 811371a6bddd5c3d7ea33fa8a5ccb7d3d36baf43
Author: Martijn Versteegh
Date:   Fri Apr 8 17:43:44 2022 +0200
Branches: master
https://developer.blender.org/rB811371a6bddd5c3d7ea33fa8a5ccb7d3d36baf43

Fix T96942: disable Adjacent Faces margin for UVs and tangent space bake

Use the Extend method for these, as these do not work correctly. For UVs
it's better to extend the UVs from the same face, and for tangent space
the normals should be encoded in a matching tangent space.

Later the Adjacent Faces method might be improved to support these cases.

Ref T96977

Differential Revision: https://developer.blender.org/D14572

===================================================================

M	intern/cycles/blender/addon/ui.py
M	source/blender/editors/object/object_bake.c
M	source/blender/editors/object/object_bake_api.c

===================================================================

diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 2c6788b867b..739a555f037 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -1916,13 +1916,20 @@ class CYCLES_RENDER_PT_bake_output_margin(CyclesButtonsPanel, Panel):
         cbk = scene.render.bake
         rd = scene.render
 
-        if rd.use_bake_multires:
-            layout.prop(rd, "bake_margin_type", text="Type")
-            layout.prop(rd, "bake_margin", text="Size")
+        if (cscene.bake_type == 'NORMAL' and cbk.normal_space == 'TANGENT') or cscene.bake_type == 'UV':
+            if rd.use_bake_multires:
+                layout.prop(rd, "bake_margin", text="Size")
+            else:
+                if cbk.target == 'IMAGE_TEXTURES':
+                    layout.prop(cbk, "margin", text="Size")
         else:
-            if cbk.target == 'IMAGE_TEXTURES':
-                layout.prop(cbk, "margin_type", text="Type")
-                layout.prop(cbk, "margin", text="Size")
+            if rd.use_bake_multires:
+                layout.prop(rd, "bake_margin_type", text="Type")
+                layout.prop(rd, "bake_margin", text="Size")
+            else:
+                if cbk.target == 'IMAGE_TEXTURES':
+                    layout.prop(cbk, "margin_type", text="Type")
+                    layout.prop(cbk, "margin", text="Size")
 
 
 
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index d93edd2776b..d469efbd0a1 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -359,7 +359,12 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
     /* copy data stored in job descriptor */
     bkr.scene = scene;
     bkr.bake_margin = scene->r.bake_margin;
-    bkr.bake_margin_type = scene->r.bake_margin_type;
+    if (scene->r.bake_mode == RE_BAKE_NORMALS) {
+      bkr.bake_margin_type = R_BAKE_EXTEND;
+    }
+    else {
+      bkr.bake_margin_type = scene->r.bake_margin_type;
+    }
     bkr.mode = scene->r.bake_mode;
     bkr.use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
     bkr.bias = scene->r.bake_biasdist;
@@ -404,7 +409,12 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
   /* backup scene settings, so their changing in UI would take no effect on baker */
   bkj->scene = scene;
   bkj->bake_margin = scene->r.bake_margin;
-  bkj->bake_margin_type = scene->r.bake_margin_type;
+  if (scene->r.bake_mode == RE_BAKE_NORMALS) {
+    bkj->bake_margin_type = R_BAKE_EXTEND;
+  }
+  else {
+    bkj->bake_margin_type = scene->r.bake_margin_type;
+  }
   bkj->mode = scene->r.bake_mode;
   bkj->use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
   bkj->bake_clear = scene->r.bake_flag & R_BAKE_CLEAR;
diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index fec87fbfa95..3060a1ecf62 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -1670,6 +1670,11 @@ static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr)
   if (bkr->save_mode == R_BAKE_SAVE_EXTERNAL) {
     bkr->save_mode = R_BAKE_SAVE_INTERNAL;
   }
+
+  if (((bkr->pass_type == SCE_PASS_NORMAL) && (bkr->normal_space == R_BAKE_SPACE_TANGENT)) ||
+      bkr->pass_type == SCE_PASS_UV) {
+    bkr->margin_type = R_BAKE_EXTEND;
+  }
 }
 
 static int bake_exec(bContext *C, wmOperator *op)



More information about the Bf-blender-cvs mailing list