star-gs

Literate program for a geometric sensitivity calculation
git clone git://git.meso-star.fr/star-gs.git
Log | Files | Refs | README | LICENSE

commit 50aef149568be0cf7583097bea7bf08a7c61e0a4
parent 9b0fd6fd923b31d78a6d31dc65d1776db546de7e
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon, 26 Apr 2021 22:06:43 +0200

Add the sgs_geometry_sample function

Diffstat:
Msrc/sgs_geometry.c | 34++++++++++++++++++++++++++++++++++
Msrc/sgs_geometry.h | 10+++++++++-
2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/src/sgs_geometry.c b/src/sgs_geometry.c @@ -23,6 +23,7 @@ #include "sgs_log.h" #include <star/s3d.h> +#include <star/ssp.h> #include <rsys/cstr.h> #include <rsys/float2.h> @@ -270,6 +271,39 @@ sgs_geometry_trace_ray } } +extern LOCAL_SYM void +sgs_geometry_sample + (const struct sgs_geometry* geom, + struct ssp_rng* rng, + struct sgs_fragment* frag) +{ + struct s3d_primitive prim = S3D_PRIMITIVE_NULL; + struct s3d_attrib position; + struct s3d_attrib normal; + float r0, r1, r2; + float st[2]; + ASSERT(geom && rng && frag); + + /* Sample the geometry */ + r0 = ssp_rng_canonical_float(rng); + r1 = ssp_rng_canonical_float(rng); + r2 = ssp_rng_canonical_float(rng); + S3D(scene_view_sample(geom->view_sp, r0, r1, r2, &prim, st)); + + /* Retrieve sampling point attributes */ + S3D(primitive_get_attrib(&prim, S3D_POSITION, st, &position)); + S3D(primitive_get_attrib(&prim, S3D_GEOMETRY_NORMAL, st, &normal)); + + /* Setup the output variable */ + d3_set_f3(frag->position, position.value); + d3_set_f3(frag->normal, normal.value); + d3_normalize(frag->normal, frag->normal); + frag->surface_type = darray_int_cdata_get(&geom->tris_type)[prim.prim_id]; + frag->s3d_pos.prim = prim; + frag->s3d_pos.st[0] = st[0]; + frag->s3d_pos.st[1] = st[1]; +} + res_T sgs_geometry_dump_vtk(const struct sgs_geometry* geom, FILE* stream) { diff --git a/src/sgs_geometry.h b/src/sgs_geometry.h @@ -152,9 +152,9 @@ static const struct sgs_hit SGS_HIT_NULL = SGS_HIT_NULL__; #define SGS_HIT_NONE(Hit) ((Hit)->distance >= FLT_MAX) /* Forward declaration */ -struct s3d_hit; struct sgs; struct sgs_geometry; +struct ssp_rng; /******************************************************************************* * Geometry API @@ -194,6 +194,14 @@ sgs_geometry_trace_ray const struct sgs_s3d_position* pos_from, /* To avoid self hit. May be NULL */ struct sgs_hit* hit); +/* Uniformly sample a point onto the faces of the geometry defined in the + * sampling_mask on geometry creation */ +extern LOCAL_SYM void +sgs_geometry_sample + (const struct sgs_geometry* geom, + struct ssp_rng* rng, + struct sgs_fragment* frag); + extern LOCAL_SYM res_T sgs_geometry_dump_vtk (const struct sgs_geometry* geom,