1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 /** \file
18  * \ingroup DNA
19  */
20 
21 #pragma once
22 
23 #include "DNA_ID.h"
24 #include "DNA_defs.h"
25 #include "DNA_listBase.h"
26 
27 #include "BLI_assert.h"
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 struct AnimData;
34 struct Object;
35 
36 typedef struct LightProbe {
37   ID id;
38   /** Animation data (must be immediately after id for utilities to use it). */
39   struct AnimData *adt;
40 
41   /** For realtime probe objects. */
42   char type;
43   /** General purpose flags for probes. */
44   char flag;
45   /** Attenuation type. */
46   char attenuation_type;
47   /** Parallax type. */
48   char parallax_type;
49 
50   /** Influence Radius. */
51   float distinf;
52   /** Parallax Radius. */
53   float distpar;
54   /** Influence falloff. */
55   float falloff;
56 
57   float clipsta, clipend;
58 
59   /** VSM visibility biases. */
60   float vis_bias, vis_bleedbias;
61   float vis_blur;
62 
63   /** Intensity multiplier. */
64   float intensity;
65 
66   /** Irradiance grid resolution. */
67   int grid_resolution_x;
68   int grid_resolution_y;
69   int grid_resolution_z;
70   char _pad1[4];
71 
72   /** Object to use as a parallax origin. */
73   struct Object *parallax_ob;
74   /** Image to use on as lighting data. */
75   struct Image *image;
76   /** Object visibility group, inclusive or exclusive. */
77   struct Collection *visibility_grp;
78 
79   /* Runtime display data */
80   float distfalloff, distgridinf;
81   char _pad[8];
82 } LightProbe;
83 
84 /* Probe->type */
85 enum {
86   LIGHTPROBE_TYPE_CUBE = 0,
87   LIGHTPROBE_TYPE_PLANAR = 1,
88   LIGHTPROBE_TYPE_GRID = 2,
89 };
90 
91 /* Probe->flag */
92 enum {
93   LIGHTPROBE_FLAG_CUSTOM_PARALLAX = (1 << 0),
94   LIGHTPROBE_FLAG_SHOW_INFLUENCE = (1 << 1),
95   LIGHTPROBE_FLAG_SHOW_PARALLAX = (1 << 2),
96   LIGHTPROBE_FLAG_SHOW_CLIP_DIST = (1 << 3),
97   LIGHTPROBE_FLAG_SHOW_DATA = (1 << 4),
98   LIGHTPROBE_FLAG_INVERT_GROUP = (1 << 5),
99 };
100 
101 /* Probe->display */
102 enum {
103   LIGHTPROBE_DISP_WIRE = 0,
104   LIGHTPROBE_DISP_SHADED = 1,
105   LIGHTPROBE_DISP_DIFFUSE = 2,
106   LIGHTPROBE_DISP_REFLECTIVE = 3,
107 };
108 
109 /* Probe->parallax && Probe->attenuation_type*/
110 enum {
111   LIGHTPROBE_SHAPE_ELIPSOID = 0,
112   LIGHTPROBE_SHAPE_BOX = 1,
113 };
114 
115 /* ------- Eevee LightProbes ------- */
116 /* Needs to be there because written to file with the light-cache. */
117 
118 /* IMPORTANT Padding in these structs is essential. It must match
119  * GLSL struct definition in lightprobe_lib.glsl. */
120 
121 /* Must match CubeData. */
122 typedef struct LightProbeCache {
123   float position[3], parallax_type;
124   float attenuation_fac;
125   float attenuation_type;
126   float _pad3[2];
127   float attenuationmat[4][4];
128   float parallaxmat[4][4];
129 } LightProbeCache;
130 
131 /* Must match GridData. */
132 typedef struct LightGridCache {
133   float mat[4][4];
134   /** Offset to the first irradiance sample in the pool. */
135   int resolution[3], offset;
136   float corner[3], attenuation_scale;
137   /** World space vector between 2 opposite cells. */
138   float increment_x[3], attenuation_bias;
139   float increment_y[3], level_bias;
140   float increment_z[3], _pad4;
141   float visibility_bias, visibility_bleed, visibility_range, _pad5;
142 } LightGridCache;
143 
144 /* These are used as ubo data. They need to be aligned to size of vec4. */
145 BLI_STATIC_ASSERT_ALIGN(LightProbeCache, 16)
146 BLI_STATIC_ASSERT_ALIGN(LightGridCache, 16)
147 
148 /* ------ Eevee Lightcache ------- */
149 
150 typedef struct LightCacheTexture {
151   struct GPUTexture *tex;
152   /** Copy of GPU datas to create GPUTextures on file read. */
153   char *data;
154   int tex_size[3];
155   char data_type;
156   char components;
157   char _pad[2];
158 } LightCacheTexture;
159 
160 typedef struct LightCache {
161   int flag;
162   /** Version number to know if the cache data is compatible with this version of blender. */
163   int version;
164   /** Type of data this cache contains. */
165   int type;
166   /* only a single cache for now */
167   /** Number of probes to use for rendering. */
168   int cube_len, grid_len;
169   /** Number of mipmap level to use. */
170   int mips_len;
171   /** Size of a visibility/reflection sample. */
172   int vis_res, ref_res;
173   char _pad[4][2];
174   /* In the future, we could create a bigger texture containing
175    * multiple caches (for animation) and interpolate between the
176    * caches overtime to another texture. */
177   LightCacheTexture grid_tx;
178   /** Contains data for mipmap level 0. */
179   LightCacheTexture cube_tx;
180   /** Does not contains valid GPUTexture, only data. */
181   LightCacheTexture *cube_mips;
182   /* All lightprobes data contained in the cache. */
183   LightProbeCache *cube_data;
184   LightGridCache *grid_data;
185 } LightCache;
186 
187 /* Bump the version number for lightcache data structure changes. */
188 #define LIGHTCACHE_STATIC_VERSION 1
189 
190 /* LightCache->type */
191 enum {
192   LIGHTCACHE_TYPE_STATIC = 0,
193 };
194 
195 /* LightCache->flag */
196 enum {
197   LIGHTCACHE_BAKED = (1 << 0),
198   LIGHTCACHE_BAKING = (1 << 1),
199   LIGHTCACHE_CUBE_READY = (1 << 2),
200   LIGHTCACHE_GRID_READY = (1 << 3),
201   /* Update tagging */
202   LIGHTCACHE_UPDATE_CUBE = (1 << 4),
203   LIGHTCACHE_UPDATE_GRID = (1 << 5),
204   LIGHTCACHE_UPDATE_WORLD = (1 << 6),
205   LIGHTCACHE_UPDATE_AUTO = (1 << 7),
206   /** Invalid means we tried to alloc it but failed. */
207   LIGHTCACHE_INVALID = (1 << 8),
208   /** The data present in the cache is valid but unusable on this GPU. */
209   LIGHTCACHE_NOT_USABLE = (1 << 9),
210 };
211 
212 /* EEVEE_LightCacheTexture->data_type */
213 enum {
214   LIGHTCACHETEX_BYTE = (1 << 0),
215   LIGHTCACHETEX_FLOAT = (1 << 1),
216   LIGHTCACHETEX_UINT = (1 << 2),
217 };
218 
219 #ifdef __cplusplus
220 }
221 #endif
222