[Bf-blender-cvs] [3143ec2] master: Fix T45606: cycles multires tangent space normal map bake issues.

Brecht Van Lommel noreply at git.blender.org
Sun Feb 14 03:56:55 CET 2016


Commit: 3143ec29d0577948f2f7750c47a6a84ab33f39d7
Author: Brecht Van Lommel
Date:   Sun Feb 14 01:54:09 2016 +0100
Branches: master
https://developer.blender.org/rB3143ec29d0577948f2f7750c47a6a84ab33f39d7

Fix T45606: cycles multires tangent space normal map bake issues.

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

M	source/blender/editors/object/object_bake_api.c
M	source/blender/render/intern/source/bake_api.c

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

diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index 51affb3..3c9b43b 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -647,6 +647,9 @@ static int bake(
 	Mesh *me_low = NULL;
 	Mesh *me_cage = NULL;
 
+	MultiresModifierData *mmd_low = NULL;
+	int mmd_flags_low = 0;
+
 	float *result = NULL;
 
 	BakePixel *pixel_array_low = NULL;
@@ -762,6 +765,17 @@ static int bake(
 	pixel_array_high = MEM_mallocN(sizeof(BakePixel) * num_pixels, "bake pixels high poly");
 	result = MEM_callocN(sizeof(float) * depth * num_pixels, "bake return pixels");
 
+	/* for multires bake, use linear UV subdivision to match low res UVs */
+	if (pass_type == SCE_PASS_NORMAL && normal_space == R_BAKE_SPACE_TANGENT && !is_selected_to_active)
+	{
+		mmd_low = (MultiresModifierData *) modifiers_findByType(ob_low, eModifierType_Multires);
+		if (mmd_low)
+		{
+			mmd_flags_low = mmd_low->flags;
+			mmd_low->flags |= eMultiresModifierFlag_PlainUv;
+		}
+	}
+
 	/* get the mesh as it arrives in the renderer */
 	me_low = bake_mesh_new_from_object(bmain, scene, ob_low);
 
@@ -1063,6 +1077,9 @@ cleanup:
 
 	ob_low->restrictflag = restrict_flag_low;
 
+	if (mmd_low)
+		mmd_low->flags = mmd_flags_low;
+
 	if (ob_cage)
 		ob_cage->restrictflag = restrict_flag_cage;
 
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c
index bac8df4..21460c7 100644
--- a/source/blender/render/intern/source/bake_api.c
+++ b/source/blender/render/intern/source/bake_api.c
@@ -792,7 +792,10 @@ void RE_bake_normal_world_to_tangent(
 		offset = i * depth;
 
 		if (primitive_id == -1) {
-			copy_v3_fl3(&result[offset], 0.5f, 0.5f, 1.0f);
+			if (depth == 4)
+				copy_v4_fl4(&result[offset], 0.5f, 0.5f, 1.0f, 1.0f);
+			else
+				copy_v3_fl3(&result[offset], 0.5f, 0.5f, 1.0f);
 			continue;
 		}




More information about the Bf-blender-cvs mailing list