star-sf

Set of surface and volume scattering functions
git clone git://git.meso-star.fr/star-sf.git
Log | Files | Refs | README | LICENSE

commit 1f02ac9a68ef25e76833bb15253da15d98b45b06
parent c2b41c82fcd97a70809fd6cab03a29b618046c8e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  5 Oct 2016 10:48:05 +0200

Comment the built-in BxDFs, Fresnel terms and Microfacet distributions

Diffstat:
Msrc/ssf.h | 83++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------
Msrc/ssf_fresnel_dielectric_dielectric.c | 4+---
2 files changed, 69 insertions(+), 18 deletions(-)

diff --git a/src/ssf.h b/src/ssf.h @@ -143,29 +143,82 @@ SSF_MICROFACET_DISTRIBUTION_TYPE_NULL = SSF_MICROFACET_DISTRIBUTION_TYPE_NULL__; BEGIN_DECLS -/* Reflects the incoming direction with respect to the surface normal */ +/******************************************************************************* + * Built-in BxDFs + ******************************************************************************/ +/* Dirac distribution whose incoming direction `wi' is the reflection of the + * supplied direction `wo' with respect to the surface normal `N'. The + * directional reflectance is controlled by the Fresnel term `Fr'. + * fr(wo, wi) = Fr(|wi.N|) * delta(wo - Reflect(wi, N)) / |wi.N| + * Since it is a dirac distribution, the returned value of the `eval' and `pdf' + * function is always 0 while the pdf returned by `sample' function is + * infinity. */ SSF_API const struct ssf_bxdf_type ssf_specular_reflection; -/* Reflects the same intensity independent of the incoming direction */ + +/* Reflects the same intensity in all direction independently of the incoming + * direction; fr(wo, wr) = R/PI */ SSF_API const struct ssf_bxdf_type ssf_lambertian_reflection; -/* Glossy reflections with respect to a microfacet distribution */ + +/* Glossy reflections with respect to a microfacet distribution. It is based on + * the Torrance Sparrow BRDF to provide a general Microfacet-based BRDF model + * fr(wo, wi) = Fr(|wi.wh|) * G(wo, wi) * D(wh) / (4 * |wo.N| * |wi.N|) + * with `wh' the half vector between `wi' and `wo', `Fr(|wi.wh|)' the Fresnel + * term that controls the directional reflectance, `G(wo, wi)' the geometric + * attenuation term that describes the masking and the shadowing of the + * microfacets and `D(wh)' the distribution area of the microfacets whose + * normal is `wh'. Note that common BRDFs based on this model ignore multiple + * scattering of lights into the microfacet structure and remove them with the + * 'G' term. As a consequence, this model does not satisfy the energy + * conservation property */ SSF_API const struct ssf_bxdf_type ssf_microfacet_reflection; + /* Glossy reflections with respect to a microfacet distribution. In contrast to - * the common microfacet reflection, this BRDF ensures, by design, the energy - * conservation property without requiring the normalization of the BRDF. As a - * counterpart, it only provides the sample function. The others functions - * return invalid value. */ + * the ssp_microfacet_reflection model, this BRDF ensures, by design, the + * energy conservation property without requiring the normalization of the + * BRDF. As a counterpart, it only provides the sample function. The others + * functions return invalid value. However, it is well suited for Monte Carlo + * integrations that only need to sample a direction and to define its + * associated directional reflectance */ SSF_API const struct ssf_bxdf_type ssf_microfacet2_reflection; -/* Fresnel term for perfect reflection */ +/******************************************************************************* + * Built-in Fresnel terms + ******************************************************************************/ +/* Fresnel term for perfect reflection; Fr = 1 */ SSF_API const struct ssf_fresnel_type ssf_fresnel_no_op; -/* Fresnel term between 2 dielectric mediums */ + +/* Fresnel term between 2 dielectric mediums. + * Fr = 1/2 * (Rs^2 + Rp^2) + * with `Rs' and `Rp' the reflectance for the light polarized with its electric + * field perpendicular or parallel to the plane of incidence, respectively. + * Rs = (n1*|wi.N| - n2*|wt.N|) / (n1*|wi.N| + n2*|wt.N) + * Rp = (n2*|wi.N| - n1*|wt.N|) / (n2*|wi.N| + n1*|wt.N) + * with `n1' and `n2' the indices of refraction of the incident and transmitted + * media, and `wi' and `wt' the incident and transmitted direction. */ SSF_API const struct ssf_fresnel_type ssf_fresnel_dielectric_dielectric; -/* Fresnel term between a dielectric and a conductor */ + +/* Fresnel term between a dielectric and a conductor. + * Fr = 1/2 * (Rs^2 + Rp^2) + * with `Rs' and `Rp' the reflectance for the light polarized with its electric + * field perpendicular or parallel to the plane of incidence, respectively. + * Rs = (n1*|wi.N| - (n2 - i*k2)*|wt.N|) / (n1*|wi.N| + (n2 - i*k2)*|wt.N|) + * Rp = ((n2 - i*k2)*|wt.N| - n1*|wi.N|) / ((n2 - i*k2)*|wt.N| + n1*|wi.N|) + * with `n1' the index of refraction of the incident media, `n2' and `k2' the + * real and imaginary part of the index of refraction of the transmitted media, + * and `wi' and `wt' the incident and transmitted direction */ SSF_API const struct ssf_fresnel_type ssf_fresnel_dielectric_conductor; -/* Beckmann microfacet distribution TODO add comments */ +/******************************************************************************* + * Built-in microfacet distributions + ******************************************************************************/ +/* Beckmann microfacet distribution. + * D(wh) = exp(-tan^2(a)/m^2) / (PI*m^2*cos^4(a)) + * with `a' = arccos(wh.N) and `m' the rougness in ]0, 1] of the surface */ SSF_API const struct ssf_microfacet_distribution_type ssf_beckmann_distribution; -/* Blinn microfacet distribution TODO add comments */ + +/* Blinn microfacet distribution. + * D(wh) = (e + 2) / (2*PI) * (wh.N)^e + * with `e' an exponent in [0, SSF_BLINN_DISTRIBUTION_MAX_EXPONENT] */ SSF_API const struct ssf_microfacet_distribution_type ssf_blinn_distribution; /******************************************************************************* @@ -378,9 +431,9 @@ ssf_microfacet_distribution_pdf const double N[3], /* Normalized Z-direction of the distribution */ const double wh[3]); /* Normalized half vector */ -/* Retrieve the internal data of the microfacet distribution term. Usefull for - * user defined distributions on which the caller has to retrieve their data to - * setup their parameters */ +/* Retrieve the internal data of the microfacet distribution. Usefull for user + * defined distributions on which the caller has to retrieve their data to + * setup their parameters. */ SSF_API res_T ssf_microfacet_distribution_get_data (struct ssf_microfacet_distribution* distrib, diff --git a/src/ssf_fresnel_dielectric_dielectric.c b/src/ssf_fresnel_dielectric_dielectric.c @@ -66,14 +66,12 @@ fresnel_dielectric_dielectric_eval(void* fresnel, const double cos_theta_i) * parallel to the plane of incidence */ Rp = (fd->eta_i*cos_theta_t - fd->eta_t*cos_theta_i) / (fd->eta_i*cos_theta_t + fd->eta_t*cos_theta_i); - Rp = fabs(Rp); Rp = Rp * Rp; /* Compute the reflectance for the light polarized with its electric field * perpendicular to the plane of incidence */ Rs = (fd->eta_i*cos_theta_i - fd->eta_t*cos_theta_t) / (fd->eta_i*cos_theta_i + fd->eta_t*cos_theta_t); - Rs = fabs(Rs); Rs = Rs * Rs; return 0.5 * (Rp + Rs); @@ -95,7 +93,7 @@ ssf_fresnel_dielectric_dielectric_setup (struct ssf_fresnel* fresnel, const double eta_i, const double eta_t) { struct fresnel_dielectric_dielectric* fd; - if(!fresnel + if(!fresnel || !FRESNEL_TYPE_EQ(&fresnel->type, &ssf_fresnel_dielectric_dielectric)) { return RES_BAD_ARG; }