1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
/*
* Copyright 2016, Blender Foundation.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Contributor(s): Blender Institute
*
*/
/** \file eevee_private.h
* \ingroup DNA
*/
struct Object;
/* Minimum UBO is 16384 bytes */
#define MAX_LIGHT 128 /* TODO : find size by dividing UBO max size by light data size */
#define MAX_SHADOW_CUBE 42 /* TODO : Make this depends on GL_MAX_ARRAY_TEXTURE_LAYERS */
#define MAX_SHADOW_MAP 64
#define MAX_SHADOW_CASCADE 8
#define MAX_CASCADE_NUM 4
typedef struct EEVEE_PassList {
/* Shadows */
struct DRWPass *shadow_pass;
struct DRWPass *shadow_cube_pass;
struct DRWPass *shadow_cascade_pass;
/* Probes */
struct DRWPass *probe_background;
struct DRWPass *probe_prefilter;
struct DRWPass *probe_sh_compute;
struct DRWPass *depth_pass;
struct DRWPass *depth_pass_cull;
struct DRWPass *default_pass;
struct DRWPass *material_pass;
struct DRWPass *tonemap;
} EEVEE_PassList;
typedef struct EEVEE_FramebufferList {
/* Shadows */
struct GPUFrameBuffer *shadow_cube_fb;
struct GPUFrameBuffer *shadow_map_fb;
struct GPUFrameBuffer *shadow_cascade_fb;
/* Probes */
struct GPUFrameBuffer *probe_fb;
struct GPUFrameBuffer *probe_filter_fb;
struct GPUFrameBuffer *probe_sh_fb;
struct GPUFrameBuffer *main; /* HDR */
} EEVEE_FramebufferList;
typedef struct EEVEE_TextureList {
/* Shadows */
struct GPUTexture *shadow_depth_cube_pool;
struct GPUTexture *shadow_depth_map_pool;
struct GPUTexture *shadow_depth_cascade_pool;
/* Probes */
struct GPUTexture *probe_rt; /* R16_G16_B16 */
struct GPUTexture *probe_depth_rt;
struct GPUTexture *probe_pool; /* R11_G11_B10 */
struct GPUTexture *probe_sh; /* R16_G16_B16 */
struct GPUTexture *color; /* R16_G16_B16 */
} EEVEE_TextureList;
typedef struct EEVEE_StorageList {
/* Lamps */
/* XXX this should be per-scenelayer and not per_viewport */
struct EEVEE_LampsInfo *lamps;
struct GPUUniformBuffer *light_ubo;
struct GPUUniformBuffer *shadow_ubo;
struct GPUUniformBuffer *shadow_render_ubo;
/* Probes */
struct EEVEE_ProbesInfo *probes;
struct GPUUniformBuffer *probe_ubo;
struct g_data *g_data;
} EEVEE_StorageList;
/* ************ LIGHT UBO ************* */
typedef struct EEVEE_Light {
float position[3], dist;
float color[3], spec;
float spotsize, spotblend, radius, shadowid;
float rightvec[3], sizex;
float upvec[3], sizey;
float forwardvec[3], lamptype;
} EEVEE_Light;
typedef struct EEVEE_ShadowCube {
float near, far, bias, pad;
} EEVEE_ShadowCube;
typedef struct EEVEE_ShadowMap {
float shadowmat[4][4]; /* World->Lamp->NDC->Tex : used for sampling the shadow map. */
float near, far, bias, pad;
} EEVEE_ShadowMap;
typedef struct EEVEE_ShadowCascade {
float shadowmat[MAX_CASCADE_NUM][4][4]; /* World->Lamp->NDC->Tex : used for sampling the shadow map. */
float split[4];
float bias[4];
} EEVEE_ShadowCascade;
typedef struct EEVEE_ShadowRender {
float shadowmat[6][4][4]; /* World->Lamp->NDC : used to render the shadow map. 6 frustrum for cubemap shadow */
int layer;
} EEVEE_ShadowRender;
/* ************ LIGHT DATA ************* */
typedef struct EEVEE_LampsInfo {
int num_light, cache_num_light;
int num_cube, cache_num_cube;
int num_map, cache_num_map;
int num_cascade, cache_num_cascade;
/* List of lights in the scene. */
struct Object *light_ref[MAX_LIGHT];
struct Object *shadow_cube_ref[MAX_SHADOW_CUBE];
struct Object *shadow_map_ref[MAX_SHADOW_MAP];
struct Object *shadow_cascade_ref[MAX_SHADOW_CASCADE];
/* UBO Storage : data used by UBO */
struct EEVEE_Light light_data[MAX_LIGHT];
struct EEVEE_ShadowRender shadow_render_data;
struct EEVEE_ShadowCube shadow_cube_data[MAX_SHADOW_CUBE];
struct EEVEE_ShadowMap shadow_map_data[MAX_SHADOW_MAP];
struct EEVEE_ShadowCascade shadow_cascade_data[MAX_SHADOW_CASCADE];
} EEVEE_LampsInfo;
/* ************ PROBE DATA ************* */
typedef struct EEVEE_ProbesInfo {
/* For rendering probes */
float probemat[6][4][4];
int layer;
float samples_ct;
float invsamples_ct;
float roughness;
float lodfactor;
float lodmax;
int shres;
int shnbr;
float shcoefs[9][3]; /* Temp */
struct GPUTexture *backgroundtex;
} EEVEE_ProbesInfo;
/* *********************************** */
typedef struct EEVEE_Data {
void *engine_type;
EEVEE_FramebufferList *fbl;
EEVEE_TextureList *txl;
EEVEE_PassList *psl;
EEVEE_StorageList *stl;
} EEVEE_Data;
/* Keep it sync with MAX_LAMP_DATA */
typedef struct EEVEE_LampEngineData {
void *sto;
void *pad;
} EEVEE_LampEngineData;
typedef struct g_data{
struct DRWShadingGroup *default_lit_grp;
struct DRWShadingGroup *material_lit_grp;
struct DRWShadingGroup *shadow_shgrp;
struct DRWShadingGroup *depth_shgrp;
struct DRWShadingGroup *depth_shgrp_cull;
struct ListBase lamps; /* Lamps gathered during cache iteration */
} g_data; /* Transient data */
/* eevee_lights.c */
void EEVEE_lights_init(EEVEE_StorageList *stl);
void EEVEE_lights_cache_init(EEVEE_StorageList *stl);
void EEVEE_lights_cache_add(EEVEE_StorageList *stl, struct Object *ob);
void EEVEE_lights_cache_finish(EEVEE_StorageList *stl, EEVEE_TextureList *txl, EEVEE_FramebufferList *fbl);
void EEVEE_lights_update(EEVEE_StorageList *stl);
void EEVEE_draw_shadows(EEVEE_Data *vedata);
/* eevee_probes.c */
void EEVEE_probes_init(EEVEE_Data *vedata);
void EEVEE_probes_cache_init(EEVEE_Data *vedata);
void EEVEE_probes_cache_add(EEVEE_Data *vedata, Object *ob);
void EEVEE_probes_cache_finish(EEVEE_Data *vedata);
void EEVEE_probes_update(EEVEE_Data *vedata);
void EEVEE_refresh_probe(EEVEE_Data *vedata);
/* Shadow Matrix */
static const float texcomat[4][4] = { /* From NDC to TexCo */
{0.5, 0.0, 0.0, 0.0},
{0.0, 0.5, 0.0, 0.0},
{0.0, 0.0, 0.5, 0.0},
{0.5, 0.5, 0.5, 1.0}
};
/* Cubemap Matrices */
static const float cubefacemat[6][4][4] = {
/* Pos X */
{{0.0, 0.0, -1.0, 0.0},
{0.0, -1.0, 0.0, 0.0},
{-1.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 0.0, 1.0}},
/* Neg X */
{{0.0, 0.0, 1.0, 0.0},
{0.0, -1.0, 0.0, 0.0},
{1.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 0.0, 1.0}},
/* Pos Y */
{{1.0, 0.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 0.0},
{0.0, -1.0, 0.0, 0.0},
{0.0, 0.0, 0.0, 1.0}},
/* Neg Y */
{{1.0, 0.0, 0.0, 0.0},
{0.0, 0.0, -1.0, 0.0},
{0.0, 1.0, 0.0, 0.0},
{0.0, 0.0, 0.0, 1.0}},
/* Pos Z */
{{1.0, 0.0, 0.0, 0.0},
{0.0, -1.0, 0.0, 0.0},
{0.0, 0.0, -1.0, 0.0},
{0.0, 0.0, 0.0, 1.0}},
/* Neg Z */
{{-1.0, 0.0, 0.0, 0.0},
{0.0, -1.0, 0.0, 0.0},
{0.0, 0.0, 1.0, 0.0},
{0.0, 0.0, 0.0, 1.0}},
};
|