7ec98c99c3f99dfc90388029b598313f62550cbf
[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
43 #include "IMB_imbuf_types.h"
44
45 /*
46  * These defines are the indexes in the StudioLight.diffuse_light
47  * X_POS means the light that is traveling towards the positive X
48  * So Light direction.
49  */
50 #define STUDIOLIGHT_X_POS 0
51 #define STUDIOLIGHT_X_NEG 1
52 #define STUDIOLIGHT_Y_POS 2
53 #define STUDIOLIGHT_Y_NEG 3
54 #define STUDIOLIGHT_Z_POS 4
55 #define STUDIOLIGHT_Z_NEG 5
56
57 #define STUDIOLIGHT_ICON_ID_TYPE_RADIANCE       (1 << 0)
58 #define STUDIOLIGHT_ICON_ID_TYPE_IRRADIANCE     (1 << 1)
59 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP         (1 << 2)
60 #define STUDIOLIGHT_ICON_ID_TYPE_MATCAP_FLIPPED (1 << 3)
61
62 #define STUDIOLIGHT_ICON_SIZE 96
63
64 /* Only 1 - 5 is supported */
65 #define STUDIOLIGHT_SH_BANDS 2
66
67 #define STUDIOLIGHT_SH_COEFS_LEN (STUDIOLIGHT_SH_BANDS * STUDIOLIGHT_SH_BANDS)
68
69 #if STUDIOLIGHT_SH_BANDS > 3
70 /* Bypass L3 */
71 #define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN (STUDIOLIGHT_SH_COEFS_LEN - 7)
72 #else
73 #define STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN STUDIOLIGHT_SH_COEFS_LEN
74 #endif
75
76 struct GPUTexture;
77 struct StudioLight;
78
79 /* StudioLight.flag */
80 enum StudioLightFlag {
81         STUDIOLIGHT_SPHERICAL_HARMONICS_COEFFICIENTS_CALCULATED = (1 << 0),
82 /*      STUDIOLIGHT_LIGHT_DIRECTION_CALCULATED                  = (1 << 1), */
83         STUDIOLIGHT_INTERNAL                                    = (1 << 2),
84         STUDIOLIGHT_EXTERNAL_FILE                               = (1 << 3),
85         STUDIOLIGHT_ORIENTATION_CAMERA                          = (1 << 4),
86         STUDIOLIGHT_ORIENTATION_WORLD                           = (1 << 5),
87         STUDIOLIGHT_ORIENTATION_VIEWNORMAL                      = (1 << 6),
88         STUDIOLIGHT_EXTERNAL_IMAGE_LOADED                       = (1 << 7),
89         STUDIOLIGHT_EQUIRECT_IRRADIANCE_IMAGE_CALCULATED        = (1 << 8),
90         STUDIOLIGHT_EQUIRECT_RADIANCE_GPUTEXTURE                = (1 << 9),
91         STUDIOLIGHT_EQUIRECT_IRRADIANCE_GPUTEXTURE              = (1 << 10),
92         STUDIOLIGHT_RADIANCE_BUFFERS_CALCULATED                 = (1 << 11),
93         STUDIOLIGHT_USER_DEFINED                                = (1 << 12),
94         STUDIOLIGHT_UI_EXPANDED                                 = (1 << 13),
95 };
96
97 #define STUDIOLIGHT_FLAG_ALL (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_EXTERNAL_FILE)
98 #define STUDIOLIGHT_FLAG_ORIENTATIONS (STUDIOLIGHT_ORIENTATION_CAMERA | STUDIOLIGHT_ORIENTATION_WORLD | STUDIOLIGHT_ORIENTATION_VIEWNORMAL)
99 #define STUDIOLIGHT_ORIENTATIONS_MATERIAL_MODE (STUDIOLIGHT_ORIENTATION_WORLD)
100 #define STUDIOLIGHT_ORIENTATIONS_SOLID (STUDIOLIGHT_INTERNAL | STUDIOLIGHT_ORIENTATION_CAMERA | STUDIOLIGHT_ORIENTATION_WORLD)
101
102 typedef void StudioLightFreeFunction(struct StudioLight *, void *data);
103
104 typedef struct StudioLight {
105         struct StudioLight *next, *prev;
106
107         int index;
108         int flag;
109         char name[FILE_MAXFILE];
110         char path[FILE_MAX];
111         char *path_irr_cache;
112         char *path_sh_cache;
113         int icon_id_irradiance;
114         int icon_id_radiance;
115         int icon_id_matcap;
116         int icon_id_matcap_flipped;
117         float spherical_harmonics_coefs[STUDIOLIGHT_SH_EFFECTIVE_COEFS_LEN][3];
118         float light_direction[3];
119         ImBuf *equirect_radiance_buffer;
120         ImBuf *equirect_irradiance_buffer;
121         ImBuf *radiance_cubemap_buffers[6];
122         struct GPUTexture *equirect_radiance_gputexture;
123         struct GPUTexture *equirect_irradiance_gputexture;
124
125         /*
126          * Free function to clean up the running icons previews (wmJob) the usage is in
127          * interface_icons. Please be aware that this was build to handle only one free function
128          * that cleans up all icons. just to keep the code simple.
129          */
130         StudioLightFreeFunction *free_function;
131         void *free_function_data;
132 } StudioLight;
133
134 void BKE_studiolight_init(void);
135 void BKE_studiolight_free(void);
136 struct StudioLight *BKE_studiolight_find(const char *name, int flag);
137 struct StudioLight *BKE_studiolight_findindex(int index, int flag);
138 struct StudioLight *BKE_studiolight_find_first(int flag);
139 void BKE_studiolight_preview(uint *icon_buffer, StudioLight *sl, int icon_id_type);
140 struct ListBase *BKE_studiolight_listbase(void);
141 void BKE_studiolight_ensure_flag(StudioLight *sl, int flag);
142 void BKE_studiolight_refresh(void);
143 StudioLight *BKE_studiolight_new(const char *path, int orientation);
144 void BKE_studiolight_remove(StudioLight *sl);
145 void BKE_studiolight_set_free_function(StudioLight *sl, StudioLightFreeFunction *free_function, void *data);
146 void BKE_studiolight_unset_icon_id(StudioLight *sl, int icon_id);
147
148 #endif /*  __BKE_STUDIOLIGHT_H__ */