Rough Dielectric BSDF
9.7 Rough Dielectric BSDF
We will now extend the microfacet approach from Section 9.6 to the case of rough dielectrics. This involves two notable changes: since dielectrics are characterized by both reflection and transmission, the model must be aware of these two separate components. In the case of transmission, Snell’s law will furthermore replace the law of reflection in the computation that determines the incident direction.
Figure 9.32 shows the dragon rendered with the Torrance–Sparrow model and both reflection and transmission.
Figure 9.32: Dragon models rendered with the Torrance–Sparrow microfacet model featuring both reflection (a) and transmission (b). (Model courtesy of Christian Schüller.)
As before, we will begin by characterizing the probability density of generated samples. The implied BSDF then directly follows from this density and the sequence of events encapsulated by a scattering interaction: visible normal sampling, reflection or refraction, and attenuation by the Fresnel and masking terms.
Rough Dielectric PDF
The density evaluation occurs in the following fragment that we previously omitted during the discussion of the smooth dielectric case.
<>=
<<Compute generalized half vector wm>>
Float cosTheta_o = CosTheta(wo), cosTheta_i = CosTheta(wi); bool reflect = cosTheta_i * cosTheta_o > 0; float etap = 1; if (!reflect) etap = cosTheta_o > 0 ? eta : (1 / eta); Vector3f wm = wi * etap + wo; if (cosTheta_i == 0 || cosTheta_o == 0 || LengthSquared(wm) == 0) return {}; wm = FaceForward(Normalize(wm), Normal3f(0, 0, 1));
<<Discard backfacing microfacets>>
if (Dot(wm, wi) * cosTheta_i < 0 || Dot(wm, wo) * cosTheta_o < 0) return {};
<<Determine Fresnel reflectance of rough dielectric boundary>>
Float R = FrDielectric(Dot(wo, wm), eta); Float T = 1 - R;
<<Compute probabilities pr and pt for sampling reflection and transmission>>
Float pr = R, pt = T; if (!(sampleFlags & BxDFReflTransFlags::Reflection)) pr = 0; if (!(sampleFlags & BxDFReflTransFlags::Transmission)) pt = 0; if (pr == 0 && pt == 0) return {};
<<Return PDF for rough dielectric>>
Float pdf; if (reflect) { <<Compute PDF of rough dielectric reflection>>
pdf = mfDistrib.PDF(wo, wm) / (4 * AbsDot(wo, wm)) * pr / (pr + pt);
} else { <<Compute PDF of rough dielectric transmission>>
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm) / etap); Float dwm_dwi = AbsDot(wi, wm) / denom; pdf = mfDistrib.PDF(wo, wm) * dwm_dwi * pt / (pr + pt);
} return pdf;
We now turn to the generalized half-direction vector, whose discussion requires a closer look at Snell’s law (Equation (9.2)) relating the elevation and azimuth of the incident and outgoing directions at a refractive interface:
Since the refraction takes place at the level of the microgeometry, all of
these angles are to be understood within a coordinate frame aligned with the
microfacet normal . Recall also that the sines in the first equation
refer to the length of the tangential component of
and
perpendicular to
.
A generalized half-direction vector builds on this observation by scaling and adding these directions to cancel out the tangential components, which yields the surface normal responsible for a particular refraction after normalization. It is defined as
(9.34)
where is the relative index of refraction
toward the sampled direction
. The reflective case is trivially subsumed,
since
when no refraction takes place. The next fragment
implements this computation, including handling of invalid configurations (e.g.,
perfectly grazing incidence) where both the BSDF and its sampling density
evaluate to zero.
<>=
Float cosTheta_o = CosTheta(wo), cosTheta_i = CosTheta(wi); bool reflect = cosTheta_i * cosTheta_o > 0; float etap = 1; if (!reflect) etap = cosTheta_o > 0 ? eta : (1 / eta); Vector3f wm = wi * etap + wo; if (cosTheta_i == 0 || cosTheta_o == 0 || LengthSquared(wm) == 0) return {}; wm = FaceForward(Normalize(wm), Normal3f(0, 0, 1));
The last line reflects an important implementation detail: with the previous
definition in Equation (9.34), always
points toward the denser medium, whereas pbrt uses the convention that
micro- and macro-normal are consistently oriented (i.e.,
). In
practice, we therefore compute the following modified half-direction vector,
where
in local coordinates:
(9.35)
Next, microfacets that are backfacing with respect to either the incident or outgoing direction do not contribute and must be discarded.
<>=
if (Dot(wm, wi) * cosTheta_i < 0 || Dot(wm, wo) * cosTheta_o < 0) return {};
Given , we can evaluate the Fresnel reflection and transmission terms
using the specialized dielectric evaluation of the Fresnel equations.
<>=
Float R = FrDielectric(Dot(wo, wm), eta); Float T = 1 - R;
We now have the values necessary to compute the PDF for , which
depends on whether it reflects or transmits at the surface.
<>=
Float pdf; if (reflect) { <<Compute PDF of rough dielectric reflection>>
pdf = mfDistrib.PDF(wo, wm) / (4 * AbsDot(wo, wm)) * pr / (pr + pt);
} else { <<Compute PDF of rough dielectric transmission>>
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm) / etap); Float dwm_dwi = AbsDot(wi, wm) / denom; pdf = mfDistrib.PDF(wo, wm) * dwm_dwi * pt / (pr + pt);
} return pdf;
As before, the bijective mapping between and
provides a change of
variables whose Jacobian determinant is crucial so that we can correctly
deduce the probability density of sampled directions
. The derivation is
more involved in the refractive case; see the “Further Reading” section
for pointers to its derivation. The final determinant is given by
(9.36)
Once more, this relationship makes it possible to evaluate the probability per
unit solid angle of the sampled incident directions obtained through the
combination of visible normal sampling and scattering:
(9.37)
The following fragment implements this computation, while additionally accounting for the discrete probability pt / (pr + pt) of sampling the transmission component.
<>=
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm) / etap); Float dwm_dwi = AbsDot(wi, wm) / denom; pdf = mfDistrib.PDF(wo, wm) * dwm_dwi * pt / (pr + pt);
Finally, the density of the reflection component agrees with the model used for conductors but for the additional discrete probability pr / (pr + pt) of choosing the reflection component.
<>=
pdf = mfDistrib.PDF(wo, wm) / (4 * AbsDot(wo, wm)) * pr / (pr + pt);
Rough Dielectric BSDF
BSDF evaluation is similarly split into reflective and transmissive components.
<>=
<<Compute generalized half vector wm>>
Float cosTheta_o = CosTheta(wo), cosTheta_i = CosTheta(wi); bool reflect = cosTheta_i * cosTheta_o > 0; float etap = 1; if (!reflect) etap = cosTheta_o > 0 ? eta : (1 / eta); Vector3f wm = wi * etap + wo; if (cosTheta_i == 0 || cosTheta_o == 0 || LengthSquared(wm) == 0) return {}; wm = FaceForward(Normalize(wm), Normal3f(0, 0, 1));
<<Discard backfacing microfacets>>
if (Dot(wm, wi) * cosTheta_i < 0 || Dot(wm, wo) * cosTheta_o < 0) return {};
Float F = FrDielectric(Dot(wo, wm), eta); if (reflect) { <<Compute reflection at rough dielectric interface>>
return SampledSpectrum(mfDistrib.D(wm) * mfDistrib.G(wo, wi) * F / std::abs(4 * cosTheta_i * cosTheta_o));
} else { <<Compute transmission at rough dielectric interface>>
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm)/etap) * cosTheta_i * cosTheta_o; Float ft = mfDistrib.D(wm) * (1 - F) * mfDistrib.G(wo, wi) * std::abs(Dot(wi, wm) * Dot(wo, wm) / denom); <<Account for non-symmetry with transmission to different medium>>
if (mode == TransportMode::Radiance) ft /= Sqr(etap);
return SampledSpectrum(ft);
}
The reflection component follows the approach used for conductors in the fragment <<Evaluate rough conductor BRDF>>:
<>=
return SampledSpectrum(mfDistrib.D(wm) * mfDistrib.G(wo, wi) * F / std::abs(4 * cosTheta_i * cosTheta_o));
For the transmission component, we can again derive the effective scattering distribution by equating a single-sample Monte Carlo estimate of the rendering equation with the product of Fresnel transmission, masking, and the incident radiance. This results in the equation
(9.38)
Substituting the PDF from Equation (9.37) and
solving for the BTDF results in
(9.39)
Finally, inserting the definition of the visible normal distribution from
Equation (9.23) and switching to the
more accurate bidirectional masking-shadowing factor yields
(9.40)
The next fragment implements this expression. It also incorporates the earlier orientation test and handling of non-symmetric scattering that was previously encountered in the perfect specular case (Section 9.5.2).
<>=
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm)/etap) * cosTheta_i * cosTheta_o; Float ft = mfDistrib.D(wm) * (1 - F) * mfDistrib.G(wo, wi) * std::abs(Dot(wi, wm) * Dot(wo, wm) / denom); <<Account for non-symmetry with transmission to different medium>>
if (mode == TransportMode::Radiance) ft /= Sqr(etap);
return SampledSpectrum(ft);
Rough Dielectric Sampling
Sampling proceeds by drawing a microfacet normal from the visible normal distribution, computing the Fresnel term, and stochastically selecting between reflection and transmission.
<>=
Vector3f wm = mfDistrib.Sample_wm(wo, u); Float R = FrDielectric(Dot(wo, wm), eta); Float T = 1 - R; <<Compute probabilities pr and pt for sampling reflection and transmission>>
Float pr = R, pt = T; if (!(sampleFlags & BxDFReflTransFlags::Reflection)) pr = 0; if (!(sampleFlags & BxDFReflTransFlags::Transmission)) pt = 0; if (pr == 0 && pt == 0) return {};
Float pdf; if (uc < pr / (pr + pt)) { <<Sample reflection at rough dielectric interface>>
Vector3f wi = Reflect(wo, wm);
if ((wo, wi)) return {};
<<Compute PDF of rough dielectric reflection>>
pdf = mfDistrib.PDF(wo, wm) / (4 * AbsDot(wo, wm)) * pr / (pr + pt);
SampledSpectrum f(mfDistrib.D(wm) * mfDistrib.G(wo, wi) * R / (4 * CosTheta(wi) * CosTheta(wo))); return BSDFSample(f, wi, pdf, BxDFFlags::GlossyReflection);
} else { <<Sample transmission at rough dielectric interface>>
Float etap;
Vector3f wi;
bool tir = (wo, (Normal3f)wm, eta, &etap, &wi);
if (SameHemisphere(wo, wi) || wi.z == 0 || tir)
return {};
<<Compute PDF of rough dielectric transmission>>
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm) / etap); Float dwm_dwi = AbsDot(wi, wm) / denom; pdf = mfDistrib.PDF(wo, wm) * dwm_dwi * pt / (pr + pt);
<<Evaluate BRDF and return BSDFSample for rough transmission>>
SampledSpectrum ft(T * mfDistrib.D(wm) * mfDistrib.G(wo, wi) * std::abs(Dot(wi, wm) * Dot(wo, wm) / (CosTheta(wi) * CosTheta(wo) * denom))); <<Account for non-symmetry with transmission to different medium>>
if (mode == TransportMode::Radiance) ft /= Sqr(etap);
return BSDFSample(ft, wi, pdf, BxDFFlags::GlossyTransmission, etap);
}
Once again, handling of the reflection component is straightforward and mostly matches the case for conductors except for extra factors that arise due to the discrete choice between reflection and transmission components.
<>=
Vector3f wi = Reflect(wo, wm);
if ((wo, wi)) return {};
<<Compute PDF of rough dielectric reflection>>
pdf = mfDistrib.PDF(wo, wm) / (4 * AbsDot(wo, wm)) * pr / (pr + pt);
SampledSpectrum f(mfDistrib.D(wm) * mfDistrib.G(wo, wi) * R / (4 * CosTheta(wi) * CosTheta(wo))); return BSDFSample(f, wi, pdf, BxDFFlags::GlossyReflection);
The transmission case invokes Refract() to determine wi. A subsequent test excludes inconsistencies that can rarely arise due to the approximate nature of floating-point arithmetic. For example, Refract() may sometimes indicate a total internal reflection configuration, which is inconsistent as the transmission component should not have been sampled in this case.
<>=
Float etap;
Vector3f wi;
bool tir = (wo, (Normal3f)wm, eta, &etap, &wi);
if (SameHemisphere(wo, wi) || wi.z == 0 || tir)
return {};
<<Compute PDF of rough dielectric transmission>>
Float denom = Sqr(Dot(wi, wm) + Dot(wo, wm) / etap); Float dwm_dwi = AbsDot(wi, wm) / denom; pdf = mfDistrib.PDF(wo, wm) * dwm_dwi * pt / (pr + pt);
<<Evaluate BRDF and return BSDFSample for rough transmission>>
SampledSpectrum ft(T * mfDistrib.D(wm) * mfDistrib.G(wo, wi) * std::abs(Dot(wi, wm) * Dot(wo, wm) / (CosTheta(wi) * CosTheta(wo) * denom))); <<Account for non-symmetry with transmission to different medium>>
if (mode == TransportMode::Radiance) ft /= Sqr(etap);
return BSDFSample(ft, wi, pdf, BxDFFlags::GlossyTransmission, etap);
The last step evaluates the BTDF from Equation (9.40) and packs the sample information into a BSDFSample.
<>=
SampledSpectrum ft(T * mfDistrib.D(wm) * mfDistrib.G(wo, wi) * std::abs(Dot(wi, wm) * Dot(wo, wm) / (CosTheta(wi) * CosTheta(wo) * denom))); <<Account for non-symmetry with transmission to different medium>>
if (mode == TransportMode::Radiance) ft /= Sqr(etap);
return BSDFSample(ft, wi, pdf, BxDFFlags::GlossyTransmission, etap);