LCOV - code coverage report
Current view: top level - engine/render - radiancehints.h (source / functions) Coverage Total Hit
Test: Libprimis Test Coverage Lines: 100.0 % 6 6
Test Date: 2026-10-21 06:30:36 Functions: 100.0 % 3 3

            Line data    Source code
       1              : #ifndef RADIANCEHINTS_H_
       2              : #define RADIANCEHINTS_H_
       3              : 
       4              : //note that radiance hints is the term for the mechanism by which global illumination is done
       5              : constexpr int rhmaxsplits = 4; //maximum number of times that radiance hints can split to increase resolution (note exponential increase in nodes)
       6              : 
       7              : extern int rhsplits;
       8              : extern int gi, gidist;
       9              : extern float giscale, giaoscale;
      10              : extern int debugrsm, debugrh;
      11              : extern std::array<GLuint, 8> rhtex;
      12              : extern Shader *rsmworldshader;
      13              : extern int rsmcull;
      14              : extern GLuint rhfbo;
      15              : 
      16              : /**
      17              :  * @brief reflective shadow map object
      18              :  *
      19              :  * defines the size, position & projection info for a reflective shadow map
      20              :  * the reflective shadow map is then used to calculate global illumination
      21              :  */
      22              : class ReflectiveShadowMap final
      23              : {
      24              :     public:
      25              :         std::array<plane, 4> cull;
      26              :         matrix4 model, proj;
      27              :         vec lightview;
      28              :         vec scale, offset;
      29              :         void setup();
      30              :     private:
      31              :         vec center, bounds;
      32              :         /**
      33              :          * @brief Sets the RSM matrix to sunlight direction
      34              :          *
      35              :          * Sets the reflectiveshadowmap's model to the global viewmatrix, then
      36              :          * points it to be oriented like the sun.
      37              :          */
      38              :         void calcmodelmatrix();
      39              :         void calcprojmatrix();
      40              :         void gencullplanes();
      41              : };
      42              : 
      43              : extern ReflectiveShadowMap rsm;
      44              : 
      45              : class RadianceHints final
      46              : {
      47              :     public:
      48            1 :         RadianceHints() : dynmin(1e16f, 1e16f, 1e16f), dynmax(-1e16f, -1e16f, -1e16f), prevdynmin(1e16f, 1e16f, 1e16f), prevdynmax(-1e16f, -1e16f, -1e16f) {}
      49              : 
      50              :         vec dynmin, dynmax;
      51              :         void setup();
      52              :         void renderslices();
      53              :         void bindparams() const;
      54              : 
      55              :         /**
      56              :          * @brief Clears the cache for each radiance hints split.
      57              :          *
      58              :          * This resets the boundary to an arbitrarily large negative value for each split.
      59              :          */
      60              :         void clearcache();
      61              : 
      62              :         /**
      63              :          * @brief Checks that every split has a cached value.
      64              :          *
      65              :          * This will return false if any split has mismached cached/center fields.
      66              :          *
      67              :          * @return true if all splits are cached
      68              :          */
      69              :         bool allcached() const;
      70              : 
      71              :         /**
      72              :          * @brief Rotates out dynmin/max to prevdynmin/max.
      73              :          *
      74              :          * The values of dynmin/max and prevdynmin/max are both equal to the previous
      75              :          * value of dynmin/max after this function is called. The previous value in
      76              :          * prevdynmin/max is deleted.
      77              :          */
      78              :         void rotatedynlimits();
      79              :         /**
      80              :          * @brief Checks if prevmin's z value is less than prevmax.
      81              :          *
      82              :          * @return true if the min value is less than the max value
      83              :          */
      84              :         bool checkprevbounds() const;
      85              :     private:
      86              :         vec prevdynmin, prevdynmax;
      87              :         //splits are used to LOD global illumination (more detail near camera)
      88              :         struct SplitInfo final
      89              :         {
      90              :             float nearplane, farplane;
      91              :             vec offset, scale;
      92              :             vec center;
      93              :             float bounds;
      94              :             vec cached;
      95              :             bool copied;
      96              : 
      97            4 :             SplitInfo() : center(-1e16f, -1e16f, -1e16f), bounds(-1e16f), cached(-1e16f, -1e16f, -1e16f), copied(false)
      98              :             {
      99            4 :             }
     100              : 
     101            4 :             void clearcache()
     102              :             {
     103            4 :                 bounds = -1e16f;
     104            4 :             }
     105              :         };
     106              :         std::array<SplitInfo, rhmaxsplits> splits;
     107              : 
     108              :         /**
     109              :          * @brief Recalculates the near and farplane split locations.
     110              :          *
     111              :          * Applies for each split in this radiance hints object. The farplane of a near split
     112              :          * is set to align with the nearplane of the next farthest object.
     113              :          */
     114              :         void updatesplitdist();
     115              : };
     116              : 
     117              : extern RadianceHints rh;
     118              : 
     119              : extern void clearradiancehintscache();
     120              : extern bool useradiancehints();
     121              : extern void setupradiancehints();
     122              : extern void cleanupradiancehints();
     123              : 
     124              : extern void viewrh();
     125              : extern void viewrsm();
     126              : 
     127              : #endif
        

Generated by: LCOV version 2.0-1