public virtual Spectrum rho(int nSamples, IEnumerable <Point2D> samples1, IEnumerable <Point2D> samples2) { var u1 = samples1.ToList(); var u2 = samples2.ToList(); Spectrum r = Spectrum.Create(0.0); for (int i = 0; i < nSamples; ++i) { // Estimate one term of $\rho_\roman{hh}$ Vector3D wo = Sampling.UniformSampleHemisphere(u1[i]); double pdfo = Sampling.UniformHemispherePdf(); Spectrum f = Sample_f(wo, out Vector3D wi, u2[i], out double pdfi, out BxdfType sampledType); if (pdfi > 0) { r += f * Reflection.AbsCosTheta(wi) * Reflection.AbsCosTheta(wo) / (pdfo * pdfi); } } return(r / (Math.PI * nSamples)); }
public virtual Spectrum Sample_f( Vector3D wo, out Vector3D wi, Point2D sample, out double pdf, out BxdfType sampledType) { sampledType = BxdfType.None; // Cosine-sample the hemisphere, flipping the direction if necessary wi = Sampling.CosineSampleHemisphere(sample); if (wo.Z < 0.0) { wi = new Vector3D(wi.X, wi.Y, -wi.Z); } pdf = Pdf(wo, wi); return(f(wo, wi)); }