solstice-solver

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

commit d0769c99b95f72271fbd28809e376f3e8213f23c
parent 185ab546e06fcd534d8ff66db695eb713b6c3ebc
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu,  6 Apr 2017 11:05:08 +0200

Update the shader API

Make public the surface fragment data structure and provide it to the
shaders.

Diffstat:
Msrc/ssol.h | 19+++++++++++++------
Msrc/ssol_draw_draft.c | 2+-
Msrc/ssol_draw_pt.c | 2+-
Msrc/ssol_material.c | 43+++++++++++++++++++------------------------
Msrc/ssol_material_c.h | 17+++--------------
Msrc/ssol_solver.c | 2+-
Msrc/test_ssol_materials.h | 64+++++++++++++++-------------------------------------------------
7 files changed, 53 insertions(+), 96 deletions(-)

diff --git a/src/ssol.h b/src/ssol.h @@ -239,16 +239,23 @@ struct ssol_medium { #define SSOL_MEDIUM_VACUUM__ { 0, 1 } static const struct ssol_medium SSOL_MEDIUM_VACUUM = SSOL_MEDIUM_VACUUM__; +struct ssol_surface_fragment { + double dir[3]; /* World space incoming direction. Point outward the surface */ + double pos[3]; /* World space position */ + double Ng[3]; /* Normalized world space geometry normal */ + double Ns[3]; /* Normalized world space shading normal */ + double uv[2]; /* Texture coordinates */ +}; +#define SSOL_SURFACE_FRAGMENT_NULL__ {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0}} +static const struct ssol_surface_fragment SSOL_SURFACE_FRAGMENT_NULL = + SSOL_SURFACE_FRAGMENT_NULL__; + typedef void (*ssol_shader_getter_T) (struct ssol_device* dev, struct ssol_param_buffer* buf, - const double wavelength, /* In nanometer */ - const double P[3], /* World space position */ - const double Ng[3], /* World space geometry normal */ - const double Ns[3], /* World space shading normal */ - const double uv[2], /* Texture coordinates */ - const double w[3], /* Incoming direction. Point toward the surface */ + const double wavelength, + const struct ssol_surface_fragment* fragment, double* val); /* Returned value */ /* Dielectric material shader */ diff --git a/src/ssol_draw_draft.c b/src/ssol_draw_draft.c @@ -42,7 +42,7 @@ Li double val[3]) { const float range[2] = {0, FLT_MAX}; - struct surface_fragment frag; + struct ssol_surface_fragment frag; struct ray_data ray_data = RAY_DATA_NULL; struct s3d_hit hit; ASSERT(scn && view && org && dir && val); diff --git a/src/ssol_draw_pt.c b/src/ssol_draw_pt.c @@ -135,7 +135,7 @@ Li(struct ssol_scene* scn, struct ssol_instance* inst; struct ssol_material* mtl; const struct shaded_shape* sshape; - struct surface_fragment frag; + struct ssol_surface_fragment frag; size_t isshape; double throughput = 1.0; double wi[3], o[3], uv[3]; diff --git a/src/ssol_material.c b/src/ssol_material.c @@ -37,23 +37,19 @@ static void shade_normal_default (struct ssol_device* dev, struct ssol_param_buffer* buf, - const double wavelength, /* In nanometer */ - const double P[3], /* World space position */ - const double Ng[3], /* World space geometry normal */ - const double Ns[3], /* World space shading normal */ - const double uv[2], /* Texture coordinates */ - const double w[3], /* Incoming direction. Point toward the surface */ + const double wlen, + const struct ssol_surface_fragment* frag, double* val) /* Returned value */ { - (void)dev, (void)buf, (void)wavelength, (void)P, (void)Ng, (void)Ns, (void)uv; - (void)w; - d3_set(val, Ns); + ASSERT(frag && val); + (void)dev, (void)buf, (void)wlen; + d3_set(val, frag->Ns); } static res_T setup_dielectric_bsdf (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, /* In nanometer */ const struct ssol_medium* medium, struct ssf_bsdf* bsdf) @@ -103,7 +99,7 @@ error: static res_T setup_matte_bsdf (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, /* In nanometer */ struct ssf_bsdf* bsdf) { @@ -114,8 +110,8 @@ setup_matte_bsdf ASSERT(bsdf); /* Fetch material attribs */ - mtl->data.matte.reflectivity(mtl->dev, mtl->buf, wavelength, fragment->pos, - fragment->Ng, fragment->Ns, fragment->uv, fragment->dir, &reflectivity); + mtl->data.matte.reflectivity + (mtl->dev, mtl->buf, wavelength, fragment, &reflectivity); /* Setup the BRDF */ res = ssf_bxdf_create(mtl->dev->allocator, &ssf_lambertian_reflection, &brdf); @@ -137,7 +133,7 @@ error: static res_T setup_mirror_bsdf (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, /* In nanometer */ const int rendering, struct ssf_bsdf* bsdf) @@ -152,10 +148,10 @@ setup_mirror_bsdf ASSERT(bsdf); /* Fetch material attribs */ - mtl->data.mirror.reflectivity(mtl->dev, mtl->buf, wavelength, fragment->pos, - fragment->Ng, fragment->Ns, fragment->uv, fragment->dir, &reflectivity); - mtl->data.mirror.roughness(mtl->dev, mtl->buf, wavelength, fragment->pos, - fragment->Ng, fragment->Ns, fragment->uv, fragment->dir, &roughness); + mtl->data.mirror.reflectivity + (mtl->dev, mtl->buf, wavelength, fragment, &reflectivity); + mtl->data.mirror.roughness + (mtl->dev, mtl->buf, wavelength, fragment, &roughness); /* Setup the fresnel term */ res = ssf_fresnel_create(mtl->dev->allocator, &ssf_fresnel_constant, &fresnel); @@ -207,7 +203,7 @@ error: static res_T setup_thin_dielectric_bsdf (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, /* In nanometer */ struct ssf_bsdf* bsdf) { @@ -490,7 +486,7 @@ ssol_material_create_virtual ******************************************************************************/ void surface_fragment_setup - (struct surface_fragment* fragment, + (struct ssol_surface_fragment* fragment, const double pos[3], const double dir[3], const double normal[3], @@ -560,19 +556,18 @@ surface_fragment_setup void material_shade_normal (const struct ssol_material* mtl, - const struct surface_fragment* frag, + const struct ssol_surface_fragment* frag, const double wavelength, double N[3]) { ASSERT(mtl && frag && N); - mtl->normal(mtl->dev, mtl->buf, wavelength, frag->pos, frag->Ng, frag->Ns, - frag->uv, frag->dir, N); + mtl->normal(mtl->dev, mtl->buf, wavelength, frag, N); } res_T material_setup_bsdf (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, /* In nanometer */ const struct ssol_medium* medium, const int rendering, /* Is BSDF used for rendering */ diff --git a/src/ssol_material_c.h b/src/ssol_material_c.h @@ -27,17 +27,6 @@ struct ssol_device; ( ((A)->refractive_index == (B)->refractive_index) \ && ((A)->absorptivity == (B)->absorptivity)) -struct surface_fragment { - double dir[3]; /* World space incoming direction */ - double pos[3]; /* World space position */ - double Ng[3]; /* Normalized world space primitive normal */ - double Ns[3]; /* Normalized world space shading normal */ - double uv[2]; /* Texture coordinates */ -}; -#define SURFACE_FRAGMENT_NULL__ {{0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0}} -static const struct surface_fragment SURFACE_FRAGMENT_NULL = - SURFACE_FRAGMENT_NULL__; - struct dielectric { int dummy; }; @@ -78,7 +67,7 @@ struct ssol_material { extern LOCAL_SYM void surface_fragment_setup - (struct surface_fragment* fragment, + (struct ssol_surface_fragment* fragment, const double pos[3], const double dir[3], const double normal[3], @@ -88,14 +77,14 @@ surface_fragment_setup extern LOCAL_SYM void material_shade_normal (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, double N[3]); extern LOCAL_SYM res_T material_setup_bsdf (const struct ssol_material* mtl, - const struct surface_fragment* fragment, + const struct ssol_surface_fragment* fragment, const double wavelength, /* In nanometer */ const struct ssol_medium* medium, /* Current medium */ const int rendering, /* Is material used for rendering purposes */ diff --git a/src/ssol_solver.c b/src/ssol_solver.c @@ -355,7 +355,7 @@ point_shade double dir[3]) { struct ssol_material* mtl; - struct surface_fragment frag; + struct ssol_surface_fragment frag; double r = 1; double wi[3], pdf; int type; diff --git a/src/test_ssol_materials.h b/src/test_ssol_materials.h @@ -25,16 +25,12 @@ get_shader_normal (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { int i; - (void)dev, (void)buf, (void)wavelength, (void)P, (void)Ng, (void)uv, (void)w; - FOR_EACH(i, 0, 3) val[i] = Ns[i]; + (void)dev, (void)buf, (void)wavelength; + FOR_EACH(i, 0, 3) val[i] = frag->Ns[i]; } static INLINE void @@ -42,15 +38,10 @@ get_shader_reflectivity (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { - (void)dev, (void)buf, (void)wavelength; - (void)P, (void)Ng, (void)Ns, (void)uv, (void) w; + (void)dev, (void)buf, (void)wavelength, (void)frag; *val = 1; } @@ -60,15 +51,10 @@ get_shader_reflectivity_2 (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { - (void) dev, (void) buf, (void) wavelength; - (void) P, (void) Ng, (void) Ns, (void) uv, (void) w; + (void)dev, (void)buf, (void)wavelength, (void)frag; *val = REFLECTIVITY; } #endif @@ -78,15 +64,10 @@ get_shader_roughness (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { - (void)dev, (void)buf, (void)wavelength; - (void)P, (void)Ng, (void)Ns, (void)uv, (void) w; + (void)dev, (void)buf, (void)wavelength, (void)frag; *val = 0; } @@ -95,15 +76,10 @@ get_shader_absorption (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { - (void)dev, (void)buf, (void)wavelength; - (void)P, (void)Ng, (void)Ns, (void)uv, (void) w; + (void)dev, (void)buf, (void)wavelength, (void)frag; *val = 0; } @@ -112,15 +88,10 @@ get_shader_thickness (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { - (void)dev, (void)buf, (void)wavelength; - (void)P, (void)Ng, (void)Ns, (void)uv, (void) w; + (void)dev, (void)buf, (void)wavelength, (void)frag; *val = 1; } @@ -129,15 +100,10 @@ get_shader_refractive_index (struct ssol_device* dev, struct ssol_param_buffer* buf, const double wavelength, - const double P[3], - const double Ng[3], - const double Ns[3], - const double uv[2], - const double w[3], + const struct ssol_surface_fragment* frag, double* val) { - (void)dev, (void)buf, (void)wavelength; - (void)P, (void)Ng, (void)Ns, (void)uv, (void) w; + (void)dev, (void)buf, (void)wavelength, (void)frag; *val = 1.5; }