16abc3c91f63ac0849b2f9cbb791abae6c9e6485
[blender.git] / release / ui / buttons_material.py
1         
2 import bpy
3
4 class MaterialButtonsPanel(bpy.types.Panel):
5         __space_type__ = "BUTTONS_WINDOW"
6         __region_type__ = "WINDOW"
7         __context__ = "material"
8         # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
9
10         def poll(self, context):
11                 return (context.material) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
12
13 class MATERIAL_PT_preview(MaterialButtonsPanel):
14         __label__ = "Preview"
15         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
16
17         def draw(self, context):
18                 layout = self.layout
19                 
20                 mat = context.material
21                 
22                 layout.template_preview(mat)
23                 
24 class MATERIAL_PT_context_material(MaterialButtonsPanel):
25         __show_header__ = False
26         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
27
28         def poll(self, context):
29                 # An exception, dont call the parent poll func because
30                 # this manages materials for all engine types
31                 
32                 return (context.object) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
33
34         def draw(self, context):
35                 layout = self.layout
36                 
37                 mat = context.material
38                 ob = context.object
39                 slot = context.material_slot
40                 space = context.space_data
41
42                 if ob:
43                         row = layout.row()
44
45                         row.template_list(ob, "materials", ob, "active_material_index", rows=2)
46
47                         col = row.column(align=True)
48                         col.itemO("object.material_slot_add", icon="ICON_ZOOMIN", text="")
49                         col.itemO("object.material_slot_remove", icon="ICON_ZOOMOUT", text="")
50
51                         if context.edit_object:
52                                 row = layout.row(align=True)
53                                 row.itemO("object.material_slot_assign", text="Assign")
54                                 row.itemO("object.material_slot_select", text="Select")
55                                 row.itemO("object.material_slot_deselect", text="Deselect")
56
57                 split = layout.split(percentage=0.65)
58
59                 if ob:
60                         split.template_ID(ob, "active_material", new="material.new")
61                         row = split.row()
62                         if slot:
63                                 row.itemR(slot, "link", expand=True)
64                         else:
65                                 row.itemL()
66                 elif mat:
67                         split.template_ID(space, "pin_id")
68                         split.itemS()
69         
70 class MATERIAL_PT_material(MaterialButtonsPanel):
71         __idname__= "MATERIAL_PT_material"
72         __label__ = "Shading"
73         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
74
75         def draw(self, context):
76                 layout = self.layout
77                 
78                 mat = context.material
79                 ob = context.object
80                 slot = context.material_slot
81                 space = context.space_data
82
83                 if mat:
84                         layout.itemR(mat, "type", expand=True)
85
86                         if mat.type in ('SURFACE', 'WIRE', 'VOLUME'):
87                                 split = layout.split()
88         
89                                 col = split.column()
90                                 col.itemR(mat, "alpha", slider=True)
91                                 col.itemR(mat, "ambient", slider=True)
92                                 col.itemR(mat, "emit")
93                                 col.itemR(mat, "translucency", slider=True)
94                                 
95                                 col = split.column()
96                                 col.itemR(mat, "z_transparency")
97                                 col.itemR(mat, "shadeless")     
98                                 col.itemR(mat, "tangent_shading")
99                                 col.itemR(mat, "cubic", slider=True)
100                                 
101                         elif mat.type == 'HALO':
102                                 layout.itemR(mat, "alpha", slider=True)
103                         
104 class MATERIAL_PT_strand(MaterialButtonsPanel):
105         __label__ = "Strand"
106         __default_closed__ = True
107         COMPAT_ENGINES = set(['BLENDER_RENDER'])
108         
109         def draw(self, context):
110                 layout = self.layout
111                 
112                 mat = context.material
113                 tan = mat.strand
114                 
115                 split = layout.split()
116                 
117                 col = split.column()
118                 col.itemL(text="Size:")
119                 col.itemR(tan, "start_size", text="Root")
120                 col.itemR(tan, "end_size", text="Tip")
121                 col.itemR(tan, "min_size", text="Minimum")
122                 col.itemR(tan, "blender_units")
123                 sub = col.column()
124                 sub.active = (not mat.shadeless)
125                 sub.itemR(tan, "tangent_shading")
126                 
127                 col = split.column()
128                 col.itemR(tan, "shape")
129                 col.itemR(tan, "width_fade")
130                 col.itemR(tan, "uv_layer")
131                 sub = col.column()
132                 sub.active = (not mat.shadeless)
133                 sub.itemR(tan, "surface_diffuse")
134                 sub = col.column()
135                 sub.active = tan.surface_diffuse
136                 sub.itemR(tan, "blend_distance", text="Distance")
137                 
138 class MATERIAL_PT_physics(MaterialButtonsPanel):
139         __label__ = "Physics"
140         COMPAT_ENGINES = set(['BLENDER_GAME'])
141         
142         def draw(self, context):
143                 layout = self.layout
144                 
145                 mat = context.material
146                 phys = mat.physics
147                 
148                 split = layout.split()
149                 
150                 col = split.column()
151                 col.itemR(phys, "distance")
152                 col.itemR(phys, "friction")
153                 col.itemR(phys, "align_to_normal")
154                 
155                 col = split.column()
156                 col.itemR(phys, "force", slider=True)
157                 col.itemR(phys, "elasticity", slider=True)
158                 col.itemR(phys, "damp", slider=True)
159                 
160 class MATERIAL_PT_options(MaterialButtonsPanel):
161         __label__ = "Options"
162         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
163
164         def draw(self, context):
165                 layout = self.layout
166                 
167                 mat = context.material
168                 
169                 split = layout.split()
170                 
171                 col = split.column()
172                 col.itemR(mat, "traceable")
173                 col.itemR(mat, "full_oversampling")
174                 col.itemR(mat, "sky")
175                 col.itemR(mat, "exclude_mist")
176                 col.itemR(mat, "invert_z")
177                 sub = col.column(align=True)
178                 sub.itemL(text="Light Group:")
179                 sub.itemR(mat, "light_group", text="")
180                 row = sub.row()
181                 row.active = mat.light_group
182                 row.itemR(mat, "light_group_exclusive", text="Exclusive")
183
184                 col = split.column()
185                 col.itemR(mat, "face_texture")
186                 sub = col.column()
187                 sub.active = mat.face_texture
188                 sub.itemR(mat, "face_texture_alpha")
189                 col.itemS()
190                 col.itemR(mat, "vertex_color_paint")
191                 col.itemR(mat, "vertex_color_light")
192                 col.itemR(mat, "object_color")
193
194 class MATERIAL_PT_shadows(MaterialButtonsPanel):
195         __label__ = "Shadows"
196         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
197
198         def draw(self, context):
199                 layout = self.layout
200                 
201                 mat = context.material
202                 
203                 split = layout.split()
204                 
205                 col = split.column()
206                 col.itemR(mat, "shadows", text="Receive")
207                 col.itemR(mat, "transparent_shadows", text="Receive Transparent")
208                 col.itemR(mat, "only_shadow", text="Shadows Only")
209                 col.itemR(mat, "cast_shadows_only", text="Cast Only")
210                 col.itemR(mat, "shadow_casting_alpha", text="Casting Alpha", slider=True)
211                 
212                 col = split.column()
213                 col.itemR(mat, "cast_buffer_shadows")
214                 sub = col.column()
215                 sub.active = mat.cast_buffer_shadows
216                 sub.itemR(mat, "shadow_buffer_bias", text="Buffer Bias")
217                 col.itemR(mat, "ray_shadow_bias", text="Auto Ray Bias")
218                 sub = col.column()
219                 sub.active = (not mat.ray_shadow_bias)
220                 sub.itemR(mat, "shadow_ray_bias", text="Ray Bias")
221                 
222
223 class MATERIAL_PT_diffuse(MaterialButtonsPanel):
224         __label__ = "Diffuse"
225         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
226
227         def poll(self, context):
228                 mat = context.material
229                 return mat and (mat.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
230
231         def draw(self, context):
232                 layout = self.layout
233                 
234                 mat = context.material  
235                 
236                 split = layout.split()
237                 
238                 col = split.column()
239                 col.itemR(mat, "diffuse_color", text="")
240                 sub = col.column()
241                 sub.active = (not mat.shadeless)
242                 sub.itemR(mat, "diffuse_reflection", text="Intensity", slider=True)
243                 
244                 col = split.column()
245                 col.active = (not mat.shadeless)
246                 col.itemR(mat, "diffuse_shader", text="")
247                 col.itemR(mat, "use_diffuse_ramp", text="Ramp")
248                 
249                 col = layout.column()
250                 col.active = (not mat.shadeless)
251                 if mat.diffuse_shader == 'OREN_NAYAR':
252                         col.itemR(mat, "roughness")
253                 elif mat.diffuse_shader == 'MINNAERT':
254                         col.itemR(mat, "darkness")
255                 elif mat.diffuse_shader == 'TOON':
256                         row = col.row()
257                         row.itemR(mat, "diffuse_toon_size", text="Size")
258                         row.itemR(mat, "diffuse_toon_smooth", text="Smooth", slider=True)
259                 elif mat.diffuse_shader == 'FRESNEL':
260                         row = col.row()
261                         row.itemR(mat, "diffuse_fresnel", text="Fresnel")
262                         row.itemR(mat, "diffuse_fresnel_factor", text="Factor")
263                         
264                 if mat.use_diffuse_ramp:
265                         layout.itemS()
266                         layout.template_color_ramp(mat.diffuse_ramp, expand=True)
267                         layout.itemS()
268                         row = layout.row()
269                         split = row.split(percentage=0.3)
270                         split.itemL(text="Input:")
271                         split.itemR(mat, "diffuse_ramp_input", text="")
272                         split = row.split(percentage=0.3)
273                         split.itemL(text="Blend:")
274                         split.itemR(mat, "diffuse_ramp_blend", text="")
275                         
276                 
277 class MATERIAL_PT_specular(MaterialButtonsPanel):
278         __label__ = "Specular"
279         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
280
281         def poll(self, context):
282                 mat = context.material
283                 return mat and (mat.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
284
285         def draw(self, context):
286                 layout = self.layout
287                 
288                 mat = context.material
289                 
290                 layout.active = (not mat.shadeless)
291                 
292                 split = layout.split()
293                 
294                 col = split.column()
295                 col.itemR(mat, "specular_color", text="")
296                 col.itemR(mat, "specular_reflection", text="Intensity", slider=True)
297
298                 col = split.column()
299                 col.itemR(mat, "specular_shader", text="")
300                 col.itemR(mat, "use_specular_ramp", text="Ramp")
301
302                 col = layout.column()
303                 if mat.specular_shader in ('COOKTORR', 'PHONG'):
304                         col.itemR(mat, "specular_hardness", text="Hardness")
305                 elif mat.specular_shader == 'BLINN':
306                         row = col.row()
307                         row.itemR(mat, "specular_hardness", text="Hardness")
308                         row.itemR(mat, "specular_ior", text="IOR")
309                 elif mat.specular_shader == 'WARDISO':
310                         col.itemR(mat, "specular_slope", text="Slope")
311                 elif mat.specular_shader == 'TOON':
312                         row = col.row()
313                         row.itemR(mat, "specular_toon_size", text="Size")
314                         row.itemR(mat, "specular_toon_smooth", text="Smooth", slider=True)
315                 
316                 if mat.use_specular_ramp:
317                         layout.itemS()
318                         layout.template_color_ramp(mat.specular_ramp, expand=True)
319                         layout.itemS()
320                         row = layout.row()
321                         split = row.split(percentage=0.3)
322                         split.itemL(text="Input:")
323                         split.itemR(mat, "specular_ramp_input", text="")
324                         split = row.split(percentage=0.3)
325                         split.itemL(text="Blend:")
326                         split.itemR(mat, "specular_ramp_blend", text="")
327                 
328 class MATERIAL_PT_sss(MaterialButtonsPanel):
329         __label__ = "Subsurface Scattering"
330         __default_closed__ = True
331         COMPAT_ENGINES = set(['BLENDER_RENDER'])
332         
333         def poll(self, context):
334                 mat = context.material
335                 return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
336
337         def draw_header(self, context):
338                 layout = self.layout
339                 sss = context.material.subsurface_scattering
340
341                 layout.itemR(sss, "enabled", text="")
342         
343         def draw(self, context):
344                 layout = self.layout
345                 
346                 mat = context.material
347                 sss = context.material.subsurface_scattering
348
349                 layout.active = sss.enabled     
350                 
351                 split = layout.split()
352                 split.active = (not mat.shadeless)
353                 
354                 col = split.column(align=True)
355                 col.itemR(sss, "color", text="")
356                 col.itemL(text="Blend:")
357                 col.itemR(sss, "color_factor", text="Color", slider=True)
358                 col.itemR(sss, "texture_factor", text="Texture", slider=True)
359                 col.itemL(text="Scattering Weight:")
360                 col.itemR(sss, "front")
361                 col.itemR(sss, "back")
362                 
363                 col = split.column()
364                 sub = col.column(align=True)
365                 sub.itemR(sss, "ior")
366                 sub.itemR(sss, "scale")
367                 col.itemR(sss, "radius", text="RGB Radius")
368                 col.itemR(sss, "error_tolerance")
369
370 class MATERIAL_PT_raymir(MaterialButtonsPanel):
371         __label__ = "Ray Mirror"
372         __default_closed__ = True
373         COMPAT_ENGINES = set(['BLENDER_RENDER'])
374         
375         def poll(self, context):
376                 mat = context.material
377                 return mat and (mat.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
378         
379         def draw_header(self, context):
380                 layout = self.layout
381                 
382                 raym = context.material.raytrace_mirror
383
384                 layout.itemR(raym, "enabled", text="")
385         
386         def draw(self, context):
387                 layout = self.layout
388                 
389                 mat = context.material
390                 raym = context.material.raytrace_mirror
391                 
392                 layout.active = raym.enabled
393                 
394                 split = layout.split()
395                 
396                 col = split.column()
397                 col.itemR(raym, "reflect", text="Reflectivity", slider=True)
398                 col.itemR(mat, "mirror_color", text="")
399                 col.itemL(text="Fresnel:")
400                 col.itemR(raym, "fresnel", text="Amount")
401                 sub = col.column()
402                 sub.active = raym.fresnel > 0
403                 sub.itemR(raym, "fresnel_fac", text="Blend", slider=True)
404                 col.itemS()
405                 col.itemS()
406                 sub = col.split(percentage=0.4)
407                 sub.itemL(text="Fade To:")
408                 sub.itemR(raym, "fade_to", text="")
409                 
410                 col = split.column()
411                 col.itemR(raym, "depth")
412                 col.itemR(raym, "distance", text="Max Dist")
413                 col.itemL(text="Gloss:")
414                 col.itemR(raym, "gloss", text="Amount", slider=True)
415                 sub = col.column()
416                 sub.active = raym.gloss < 1
417                 sub.itemR(raym, "gloss_threshold", slider=True, text="Threshold")
418                 sub.itemR(raym, "gloss_samples", text="Samples")
419                 sub.itemR(raym, "gloss_anisotropic", slider=True, text="Anisotropic")
420                 
421                 
422 class MATERIAL_PT_raytransp(MaterialButtonsPanel):
423         __label__= "Ray Transparency"
424         __default_closed__ = True
425         COMPAT_ENGINES = set(['BLENDER_RENDER'])
426                 
427         def poll(self, context):
428                 mat = context.material
429                 return mat and (mat.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
430
431         def draw_header(self, context):
432                 layout = self.layout
433                 
434                 rayt = context.material.raytrace_transparency
435
436                 layout.itemR(rayt, "enabled", text="")
437
438         def draw(self, context):
439                 layout = self.layout
440                 
441                 mat = context.material
442                 rayt = context.material.raytrace_transparency
443                 
444                 layout.active = rayt.enabled and (not mat.shadeless)
445                 
446                 split = layout.split()
447                 
448                 col = split.column()
449                 col.itemR(rayt, "ior")
450                 col.itemR(rayt, "falloff")
451                 col.itemR(rayt, "limit")
452                 
453                 col = split.column()
454                 col.itemR(rayt, "depth")
455                 col.itemR(rayt, "filter", slider=True)
456                 col.itemR(rayt, "specular_opacity", slider=True, text="Spec Opacity")
457                 
458                 split = layout.split()
459                 
460                 col = split.column()
461                 col.itemL(text="Fresnel:")
462                 col.itemR(rayt, "fresnel", text="Amount")
463                 sub = col.column()
464                 sub.active = rayt.fresnel > 0
465                 sub.itemR(rayt, "fresnel_fac", text="Blend", slider=True)
466                 
467                 col = split.column()
468                 col.itemL(text="Gloss:")
469                 col.itemR(rayt, "gloss", text="Amount", slider=True)
470                 sub = col.column()
471                 sub.active = rayt.gloss < 1
472                 sub.itemR(rayt, "gloss_threshold", slider=True, text="Threshold")
473                 sub.itemR(rayt, "gloss_samples", text="Samples")
474                 
475 class MATERIAL_PT_halo(MaterialButtonsPanel):
476         __label__= "Halo"
477         COMPAT_ENGINES = set(['BLENDER_RENDER'])
478         
479         def poll(self, context):
480                 mat = context.material
481                 return mat and (mat.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
482         
483         def draw(self, context):
484                 layout = self.layout
485                 
486                 mat = context.material
487                 halo = mat.halo
488
489                 split = layout.split()
490                 
491                 col = split.column()
492                 col.itemR(mat, "diffuse_color", text="")
493                 col.itemR(halo, "size")
494                 col.itemR(halo, "hardness")
495                 col.itemR(halo, "add", slider=True)
496                 col.itemL(text="Options:")
497                 col.itemR(halo, "use_texture", text="Texture")
498                 col.itemR(halo, "use_vertex_normal", text="Vertex Normal")
499                 col.itemR(halo, "xalpha")
500                 col.itemR(halo, "shaded")
501                 col.itemR(halo, "soft")
502
503                 col = split.column()
504                 col.itemR(halo, "ring")
505                 sub = col.column()
506                 sub.active = halo.ring
507                 sub.itemR(halo, "rings")
508                 sub.itemR(mat, "mirror_color", text="")
509                 col.itemR(halo, "lines")
510                 sub = col.column()
511                 sub.active = halo.lines
512                 sub.itemR(halo, "line_number", text="Lines")
513                 sub.itemR(mat, "specular_color", text="")
514                 col.itemR(halo, "star")
515                 sub = col.column()
516                 sub.active = halo.star
517                 sub.itemR(halo, "star_tips")
518                 col.itemR(halo, "flare_mode")
519                 sub = col.column()
520                 sub.active = halo.flare_mode
521                 sub.itemR(halo, "flare_size", text="Size")
522                 sub.itemR(halo, "flare_subsize", text="Subsize")
523                 sub.itemR(halo, "flare_boost", text="Boost")
524                 sub.itemR(halo, "flare_seed", text="Seed")
525                 sub.itemR(halo, "flares_sub", text="Sub")
526
527 bpy.types.register(MATERIAL_PT_context_material)
528 bpy.types.register(MATERIAL_PT_preview)
529 bpy.types.register(MATERIAL_PT_material)
530 bpy.types.register(MATERIAL_PT_diffuse)
531 bpy.types.register(MATERIAL_PT_specular)
532 bpy.types.register(MATERIAL_PT_raymir)
533 bpy.types.register(MATERIAL_PT_raytransp)
534 bpy.types.register(MATERIAL_PT_sss)
535 bpy.types.register(MATERIAL_PT_halo)
536 bpy.types.register(MATERIAL_PT_physics)
537 bpy.types.register(MATERIAL_PT_strand)
538 bpy.types.register(MATERIAL_PT_options)
539 bpy.types.register(MATERIAL_PT_shadows)