solstice-solver

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

ssol_c.h (2543B)


      1 /* Copyright (C) 2018-2026 |Meso|Star> (contact@meso-star.com)
      2  * Copyright (C) 2016, 2018 CNRS
      3  *
      4  * This program is free software: you can redistribute it and/or modify
      5  * it under the terms of the GNU General Public License as published by
      6  * the Free Software Foundation, either version 3 of the License, or
      7  * (at your option) any later version.
      8  *
      9  * This program is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12  * GNU General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU General Public License
     15  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     16 
     17 #ifndef SSOL_C_H
     18 #define SSOL_C_H
     19 
     20 #include "ssol.h"
     21 #include "ssol_instance_c.h"
     22 
     23 #include <rsys/math.h>
     24 #include <star/s3d.h>
     25 
     26 #include <math.h>
     27 
     28 /* Map from SSOL attributes to Star-3D ones */
     29 #define SSOL_TO_S3D_POSITION S3D_POSITION
     30 #define SSOL_TO_S3D_NORMAL S3D_ATTRIB_0
     31 #define SSOL_TO_S3D_TEXCOORD S3D_ATTRIB_1
     32 
     33 /* Data sent to the Star-3D filter function */
     34 struct ray_data {
     35   struct ssol_scene* scn; /* The scene into which the ray is traced */
     36   struct s3d_primitive prim_from; /* Primitive from which the ray starts */
     37   const struct ssol_instance* inst_from; /* Instance from which the ray starts */
     38   const struct shaded_shape* sshape_from; /* Shape from which the ray starts */
     39   enum  ssol_side_flag side_from; /* Primitive side from which the ray starts */
     40   short discard_virtual_materials; /* Define if virtual materials are not RT */
     41   short reversed_ray; /* Define if the ray direction is reversed */
     42   int point_init_closest_point;
     43 
     44   /* Output data */
     45   double N[3]; /* Normal of the nearest punched surface point */
     46   double dst; /* Hit distance of the nearest punched surface point */
     47 };
     48 
     49 static const struct ray_data RAY_DATA_NULL = {
     50   NULL, S3D_PRIMITIVE_NULL__, NULL, NULL, SSOL_INVALID_SIDE, 0, 0, 0,
     51   {0,0,0}, FLT_MAX
     52 };
     53 
     54 
     55 static FINLINE enum s3d_attrib_usage
     56 ssol_to_s3d_attrib_usage(const enum ssol_attrib_usage usage)
     57 {
     58   switch(usage) {
     59     case SSOL_POSITION: return SSOL_TO_S3D_POSITION;
     60     case SSOL_NORMAL: return SSOL_TO_S3D_NORMAL;
     61     case SSOL_TEXCOORD: return SSOL_TO_S3D_TEXCOORD;
     62     default: FATAL("Unreachable code\n"); break;
     63   }
     64 }
     65 
     66 extern LOCAL_SYM int
     67 hit_filter_function
     68   (const struct s3d_hit* hit,
     69    const float org[3],
     70    const float dir[3],
     71    const float range[2],
     72    void* realisation,
     73    void* filter_data);
     74 
     75 #endif /* SSOL_C_H */
     76