 			if (traverseLeft && traverseRight) {
 				*(stack++) = right;
 				stackpos += 1;
+			}
+
+			if (!isNested && nestedStackPos >= 0) {
+				const auto& param = ctxt.shapes[node->shapeid];
+				transformedRay = param.mtxW2L.applyRay(r);
+				isNested = true;
 			}
 		}
 		AT_ASSERT(0 <= stackpos && stackpos < STACK_SIZE);

		bool traverseLeft = false;
		bool traverseRight = false;

		if (left) {
			if (left->isLeaf()) {
				aten::hitrecord recLeft;
				const auto& leftobj = ctxt.shapes[left->shapeid];

				if (intersectShape(leftobj, r, t_min, t_max, recLeft)) {
					if (recLeft.t < rec.t) {
						rec = recLeft;
						rec.obj = (void*)&leftobj;

	*stack++ = nullptr;

	int stackpos = 1;
	int nestedStackPos = -1;

	aten::BVHNode* node = &ctxt.nodes[0];

	aten::ray transformedRay = r;
	bool isNested = false;

	do {
		aten::BVHNode* left = node->left >= 0 ? &ctxt.nodes[node->left] : nullptr;
