Physically based defaults for Eevee Bloom and Shutter
[blender.git] / source / blender / blenkernel / BKE_studiolight.h
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (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, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2006-2007 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 #ifndef __BKE_STUDIOLIGHT_H__
29 #define __BKE_STUDIOLIGHT_H__
30
31 /** \file BKE_studiolight.h
32  *  \ingroup bke
33  *
34  * Studio lighting for the 3dview
35  */
36
37 #include "BKE_context.h"
38
39 #include "BLI_sys_types.h"
40
41 #include "DNA_space_types.h"
42 #include "DNA_userdef_types.h"
43
44 #include "IMB_imbuf_types.h"
45
46 /*
47  * These defines are the indexes in the StudioLight.diffuse_light
48  * X_POS means the light that is traveling towards the positive X
49  * So Light direction.
50  */
51 #define STUDIOLIGHT_X_POS 0
52 #define STUDIOLIGHT_X_NEG 1
53 #define STUDIOLIGHT_Y_POS 2
54 #define STUDIOLIGHT_Y_NEG 3
55 #define STUDIOLIGHT_Z_POS 4
56 #define STUDIOLIGHT_Z_NEG 5
57
58 #define STUDIOLIGHT_ICON_ID_TYPE_RADIANCE       (1 << 0)
59 #define STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE     (1 << 1)
60 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP         (1 << 2)
61 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED (1 << 3)
62
63 #define STUDIOLIGHT_MAX_LIGHT 4
64
65 #define STUDIOLIGHT_ICON_SIZE 96
66
67 /* Only 1 - 5 is supported */
68 #define STUDIOLIGHT_SH_BANDS 2
69
70 #define STUDIOLIGHT_SH_COEFS_LEN (STUDIOLIGHT_SH_BANDS * STUDIOLIGHT_SH_BANDS)
71
72 #if STUDIOLIGHT_SH_BANDS > 3
73 /* Bypass L3 */
74 #define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN (STUDIOLIGHT_SH_COEFS_LEN - 7)
75 #else
76 #define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN STUDIOLIGHT_SH_COEFS_LEN
77 #endif
78
79 struct GPUTexture;
80 struct StudioLight;
81
82 /* StudioLight.flag */
83 enum StudioLightFlag {
84         STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED = (1 << 0),
85 /*      STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED                  = (1 << 1), */
86         STUDIOLIGHT_INTERNAL                                    = (1 << 2),
87         STUDIOLIGHT_EXTERNAL_FILE                               = (1 << 3),
88         STUDIOLIGHT_TYPE_STUDIO                                 = (1 << 4),
89         STUDIOLIGHT_TYPE_WORLD                                  = (1 << 5),
90         STUDIOLIGHT_TYPE_MATCAP                                 = (1 << 6),
91         STUDIOLIGHT_EXTERNAL_IMAGE_LOADED                       = (1 << 7),
92         STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED        = (1 << 8),
93         STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE                = (1 << 9),
94         STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE              = (1 << 10),
95         STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED                 = (1 << 11),
96         STUDIOLIGHT_USER_DEFINED                                = (1 << 12),
97         STUDIOLIGHT_UI_EXPANDED                                 = (1 << 13),
98 };
99
100 #define STUDIOLIGHT_FLAG_ALL (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_EXTERNAL_FILE)
101 #define STUDIOLIGHT_FLAG_ORIENTATIONS (STUDIOLIGHT_TYPE_STUDIO | STUDIOLIGHT_TYPE_WORLD | STUDIOLIGHT_TYPE_MATCAP)
102 #define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE (STUDIOLIGHT_TYPE_WORLD)
103 #define STUDIOLIGHT_ORIENTATIONS_SOLID (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_TYPE_STUDIO)
104
105 typedef void StudioLightFreeFunction(struct StudioLight *, void *data);
106
107 typedef struct StudioLight {
108         struct StudioLight *next, *prev;
109
110         int index;
111         int flag;
112         char name[FILE_MAXFILE];
113         char path[FILE_MAX];
114         char *path_irr_cache;
115         char *path_sh_cache;
116         int icon_id_irradiance;
117         int icon_id_radiance;
118         int icon_id_matcap;
119         int icon_id_matcap_flipped;
120         float spherical_harmonics_coefs[STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN][3];
121         float light_direction[3];
122         ImBuf *equirect_radiance_buffer;
123         ImBuf *equirect_irradiance_buffer;
124         ImBuf *radiance_cubemap_buffers[6];
125         struct GPUTexture *equirect_radiance_gputexture;
126         struct GPUTexture *equirect_irradiance_gputexture;
127         SolidLight light[STUDIOLIGHT_MAX_LIGHT];
128         float light_ambient[3];
129
130         /*
131          * Free function to clean up the running icons previews (wmJob) the usage is in
132          * interface_icons. Please be aware that this was build to handle only one free function
133          * that cleans up all icons. just to keep the code simple.
134          */
135         StudioLightFreeFunction *free_function;
136         void *free_function_data;
137 } StudioLight;
138
139 void BKE_studiolight_init(void);
140 void BKE_studiolight_free(void);
141 struct StudioLight *BKE_studiolight_find(const char *name, int flag);
142 struct StudioLight *BKE_studiolight_findindex(int index, int flag);
143 struct StudioLight *BKE_studiolight_find_default(int flag);
144 void BKE_studiolight_preview(uint *icon_buffer, StudioLight *sl, int icon_id_type);
145 struct ListBase *BKE_studiolight_listbase(void);
146 void BKE_studiolight_ensure_flag(StudioLight *sl, int flag);
147 void BKE_studiolight_refresh(void);
148 StudioLight *BKE_studiolight_load(const char *path, int orientation);
149 StudioLight *BKE_studiolight_create(const char *path, const SolidLight light[4], const float light_ambient[3]);
150 StudioLight *BKE_studiolight_studio_edit_get(void);
151 void BKE_studiolight_remove(StudioLight *sl);
152 void BKE_studiolight_set_free_function(StudioLight *sl, StudioLightFreeFunction *free_function, void *data);
153 void BKE_studiolight_unset_icon_id(StudioLight *sl, int icon_id);
154
155 #endif /*  __BKE_STUDIOLIGHT_H__ */