solstice

Compute collected power and efficiencies of a solar plant
git clone git://git.meso-star.com/solstice.git
Log | Files | Refs | README | LICENSE

commit 0590aa04f3b95ec25e4c81546448fb2c63d47ec1
parent 450a4545be809f1c2550bbdc0d0ce56de50563fe
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Tue, 12 Dec 2017 11:12:55 +0100

Add the ufacet_distrib attrib to the Solparser mirror

This enumerable defines the type of the microfacet distribution to use
when the mirror 'roughness' is not 0.

Diffstat:
Msrc/parser/solparser_material.c | 39+++++++++++++++++++++++++++++++++++++--
Msrc/parser/solparser_material.h | 10+++++++++-
2 files changed, 46 insertions(+), 3 deletions(-)

diff --git a/src/parser/solparser_material.c b/src/parser/solparser_material.c @@ -22,6 +22,38 @@ * Helper functions ******************************************************************************/ static res_T +parse_microfacet + (struct solparser* parser, + const yaml_node_t* microfacet, + enum solparser_microfacet_distribution* distrib) +{ + res_T res = RES_OK; + ASSERT(doc && microfacet && distrib); + + if(microfacet->type != YAML_SCALAR_NODE) { + log_err(parser, microfacet, + "expect the name of a microfacet distribution.\n"); + res = RES_BAD_ARG; + goto error; + } + + if(!strcmp((char*)microfacet->data.scalar.value, "BECKMANN")) { + *distrib = SOLPARSER_MICROFACET_BECKMANN; + } else if(!strcmp((char*)microfacet->data.scalar.value, "PILLBOX")) { + *distrib = SOLPARSER_MICROFACET_PILLBOX; + } else { + log_err(parser, microfacet, "unknown microfacet distribution `%s'.\n", + microfacet->data.scalar.value); + res = RES_BAD_ARG; + goto error; + } +exit: + return res; +error: + goto exit; +} + +static res_T parse_material_dielectric (struct solparser* parser, yaml_document_t* doc, @@ -213,7 +245,7 @@ parse_material_mirror const yaml_node_t* mirror, struct solparser_material_mirror_id* out_imtl) { - enum { NORMAL_MAP, REFLECTIVITY, ROUGHNESS }; + enum { MICROFACET, NORMAL_MAP, REFLECTIVITY, ROUGHNESS }; struct solparser_material_mirror* mtl = NULL; size_t imtl = SIZE_MAX; int mask = 0; /* Register the parsed attributes */ @@ -259,7 +291,10 @@ parse_material_mirror } \ mask |= BIT(Flag); \ } (void)0 - if(!strcmp((char*)key->data.scalar.value, "normal_map")) { + if(!strcmp((char*)key->data.scalar.value, "microfacet")) { + SETUP_MASK(MICROFACET, "microfacet"); + res = parse_microfacet(parser, val, &mtl->ufacet_distrib); + } else if(!strcmp((char*)key->data.scalar.value, "normal_map")) { SETUP_MASK(NORMAL_MAP, "normal_map"); res = parse_image(parser, doc, val, &mtl->normal_map); } else if(!strcmp((char*)key->data.scalar.value, "reflectivity")) { diff --git a/src/parser/solparser_material.h b/src/parser/solparser_material.h @@ -28,12 +28,16 @@ enum solparser_material_type { SOLPARSER_MATERIAL_VIRTUAL }; +enum solparser_microfacet_distribution { + SOLPARSER_MICROFACET_BECKMANN, + SOLPARSER_MICROFACET_PILLBOX +}; + struct solparser_material_dielectric { struct solparser_medium_id medium_i; /* Medium the material "looks at" */ struct solparser_medium_id medium_t; /* Opposite medium */ struct solparser_image_id normal_map; }; - struct solparser_material_dielectric_id { size_t i; }; static INLINE void @@ -66,6 +70,7 @@ solparser_material_matte_init struct solparser_material_mirror { struct solparser_mtl_data roughness; /* In [0, 1] */ struct solparser_mtl_data reflectivity; /* In [0, 1] */ + enum solparser_microfacet_distribution ufacet_distrib; struct solparser_image_id normal_map; }; @@ -78,6 +83,9 @@ solparser_material_mirror_init { ASSERT(mirror); (void)allocator; + mirror->roughness.type = SOLPARSER_MTL_DATA_REAL; + mirror->roughness.value.real = 0; + mirror->ufacet_distrib = SOLPARSER_MICROFACET_BECKMANN; mirror->normal_map.i = SIZE_MAX; }