BSDF *Material::getBSDF(SurfacePoint &pt) { BSDF *bsdf = NULL; if (m_bsdf == "diffuse") { bsdf = new DiffuseBSDF(pt, this); } else if (m_bsdf == "dielectric") { bsdf = new DielectricBSDF(pt, this); } else if (m_bsdf == "modifiedPhong" || m_bsdf == "phong") { bsdf = new ModifiedPhongBSDF(pt, this); } else if (m_bsdf == "absorbent") { bsdf = new AbsorbentBSDF(pt, this); } else if (m_bsdf == "specular") { (*this)["transparency"] = 0.0; bsdf = new DielectricBSDF(pt, this); } else if (m_bsdf == "transmissive") { (*this)["transparency"] = 1.0; bsdf = new DielectricBSDF(pt, this); } else { cerr << "invalid material (BSDF type): " << m_bsdf << endl; ASSERT(0 && "Found Invalid Material (BSDF type)"); return NULL; } bsdf->init(); return bsdf; }
BDPTPathVertex(const Scene& scene, const PowerBasedLightSampler& sampler, float lightSample, const Vec2f& positionSample, const Vec2f& directionSample, const Light*& pLight, float& lightPdf, uint32_t pathCount, MisFunctor&& mis) { pLight = sampler.sample(scene, lightSample, lightPdf); if(!pLight) { lightPdf = 0.f; m_Power = zero<Vec3f>(); m_fPathPdf = 0.f; m_nDepth = 0u; return; } RaySample raySample; float rayOriginPdf, intersectionPdfWrtArea, rayOriginToIncidentDirJacobian; auto Le = pLight->sampleExitantRay(scene, positionSample, directionSample, raySample, rayOriginPdf, m_Intersection, rayOriginToIncidentDirJacobian, intersectionPdfWrtArea); if(Le == zero<Vec3f>() || raySample.pdf == 0.f) { m_Power = Le; m_fPathPdf = 0.f; m_nDepth = 0u; return; } raySample.pdf *= lightPdf; Le /= raySample.pdf; m_Power = Le; m_nDepth = 1u; if(!m_Intersection) { m_fPathPdf = 0.f; m_fPdfWrtArea = 0.f; m_fdVC = 0.f; m_fdVCM = 0.f; } else { m_BSDF.init(-raySample.value.dir, m_Intersection, scene); m_fPathPdf = rayOriginPdf * intersectionPdfWrtArea; m_fPdfWrtArea = intersectionPdfWrtArea; m_fdVCM = mis(pathCount / m_fPdfWrtArea); m_fdVC = mis(pathCount * rayOriginToIncidentDirJacobian / m_fPathPdf); } }
BDPTPathVertex(const Scene& scene, const Sensor& sensor, const Vec2f& lensSample, const Vec2f& imageSample, uint32_t pathCount, MisFunctor&& mis) { RaySample raySample; float rayOriginPdf, rayDirectionPdf, intersectionPdfWrtArea, rayOriginToIncidentDirJacobian; auto We = sensor.sampleExitantRay(scene, lensSample, imageSample, raySample, rayOriginPdf, rayDirectionPdf, m_Intersection, rayOriginToIncidentDirJacobian, intersectionPdfWrtArea); if(We == zero<Vec3f>() || raySample.pdf == 0.f) { m_Power = We; m_fPathPdf = 0.f; m_nDepth = 0u; return; } We /= raySample.pdf; m_Power = We; m_nDepth = 1u; if(!m_Intersection) { m_fPathPdf = raySample.pdf; m_fPdfWrtArea = 0.f; m_fdVC = 0.f; m_fdVCM = 0.f; } else { m_BSDF.init(-raySample.value.dir, m_Intersection, scene); m_fPathPdf = rayOriginPdf * intersectionPdfWrtArea; m_fPdfWrtArea = intersectionPdfWrtArea; m_fdVCM = mis(pathCount / m_fPdfWrtArea); m_fdVC = mis(pathCount * rayOriginToIncidentDirJacobian / m_fPathPdf); } }