public override float Sample(Surfel surfel, out Vector3 wi, Vector2 sample, out float pdf) { var wo = surfel.ray; var entering = Vector3.Dot(wo, surfel.normal) < 0; var etaI = entering ? etaA : etaB; var etaT = entering ? etaB : etaA; var eta = etaI / etaT; var n = Vector3Extensions.Faceforward(surfel.normal, wo); if (!wo.Refract(n, eta, out wi)) { pdf = 0; return(0); } pdf = 1; var cos = Vector3.Dot(wi, surfel.normal); var ft = t * (1 - fresnel.Evaluate(cos)); if (mode == TransportMode.Radiance) { ft *= (etaI * etaI) / (etaT * etaT); } return(ft / Math.Abs(cos)); }
public override float Sample(Surfel surfel, out Vector3 wi, Vector2 sample, out float pdf) { float res; var f = fresnel.Evaluate(Vector3.Dot(surfel.normal, surfel.ray)); if (sample.X < f) { res = reflection.Sample(surfel, out wi, sample, out pdf); pdf = f; } else { res = transmission.Sample(surfel, out wi, sample, out pdf); pdf = 1 - f; } return(res); }