public bool RayCast(int index, int nodeID) { if (NativeNodes[nodeID].IsLeaf == 1) { float bestDist = float.MaxValue; HitInfo hitInfo = new HitInfo(); for (int i = 0; i < NativeNodes[nodeID].PrimitivesCount; i++) { hitInfo.Clear(); if (NativePrims[NativeNodes[nodeID].PrimitivesOffset + i].IntersectRay(Rays[index], out hitInfo)) { if (hitInfo.HitDistance < bestDist) { bestDist = hitInfo.HitDistance; HitInfos.Add(new HitInfo(hitInfo)); } } } } else { // ReSharper disable once NotAccessedVariable float hitDist; if (BVHBBox.IntersectRay(Rays[index], NativeNodes[nodeID].BMin, NativeNodes[nodeID].BMax, out hitDist)) { float d1; float d2; int lNodeID = NativeNodes[nodeID].LChildID; int rNodeID = NativeNodes[nodeID].RChildID; bool bHitL = BVHBBox.IntersectRay(Rays[index], NativeNodes[lNodeID].BMin, NativeNodes[lNodeID].BMax, out d1); bool bHitR = BVHBBox.IntersectRay(Rays[index], NativeNodes[rNodeID].BMin, NativeNodes[rNodeID].BMax, out d2); if (bHitL && bHitR) { if (d1 > d2) { RayCast(index, lNodeID); RayCast(index, rNodeID); } else { RayCast(index, rNodeID); RayCast(index, lNodeID); } } else if (bHitL) { RayCast(index, lNodeID); } else if (bHitR) { RayCast(index, rNodeID); } } } return(false); }