solstice-solver

Solver library of the solstice app
git clone git://git.meso-star.com/solstice-solver.git
Log | Files | Refs | README | LICENSE

commit ad2f1d8fa38c922d196183cf6fc9e767509fb044
parent cfa76bd75b2b7af6a880722c87ebd519dc2dd482
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue,  7 Mar 2017 14:35:59 +0100

Add an the internal material_shade_rendering function

This function setups a BSDF for rendering purposes. Actually, it avoids
to use BRDFs that cannot be evaluated, and thus that cannot be used for
direct lighting.

Diffstat:
Msrc/ssol_draw_pt.c | 4+++-
Msrc/ssol_material.c | 68+++++++++++++++++++++++++++++++++++++++++++++++++-------------------
Msrc/ssol_material_c.h | 9++++++++-
3 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/src/ssol_draw_pt.c b/src/ssol_draw_pt.c @@ -131,6 +131,7 @@ Li float ray_org[3]; float ray_dir[3]; enum ssol_side_flag side; + res_T res = RES_OK; ASSERT(scn && view && org && dir && val); ray_data.scn = scn; @@ -173,7 +174,8 @@ Li surface_fragment_setup(&frag, o, wo, N, &hit.prim, hit.uv); SSF(bsdf_clear(ctx->bsdf)); - CHECK(material_shade(mtl, &frag, 1/*TODO wavelength*/, ctx->bsdf), RES_OK); + res = material_shade_rendering(mtl, &frag, 1/*TODO wavelength*/, ctx->bsdf); + CHECK(res, RES_OK); /* Update the ray */ ray_data.prim_from = hit.prim; diff --git a/src/ssol_material.c b/src/ssol_material.c @@ -78,6 +78,7 @@ mirror_shade (const struct ssol_material* mtl, const struct surface_fragment* fragment, const double wavelength, /* In nanometer */ + const int rendering, struct ssf_bsdf* bsdf) { struct ssf_bxdf* brdf = NULL; @@ -120,8 +121,16 @@ mirror_shade res = ssf_beckmann_distribution_setup(distrib, roughness); if(res != RES_OK) goto error; - res = ssf_bxdf_create - (mtl->dev->allocator, &ssf_microfacet2_reflection, &brdf); + /* Microfacet2 is not well suited for rendering since it cannot be + * evaluated and consequently it returns an invalid result for direct + * lighting. */ + if(rendering) { + res = ssf_bxdf_create + (mtl->dev->allocator, &ssf_microfacet_reflection, &brdf); + } else { + res = ssf_bxdf_create + (mtl->dev->allocator, &ssf_microfacet2_reflection, &brdf); + } if(res != RES_OK) goto error; res = ssf_microfacet_reflection_setup(brdf, fresnel, distrib); if(res != RES_OK) goto error; @@ -189,6 +198,34 @@ error: goto exit; } +static INLINE res_T +shade + (const struct ssol_material* mtl, + const struct surface_fragment* fragment, + const double wavelength, /* In nanometer */ + const int rendering, /* Is material used for rendering */ + struct ssf_bsdf* bsdf) +{ + res_T res = RES_OK; + ASSERT(mtl); + + /* Specific material shading */ + switch(mtl->type) { + case SSOL_MATERIAL_MATTE: + res = matte_shade(mtl, fragment, wavelength, bsdf); + break; + case SSOL_MATERIAL_MIRROR: + res = mirror_shade(mtl, fragment, wavelength, rendering, bsdf); + break; + case SSOL_MATERIAL_THIN_DIELECTRIC: + res = thin_dielectric_shade(mtl, fragment, wavelength, bsdf); + break; + case SSOL_MATERIAL_VIRTUAL: /* Nothing to shade */ break; + default: FATAL("Unreachable code\n"); break; + } + return res; +} + static INLINE int check_shader_mirror(const struct ssol_mirror_shader* shader) { @@ -455,23 +492,16 @@ material_shade const double wavelength, /* In nanometer */ struct ssf_bsdf* bsdf) { - res_T res = RES_OK; - ASSERT(mtl); + return shade(mtl, fragment, wavelength, 0, bsdf); +} - /* Specific material shading */ - switch(mtl->type) { - case SSOL_MATERIAL_MATTE: - res = matte_shade(mtl, fragment, wavelength, bsdf); - break; - case SSOL_MATERIAL_MIRROR: - res = mirror_shade(mtl, fragment, wavelength, bsdf); - break; - case SSOL_MATERIAL_THIN_DIELECTRIC: - res = thin_dielectric_shade(mtl, fragment, wavelength, bsdf); - break; - case SSOL_MATERIAL_VIRTUAL: /* Nothing to shade */ break; - default: FATAL("Unreachable code\n"); break; - } - return res; +res_T +material_shade_rendering + (const struct ssol_material* mtl, + const struct surface_fragment* fragment, + const double wavelength, /* In nanometer */ + struct ssf_bsdf* bsdf) +{ + return shade(mtl, fragment, wavelength, 1, bsdf); } diff --git a/src/ssol_material_c.h b/src/ssol_material_c.h @@ -64,5 +64,12 @@ material_shade const double wavelength, /* In nanometer */ struct ssf_bsdf* bsdf); /* Bidirectional Scattering Distribution Function */ -#endif /* SSOL_MATERIAL_C_H */ +/* Material shading for rendering purposes */ +extern LOCAL_SYM res_T +material_shade_rendering + (const struct ssol_material* mtl, + const struct surface_fragment* fragment, + const double wavelength, /* In nanometer */ + struct ssf_bsdf* bsdf); /* Bidirectional Scattering Distribution Function */ +#endif /* SSOL_MATERIAL_C_H */