 	*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;

		}

		if (!traverseLeft && !traverseRight) {
			node = *(--stack);
			stackpos -= 1;
		}

		if (right) {
			if (right->isLeaf()) {
				aten::hitrecord recRight;
				bool isHitRight = false;
				const auto& rightobj = ctxt.shapes[right->shapeid];

				if (right->nestid >= 0) {
					traverseRight = right->bbox.hit(r, t_min, t_max, &right_t);

					if (traverseRight && right_t < left_t) {
						right = &ctxt.nodes[right->nestid];
						nestedStackPos = stackpos;
					}
				}
				else {
					if (right->primid >= 0) {

					}
					else {
						isHitRight = intersectShape(rightobj, isNested ? transformedRay : r, t_min, t_max, recRight);
					}
				}

				if (isHitRight) {
					if (recRight.t < rec.t) {
						rec = recRight;
						rec.obj = (void*)&rightobj;
