 		ctxt.matrices = matrices;
 	}
 
+	auto ray = rays[idx];
+
 	aten::hitrecord rec;
 	aten::Intersection isect;
 
-	bool isHit = intersectBVH(&ctxt, camsample.r, &isect);
+	bool isHit = intersectBVH(&ctxt, ray, &isect);
 
 	if (isHit) {
 		auto obj = &ctxt.shapes[isect.objid];
-		evalHitResult(&ctxt, obj, camsample.r, &rec, &isect);
+		evalHitResult(&ctxt, obj, ray, &rec, &isect);
 
 		aten::vec4 pos = aten::vec4(rec.p, 1);
 		pos = mtxW2C.apply(pos);


	const auto idx = getIdx(ix, iy, width);

	aten::sampler sampler;
	sampler.init((iy * height * 4 + ix * 4) * maxSamples + sample + 1 + seed, sobolmatrices);

	float s = (ix + sampler.nextSample()) / (float)(camera->width - 1);
	float t = (iy + sampler.nextSample()) / (float)(camera->height - 1);

	AT_NAME::CameraSampleResult camsample;
	AT_NAME::PinholeCamera::sample(&camsample, camera, s, t);

	Context ctxt;
	{
		ctxt.geomnum = geomnum;

			sample, maxSamples,
			seed,
			mtxW2C,
			rays.ptr(),
			shapeparam.ptr(), shapeparam.num(),
			nodetex.ptr(),
			primparams.ptr(),
