Page MenuHome

Fix T43553 Cycles Bake does not support dupligroups
Needs ReviewPublic

Authored by Dalai Felinto (dfelinto) on Apr 29 2015, 6:46 AM.

Details

Summary

work in progress!

@Sergey Sharybin (sergey) could you review the cycles part? I'm not sure how to actually use the Transform in kernel_bake.h (see the TODOs there), but apart from that I think it's correct.

In the Blender side I still need to populate the bake data with the dupli objects and pass the matrix.

I think the matrix I need to pass is one that can be used directly by the kernel_bake.h, and it will be an identity matrix for all but the dupli objects.
For those I probably need the dupli matrix in relation to the object original matrix.

Diff Detail

Repository
rB Blender
Branch
fix-bake-dupli

Event Timeline

Dalai Felinto (dfelinto) retitled this revision from to Fix T43553 Cycles Bake does not support dupligroups.
Dalai Felinto (dfelinto) updated this object.

Not really sure about passing transform all over the place is the cleanest approach.

Did you check if it's possible to use same object info as we're using for instances in render kernel?

And also not really sure. You put transform into Task, is it because you're aiming doing multiple instances in separate threads?

Did you check if it's possible to use same object info as we're using for instances in render kernel?

The multiplication bit? I will check, I'm not even sure on how to use the Transform, so any sample code will help.

And also not really sure. You put transform into Task, is it because you're aiming doing multiple instances in separate threads?

I went along with what we were doing for shader_type. I can store the orientation in the kernel globals instead.

Shader type makes sense to be stored in Task since it describes how exactly task is to be handled. using task for passing some extra data for the kernel invocation is a bad design. Using kernel globals for that is also wrong because it is supposed to be used for data which is global for the whole kernel.

I'm still not sure why you can't use __objects storage which already contains object transform.

Dalai Felinto (dfelinto) edited edge metadata.
  • Bake-API: changes required to handle duplicated objects

@Sergey Sharybin (sergey) this now has the bulk of the proposed changes for the Bake-API (the Blender side, not the Cycles part).

Cycles itself still misses using the actual matrix to transform its rays.
(which also means I haven't fully tested this patch yet)

I think I'm running into some memories issues with this patch, that I will investigate it later.
I would appreciate your thoughts on the current design though.

I'm still not sure why you can't use __objects storage which already contains object transform.

I'm not familiar with this. But I can look at that once we get the patch working. Either way I hope it's clear that the transformation we need is not already in __objects since it's neither the parent object or the duplicated object matrix.

This revision was automatically updated to reflect the committed changes.

:/ I pushed it to the wrong repository, it was never intended to go to blender.org

  • code typo, assert fix and small changes

There is no longer memory issues here.

  • Using transform_point and transform_direction to effectively transform the rays

    The result is still not correct, but I'm not sure if the problem is in Cycles or the Blender side (the matrix).
Sergey Sharybin (sergey) requested changes to this revision.Jun 10 2015, 9:11 AM
Sergey Sharybin (sergey) edited edge metadata.

@Dalai Felinto (dfelinto), don't really think transforming normal as a direction is correct here, it'll give issues in cases with shear. You need either to multiply by either transposed or transposed inversed matrix (depending on which space you're changing the normal in).

Replying on earlier comment: yes, tfm is not in the __objects but i think reasonable thing to do would be to make it so __objects are getting updated by baking pipeline instead of passing those arguments around. Could be done later once everything else is working.

As for changes in baking API -- think it's reasonable changes in the RNA level. Blender-side also seems reasonable from quick look (didn't check for errors or something like this).

One idea tho would be to make it a Py API call to triangulate the mesh. We briefly discussed it with @Campbell Barton (campbellbarton) and prefer him to do dump of those discussion :)

This revision now requires changes to proceed.Jun 10 2015, 9:11 AM

Only minor suggestions. (ontop of sergey's comments)

source/blender/editors/object/object_bake_api.c
552–567

Realize its not directly related to this patch (since the triangulate modifier was used already), but think we could use tessface layout, or have a version of BKE_mesh_recalc_tessellation that outputs MPoly tri's instead of MFace's\

Would avoid going via BMesh conversion.

959–960

No strong opinion. But this could just be a NULL argument. to avoid doing any transformation. (since this is such a common case)

Dalai Felinto (dfelinto) edited edge metadata.
  • Fix crash - we have only one DM per mesh, but we were not using them correctly
  • Fix: storing the baking matrix in .mat, not .imat - this was leading to any ray to miss the objects
  • Fix: rays were missing the high poly objects when the parent object had transformation (dob->mat is already in world space)

Things are working :)
Now it's a good time to address eventual design issues.

Dalai Felinto (dfelinto) edited edge metadata.
  • Merge remote-tracking branch 'origin/master' into fix-bake-dupli
  • Documenting matrix in the API

Merge master in to make easy to review the upcoming patch

  • From review: use NULL for identity matrices

@Campbell Barton (campbellbarton) this is what you suggested. Is that ok?
Also I know CPU can take the NULL pointer as paramenters, but I'm not sure about GPU (nor can I test here). @Sergey Sharybin (sergey) any thoughts?

Replies to @Campbell Barton (campbellbarton) :

Realize its not directly related to this patch (since the triangulate modifier was used already), but think we could use tessface layout, or have a version of BKE_mesh_recalc_tessellation that outputs MPoly tri's instead of MFace's

As you mentioned, triangulated modifier was used already. I'm ok with trying this *after* dupli group is fixed. But not as part of the main/current patch.

No strong opinion. But this could just be a NULL argument. to avoid doing any transformation. (since this is such a common case)

Ok, this is addressed here:
https://developer.blender.org/D1271?vs=4559&id=4560&whitespace=ignore-most#toc

See my previous comment on that matter (re: GPU)

@Sergey Sharybin (sergey) I tried a new/clean approach yesterday, but something is not working.

Basically I'm passing the ob_dup->mat for the baking function, and using it to get the correct object_id:

	/* for duplicated objects, we get the object id by the object name and its transformation matrix */
	if(matrix)
		tfm = get_transform(*matrix);

	/* find object index. todo: is arbitrary - copied from mesh_displace.cpp */
	for(size_t i = 0; i < scene->objects.size(); i++) {
		Object *b_ob = scene->objects[i];

		if(strcmp(b_ob->name.c_str(), b_object.name().c_str()) == 0) {

			/* duplicated object of the same type but not the right copy of it */
			if(matrix && tfm != b_ob->tfm)
				continue;

			fprintf(stderr, "%s : %lu : %s\n", __func__, i, b_ob->name.c_str());

			object_index = i;
			tri_offset = b_ob->mesh->tri_offset;
			break;
		}
	}

(and add a #if 0 #endif in kernel_bake.h to remove the transformations previously added)

This part works fine, and it gives me different ids for each of the baked objects and dupli objects. The problem is, I still need to transform the position and direction in kernel for this to work correctly.

Shouldn't the above be all I need? I expected the dupli object to work just like any other object.

  • Merge remote-tracking branch 'origin/master' into fix-bake-dupli

(to get the recent cycles bake fixes)

@Brecht Van Lommel (brecht) do you have time to take a quick look at this? Maybe some suggestions ... sergey has been quite busy lately (understandably so), and I would love to be done with this patch :)