 
 			// Stack hit children.
 			if (res > 0) {
-				for (int i = 0; i < numChildren; i++) {
-					if (res & (1 << i)) {
-						stack[stackpos] = QbvhIntersect(
-							leftChildrenIdx + i,
-							intersectT[i]);
+#pragma unroll
+				for (int i = 0; i < 4; i++) {
+					if ((res & (1 << i)) && intersectT[i] < t_max) {
+						stack[stackpos] = leftChildrenIdx + i;
 						stackpos++;
 					}
 				}


	int stackpos = beginStackPos + 1;

	stack[stackpos] = QbvhIntersect(0, t_max);
	stackpos++;
	
	while (stackpos > beginStackPos) {
		auto qi = stack[stackpos - 1];
		stackpos -= 1;

		if (qi.t > t_max) {
			continue;
		}

		// x : leftChildIdx, y : isLeaf, z : numChildren
		float4 node = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 0);

		// x: shapeid, y : primid, z : exid, w : meshid
		float4 attrib = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 1);

		float4 bminx = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 2);
		float4 bmaxx = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 3);
		float4 bminy = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 4);
		float4 bmaxy = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 5);
		float4 bminz = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 6);
		float4 bmaxz = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * qi.nodeid + 7);

		int leftChildrenIdx = (int)node.x;
		int isLeaf = (int)node.y;

	aten::Intersection* isect)
{
	static const int stacksize = 64;
	int stack[stacksize];

	aten::Intersection isectTmp;

	isect->t = t_max;

	int stackpos = 0;
	stack[stackpos] = 0;
	stackpos++;

	while (stackpos > 0) {
		int nodeid = stack[stackpos - 1];
		stackpos -= 1;

		// x : leftChildIdx, y : isLeaf, z : numChildren
		float4 node = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 0);

		// x: shapeid, y : primid, z : exid, w : meshid
		float4 attrib = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 1);

		float4 bminx = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 2);
		float4 bmaxx = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 3);
		float4 bminy = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 4);
		float4 bmaxy = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 5);
		float4 bminz = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 6);
		float4 bmaxz = tex1Dfetch<float4>(nodes, aten::GPUBvhNodeSize * nodeid + 7);

		int leftChildrenIdx = (int)node.x;
		int isLeaf = (int)node.y;
