Spectrum sampleRayDifferential(RayDifferential &ray, const Point2 &pixelSample, const Point2 &otherSample, Float timeSample) const { /* Record pixel index, added by Lifan */ ray.index.x = (int)std::floor(pixelSample.x); ray.index.y = (int)std::floor(pixelSample.y); Point2 tmp = warp::squareToUniformDiskConcentric(otherSample) * m_apertureRadius; ray.time = sampleTime(timeSample); /* Compute the corresponding position on the near plane (in local camera space) */ Point nearP = m_sampleToCamera(Point( pixelSample.x * m_invResolution.x, pixelSample.y * m_invResolution.y, 0.0f)); /* Aperture position */ Point apertureP(tmp.x, tmp.y, 0.0f); /* Sampled position on the focal plane */ Float fDist = m_focusDistance / nearP.z; Point focusP = nearP * fDist; Point focusPx = (nearP+m_dx) * fDist; Point focusPy = (nearP+m_dy) * fDist; /* Turn that into a normalized ray direction, and adjust the ray interval accordingly */ Vector d = normalize(focusP - apertureP); Float invZ = 1.0f / d.z; ray.mint = m_nearClip * invZ; ray.maxt = m_farClip * invZ; const Transform &trafo = m_worldTransform->eval(ray.time); ray.setOrigin(trafo.transformAffine(apertureP)); ray.setDirection(trafo(d)); ray.rxOrigin = ray.ryOrigin = ray.o; ray.rxDirection = trafo(normalize(Vector(focusPx - apertureP))); ray.ryDirection = trafo(normalize(Vector(focusPy - apertureP))); ray.hasDifferentials = true; return Spectrum(1.0f); }
Spectrum sampleRayDifferential(RayDifferential &ray, const Point2 &pixelSample, const Point2 &otherSample, Float timeSample) const { ray.time = sampleTime(timeSample); const Transform &trafo = m_worldTransform->eval(ray.time); /* Compute the corresponding position on the near plane (in local camera space) */ Point nearP = m_sampleToCamera.transformAffine(Point( pixelSample.x * m_invResolution.x, pixelSample.y * m_invResolution.y, 0.0f)); nearP.z = 0.0f; ray.setOrigin(trafo.transformAffine(nearP)); ray.setDirection(normalize(trafo(Vector(0, 0, 1)))); ray.mint = m_nearClip; ray.maxt = m_farClip; ray.rxOrigin = trafo(nearP + m_dx); ray.ryOrigin = trafo(nearP + m_dy); ray.rxDirection = ray.ryDirection = ray.d; ray.hasDifferentials = true; return Spectrum(1.0f); }