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  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup DNA
22  */
23 
24 #pragma once
25 
26 #include "DNA_ID.h"
27 #include "DNA_defs.h"
28 #include "DNA_listBase.h"
29 
30 #ifndef MAX_MTEX
31 #  define MAX_MTEX 18
32 #endif
33 
34 struct AnimData;
35 struct Image;
36 struct Ipo;
37 struct bNodeTree;
38 
39 /* WATCH IT: change type? also make changes in ipo.h  */
40 
41 typedef struct TexPaintSlot {
42   /** Image to be painted on. */
43   struct Image *ima;
44   /** Customdata index for uv layer, MAX_NAM.E*/
45   char *uvname;
46   /** Do we have a valid image and UV map. */
47   int valid;
48   /** Copy of node inteporlation setting. */
49   int interp;
50 } TexPaintSlot;
51 
52 typedef struct MaterialGPencilStyle {
53   /** Texture image for strokes. */
54   struct Image *sima;
55   /** Texture image for filling. */
56   struct Image *ima;
57   /** Color for paint and strokes (alpha included). */
58   float stroke_rgba[4];
59   /** Color that should be used for drawing "fills" for strokes (alpha included). */
60   float fill_rgba[4];
61   /** Secondary color used for gradients and other stuff. */
62   float mix_rgba[4];
63   /** Settings. */
64   short flag;
65   /** Custom index for passes. */
66   short index;
67   /** Style for drawing strokes (used to select shader type). */
68   short stroke_style;
69   /** Style for filling areas (used to select shader type). */
70   short fill_style;
71   /** Factor used to define shader behavior (several uses). */
72   float mix_factor;
73   /** Angle used for gradients orientation. */
74   float gradient_angle DNA_DEPRECATED;
75   /** Radius for radial gradients. */
76   float gradient_radius DNA_DEPRECATED;
77   char _pad2[4];
78   /** Uv coordinates scale. */
79   float gradient_scale[2] DNA_DEPRECATED;
80   /** Factor to shift filling in 2d space. */
81   float gradient_shift[2] DNA_DEPRECATED;
82   /** Angle used for texture orientation. */
83   float texture_angle;
84   /** Texture scale (separated of uv scale). */
85   float texture_scale[2];
86   /** Factor to shift texture in 2d space. */
87   float texture_offset[2];
88   /** Texture opacity. */
89   float texture_opacity DNA_DEPRECATED;
90   /** Pixel size for uv along the stroke. */
91   float texture_pixsize;
92   /** Drawing mode (line or dots). */
93   int mode;
94 
95   /** Type of gradient. */
96   int gradient_type;
97 
98   /** Factor used to mix texture and stroke color. */
99   float mix_stroke_factor;
100   /** Mode used to align Dots and Boxes with stroke drawing path and object rotation */
101   int alignment_mode;
102   char _pad[4];
103 } MaterialGPencilStyle;
104 
105 /* MaterialGPencilStyle->flag */
106 typedef enum eMaterialGPencilStyle_Flag {
107   /* Fill Texture is a pattern */
108   GP_MATERIAL_FILL_PATTERN = (1 << 0),
109   /* don't display color */
110   GP_MATERIAL_HIDE = (1 << 1),
111   /* protected from further editing */
112   GP_MATERIAL_LOCKED = (1 << 2),
113   /* do onion skinning */
114   GP_MATERIAL_HIDE_ONIONSKIN = (1 << 3),
115   /* clamp texture */
116   GP_MATERIAL_TEX_CLAMP = (1 << 4),
117   /* mix fill texture */
118   GP_MATERIAL_FILL_TEX_MIX = (1 << 5),
119   /* Flip fill colors */
120   GP_MATERIAL_FLIP_FILL = (1 << 6),
121   /* Stroke Texture is a pattern */
122   GP_MATERIAL_STROKE_PATTERN = (1 << 7),
123   /* Stroke show main switch */
124   GP_MATERIAL_STROKE_SHOW = (1 << 8),
125   /* Fill show main switch */
126   GP_MATERIAL_FILL_SHOW = (1 << 9),
127   /* mix stroke texture */
128   GP_MATERIAL_STROKE_TEX_MIX = (1 << 11),
129   /* disable stencil clipping (overlap) */
130   GP_MATERIAL_DISABLE_STENCIL = (1 << 12),
131   /* Material used as stroke masking. */
132   GP_MATERIAL_IS_STROKE_HOLDOUT = (1 << 13),
133   /* Material used as fill masking. */
134   GP_MATERIAL_IS_FILL_HOLDOUT = (1 << 14),
135 } eMaterialGPencilStyle_Flag;
136 
137 typedef enum eMaterialGPencilStyle_Mode {
138   GP_MATERIAL_MODE_LINE = 0,
139   GP_MATERIAL_MODE_DOT = 1,
140   GP_MATERIAL_MODE_SQUARE = 2,
141 } eMaterialGPencilStyle_Mode;
142 
143 typedef struct Material {
144   ID id;
145   /** Animation data (must be immediately after id for utilities to use it). */
146   struct AnimData *adt;
147 
148   short flag;
149   char _pad1[2];
150 
151   /* Colors from Blender Internal that we are still using. */
152   float r, g, b, a;
153   float specr, specg, specb;
154   float alpha DNA_DEPRECATED;
155   float ray_mirror DNA_DEPRECATED;
156   float spec;
157   /** Renamed and inversed to roughness. */
158   float gloss_mir DNA_DEPRECATED;
159   float roughness;
160   float metallic;
161 
162   /** Nodes */
163   char use_nodes;
164 
165   /** Preview render. */
166   char pr_type;
167   short pr_texture;
168   short pr_flag;
169 
170   /** Index for render passes. */
171   short index;
172 
173   struct bNodeTree *nodetree;
174   /** Old animation system, deprecated for 2.5. */
175   struct Ipo *ipo DNA_DEPRECATED;
176   struct PreviewImage *preview;
177 
178   /* Freestyle line settings. */
179   float line_col[4];
180   short line_priority;
181   short vcol_alpha;
182 
183   /* Texture painting slots. */
184   short paint_active_slot;
185   short paint_clone_slot;
186   short tot_slots;
187   char _pad2[2];
188 
189   /* Transparency. */
190   float alpha_threshold;
191   float refract_depth;
192   char blend_method;
193   char blend_shadow;
194   char blend_flag;
195   char _pad3[1];
196 
197   /**
198    * Cached slots for texture painting, must be refreshed in
199    * refresh_texpaint_image_cache before using.
200    */
201   struct TexPaintSlot *texpaintslot;
202 
203   /** Runtime cache for GLSL materials. */
204   ListBase gpumaterial;
205 
206   /** Grease pencil color. */
207   struct MaterialGPencilStyle *gp_style;
208 } Material;
209 
210 /* **************** MATERIAL ********************* */
211 
212 /* maximum number of materials per material array.
213  * (on object, mesh, light, etc.). limited by
214  * short mat_nr in verts, faces.
215  * -1 because for active material we store the index + 1 */
216 #define MAXMAT (32767 - 1)
217 
218 /* flag */
219 /* for render */
220 /* #define MA_IS_USED      (1 << 0) */ /* UNUSED */
221                                        /* for dopesheet */
222 #define MA_DS_EXPAND (1 << 1)
223 /* for dopesheet (texture stack expander)
224  * NOTE: this must have the same value as other texture stacks,
225  * otherwise anim-editors will not read correctly
226  */
227 #define MA_DS_SHOW_TEXS (1 << 2)
228 
229 /* ramps */
230 #define MA_RAMP_BLEND 0
231 #define MA_RAMP_ADD 1
232 #define MA_RAMP_MULT 2
233 #define MA_RAMP_SUB 3
234 #define MA_RAMP_SCREEN 4
235 #define MA_RAMP_DIV 5
236 #define MA_RAMP_DIFF 6
237 #define MA_RAMP_DARK 7
238 #define MA_RAMP_LIGHT 8
239 #define MA_RAMP_OVERLAY 9
240 #define MA_RAMP_DODGE 10
241 #define MA_RAMP_BURN 11
242 #define MA_RAMP_HUE 12
243 #define MA_RAMP_SAT 13
244 #define MA_RAMP_VAL 14
245 #define MA_RAMP_COLOR 15
246 #define MA_RAMP_SOFT 16
247 #define MA_RAMP_LINEAR 17
248 
249 /* texco */
250 #define TEXCO_ORCO (1 << 0)
251 /* #define TEXCO_REFL      (1 << 1) */ /* deprecated */
252 /* #define TEXCO_NORM      (1 << 2) */ /* deprecated */
253 #define TEXCO_GLOB (1 << 3)
254 #define TEXCO_UV (1 << 4)
255 #define TEXCO_OBJECT (1 << 5)
256 /* #define TEXCO_LAVECTOR  (1 << 6) */ /* deprecated */
257 /* #define TEXCO_VIEW      (1 << 7) */ /* deprecated */
258 /* #define TEXCO_STICKY   (1 << 8) */  /* deprecated */
259 /* #define TEXCO_OSA       (1 << 9) */ /* deprecated */
260 #define TEXCO_WINDOW (1 << 10)
261 /* #define NEED_UV         (1 << 11) */ /* deprecated */
262 /* #define TEXCO_TANGENT   (1 << 12) */ /* deprecated */
263 /* still stored in vertex->accum, 1 D */
264 #define TEXCO_STRAND (1 << 13)
265 /** strand is used for normal materials, particle for halo materials */
266 #define TEXCO_PARTICLE (1 << 13)
267 /* #define TEXCO_STRESS    (1 << 14) */ /* deprecated */
268 /* #define TEXCO_SPEED     (1 << 15) */ /* deprecated */
269 
270 /* mapto */
271 #define MAP_COL (1 << 0)
272 #define MAP_ALPHA (1 << 7)
273 
274 /* pmapto */
275 /* init */
276 #define MAP_PA_INIT ((1 << 5) - 1)
277 #define MAP_PA_TIME (1 << 0)
278 #define MAP_PA_LIFE (1 << 1)
279 #define MAP_PA_DENS (1 << 2)
280 #define MAP_PA_SIZE (1 << 3)
281 #define MAP_PA_LENGTH (1 << 4)
282 /* reset */
283 #define MAP_PA_IVEL (1 << 5)
284 /* physics */
285 #define MAP_PA_PVEL (1 << 6)
286 /* path cache */
287 #define MAP_PA_CLUMP (1 << 7)
288 #define MAP_PA_KINK (1 << 8)
289 #define MAP_PA_ROUGH (1 << 9)
290 #define MAP_PA_FREQ (1 << 10)
291 
292 /* pr_type */
293 #define MA_FLAT 0
294 #define MA_SPHERE 1
295 #define MA_CUBE 2
296 #define MA_SHADERBALL 3
297 #define MA_SPHERE_A 4 /* Used for icon renders only. */
298 #define MA_TEXTURE 5
299 #define MA_LAMP 6
300 #define MA_SKY 7
301 #define MA_HAIR 10
302 #define MA_ATMOS 11
303 #define MA_CLOTH 12
304 #define MA_FLUID 13
305 
306 /* pr_flag */
307 #define MA_PREVIEW_WORLD (1 << 0)
308 
309 /* blend_method */
310 enum {
311   MA_BM_SOLID = 0,
312   // MA_BM_ADD = 1, /* deprecated */
313   // MA_BM_MULTIPLY = 2,  /* deprecated */
314   MA_BM_CLIP = 3,
315   MA_BM_HASHED = 4,
316   MA_BM_BLEND = 5,
317 };
318 
319 /* blend_flag */
320 enum {
321   MA_BL_HIDE_BACKFACE = (1 << 0),
322   MA_BL_SS_REFRACTION = (1 << 1),
323   MA_BL_CULL_BACKFACE = (1 << 2),
324   MA_BL_TRANSLUCENCY = (1 << 3),
325 };
326 
327 /* blend_shadow */
328 enum {
329   MA_BS_NONE = 0,
330   MA_BS_SOLID = 1,
331   MA_BS_CLIP = 2,
332   MA_BS_HASHED = 3,
333 };
334 
335 /* Grease Pencil Stroke styles */
336 enum {
337   GP_MATERIAL_STROKE_STYLE_SOLID = 0,
338   GP_MATERIAL_STROKE_STYLE_TEXTURE = 1,
339 };
340 
341 /* Grease Pencil Fill styles */
342 enum {
343   GP_MATERIAL_FILL_STYLE_SOLID = 0,
344   GP_MATERIAL_FILL_STYLE_GRADIENT = 1,
345   GP_MATERIAL_FILL_STYLE_CHECKER = 2, /* DEPRECATED (only for convert old files) */
346   GP_MATERIAL_FILL_STYLE_TEXTURE = 3,
347 };
348 
349 /* Grease Pencil Gradient Types */
350 enum {
351   GP_MATERIAL_GRADIENT_LINEAR = 0,
352   GP_MATERIAL_GRADIENT_RADIAL = 1,
353 };
354 
355 /* Grease Pencil Follow Drawing Modes */
356 enum {
357   GP_MATERIAL_FOLLOW_PATH = 0,
358   GP_MATERIAL_FOLLOW_OBJ = 1,
359   GP_MATERIAL_FOLLOW_FIXED = 2,
360 };
361