MCPcopy Create free account
hub / github.com/RenderKit/embree / OBJMaterial__sample

Function OBJMaterial__sample

tutorials/pathtracer/pathtracer_device.cpp:573–633  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

571}
572
573Vec3fa OBJMaterial__sample(ISPCOBJMaterial* material, const BRDF& brdf, const Vec3fa& Lw, const Vec3fa& wo, const DifferentialGeometry& dg, Sample3f& wi_o, Medium& medium, const Vec2f& s)
574{
575 Vec3fa cd = Vec3fa(0.0f);
576 Sample3f wid = make_Sample3f(Vec3fa(0.0f),0.0f);
577 if (max(max(brdf.Kd.x,brdf.Kd.y),brdf.Kd.z) > 0.0f) {
578 wid = cosineSampleHemisphere(s.x,s.y,dg.Ns);
579 cd = float(one_over_pi) * clamp(dot(wid.v,dg.Ns)) * brdf.Kd;
580 }
581
582 Vec3fa cs = Vec3fa(0.0f);
583 Sample3f wis = make_Sample3f(Vec3fa(0.0f),0.0f);
584 if (max(max(brdf.Ks.x,brdf.Ks.y),brdf.Ks.z) > 0.0f)
585 {
586 const Sample3f refl = make_Sample3f(reflect(wo,dg.Ns),1.0f);
587 wis.v = powerCosineSampleHemisphere(brdf.Ns,s);
588 wis.pdf = powerCosineSampleHemispherePDF(wis.v,brdf.Ns);
589 wis.v = frame(refl.v) * wis.v;
590 cs = (brdf.Ns+2) * float(one_over_two_pi) * powf(max(dot(refl.v,wis.v),1e-10f),brdf.Ns) * clamp(dot(wis.v,dg.Ns)) * brdf.Ks;
591 }
592
593 Vec3fa ct = Vec3fa(0.0f);
594 Sample3f wit = make_Sample3f(Vec3fa(0.0f),0.0f);
595 if (max(max(brdf.Kt.x,brdf.Kt.y),brdf.Kt.z) > 0.0f)
596 {
597 wit = make_Sample3f(neg(wo),1.0f);
598 ct = brdf.Kt;
599 }
600
601 const Vec3fa md = Lw*cd/wid.pdf;
602 const Vec3fa ms = Lw*cs/wis.pdf;
603 const Vec3fa mt = Lw*ct/wit.pdf;
604
605 const float Cd = wid.pdf == 0.0f ? 0.0f : max(max(md.x,md.y),md.z);
606 const float Cs = wis.pdf == 0.0f ? 0.0f : max(max(ms.x,ms.y),ms.z);
607 const float Ct = wit.pdf == 0.0f ? 0.0f : max(max(mt.x,mt.y),mt.z);
608 const float C = Cd + Cs + Ct;
609
610 if (C == 0.0f) {
611 wi_o = make_Sample3f(Vec3fa(0,0,0),0);
612 return Vec3fa(0,0,0);
613 }
614
615 const float CPd = Cd/C;
616 const float CPs = Cs/C;
617 const float CPt = Ct/C;
618
619 if (s.x < CPd) {
620 wi_o = make_Sample3f(wid.v,wid.pdf*CPd);
621 return cd;
622 }
623 else if (s.x < CPd + CPs)
624 {
625 wi_o = make_Sample3f(wis.v,wis.pdf*CPs);
626 return cs;
627 }
628 else
629 {
630 wi_o = make_Sample3f(wit.v,wit.pdf*CPt);

Callers 1

Material__sampleFunction · 0.85

Calls 11

make_Sample3fFunction · 0.85
cosineSampleHemisphereFunction · 0.85
reflectFunction · 0.85
frameFunction · 0.85
negFunction · 0.85
Vec3faClass · 0.50
maxFunction · 0.50
clampFunction · 0.50
dotFunction · 0.50

Tested by

no test coverage detected