svn merge -r 22423:22450 https://svn.blender.org/svnroot/bf-blender/branches/blender2...
[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']:
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 poll(self, context):
110                 return context.material.type in ['SURFACE', 'WIRE', 'HALO']
111         
112         def draw(self, context):
113                 layout = self.layout
114                 
115                 mat = context.material
116                 tan = mat.strand
117                 
118                 split = layout.split()
119                 
120                 col = split.column()
121                 col.itemL(text="Size:")
122                 col.itemR(tan, "start_size", text="Root")
123                 col.itemR(tan, "end_size", text="Tip")
124                 col.itemR(tan, "min_size", text="Minimum")
125                 col.itemR(tan, "blender_units")
126                 sub = col.column()
127                 sub.active = (not mat.shadeless)
128                 sub.itemR(tan, "tangent_shading")
129                 
130                 col = split.column()
131                 col.itemR(tan, "shape")
132                 col.itemR(tan, "width_fade")
133                 col.itemR(tan, "uv_layer")
134                 sub = col.column()
135                 sub.active = (not mat.shadeless)
136                 sub.itemR(tan, "surface_diffuse")
137                 sub = col.column()
138                 sub.active = tan.surface_diffuse
139                 sub.itemR(tan, "blend_distance", text="Distance")
140                 
141 class MATERIAL_PT_physics(MaterialButtonsPanel):
142         __label__ = "Physics"
143         COMPAT_ENGINES = set(['BLENDER_GAME'])
144         
145         def draw(self, context):
146                 layout = self.layout
147                 
148                 mat = context.material
149                 phys = mat.physics
150                 
151                 split = layout.split()
152                 
153                 col = split.column()
154                 col.itemR(phys, "distance")
155                 col.itemR(phys, "friction")
156                 col.itemR(phys, "align_to_normal")
157                 
158                 col = split.column()
159                 col.itemR(phys, "force", slider=True)
160                 col.itemR(phys, "elasticity", slider=True)
161                 col.itemR(phys, "damp", slider=True)
162                 
163 class MATERIAL_PT_options(MaterialButtonsPanel):
164         __label__ = "Options"
165         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
166
167         def poll(self, context):
168                 return (context.material.type in ['SURFACE', 'WIRE', 'HALO'])
169
170         def draw(self, context):
171                 layout = self.layout
172                 
173                 mat = context.material
174                 
175                 split = layout.split()
176                 
177                 col = split.column()
178                 col.itemR(mat, "traceable")
179                 col.itemR(mat, "full_oversampling")
180                 col.itemR(mat, "sky")
181                 col.itemR(mat, "exclude_mist")
182                 col.itemR(mat, "invert_z")
183                 sub = col.column(align=True)
184                 sub.itemL(text="Light Group:")
185                 sub.itemR(mat, "light_group", text="")
186                 row = sub.row()
187                 row.active = mat.light_group
188                 row.itemR(mat, "light_group_exclusive", text="Exclusive")
189
190                 col = split.column()
191                 col.itemR(mat, "face_texture")
192                 sub = col.column()
193                 sub.active = mat.face_texture
194                 sub.itemR(mat, "face_texture_alpha")
195                 col.itemS()
196                 col.itemR(mat, "vertex_color_paint")
197                 col.itemR(mat, "vertex_color_light")
198                 col.itemR(mat, "object_color")
199
200 class MATERIAL_PT_shadows(MaterialButtonsPanel):
201         __label__ = "Shadows"
202         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
203         
204         def poll(self, context):
205                 return context.material.type in ['SURFACE', 'WIRE']
206
207         def draw(self, context):
208                 layout = self.layout
209                 
210                 mat = context.material
211                 
212                 split = layout.split()
213                 
214                 col = split.column()
215                 col.itemR(mat, "shadows", text="Receive")
216                 col.itemR(mat, "transparent_shadows", text="Receive Transparent")
217                 col.itemR(mat, "only_shadow", text="Shadows Only")
218                 col.itemR(mat, "cast_shadows_only", text="Cast Only")
219                 col.itemR(mat, "shadow_casting_alpha", text="Casting Alpha", slider=True)
220                 
221                 col = split.column()
222                 col.itemR(mat, "cast_buffer_shadows")
223                 sub = col.column()
224                 sub.active = mat.cast_buffer_shadows
225                 sub.itemR(mat, "shadow_buffer_bias", text="Buffer Bias")
226                 col.itemR(mat, "ray_shadow_bias", text="Auto Ray Bias")
227                 sub = col.column()
228                 sub.active = (not mat.ray_shadow_bias)
229                 sub.itemR(mat, "shadow_ray_bias", text="Ray Bias")
230                 
231
232 class MATERIAL_PT_diffuse(MaterialButtonsPanel):
233         __label__ = "Diffuse"
234         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
235
236         def poll(self, context):
237                 mat = context.material
238                 return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
239
240         def draw(self, context):
241                 layout = self.layout
242                 
243                 mat = context.material  
244                 
245                 split = layout.split()
246                 
247                 col = split.column()
248                 col.itemR(mat, "diffuse_color", text="")
249                 sub = col.column()
250                 sub.active = (not mat.shadeless)
251                 sub.itemR(mat, "diffuse_reflection", text="Intensity", slider=True)
252                 
253                 col = split.column()
254                 col.active = (not mat.shadeless)
255                 col.itemR(mat, "diffuse_shader", text="")
256                 col.itemR(mat, "use_diffuse_ramp", text="Ramp")
257                 
258                 col = layout.column()
259                 col.active = (not mat.shadeless)
260                 if mat.diffuse_shader == 'OREN_NAYAR':
261                         col.itemR(mat, "roughness")
262                 elif mat.diffuse_shader == 'MINNAERT':
263                         col.itemR(mat, "darkness")
264                 elif mat.diffuse_shader == 'TOON':
265                         row = col.row()
266                         row.itemR(mat, "diffuse_toon_size", text="Size")
267                         row.itemR(mat, "diffuse_toon_smooth", text="Smooth", slider=True)
268                 elif mat.diffuse_shader == 'FRESNEL':
269                         row = col.row()
270                         row.itemR(mat, "diffuse_fresnel", text="Fresnel")
271                         row.itemR(mat, "diffuse_fresnel_factor", text="Factor")
272                         
273                 if mat.use_diffuse_ramp:
274                         layout.itemS()
275                         layout.template_color_ramp(mat.diffuse_ramp, expand=True)
276                         layout.itemS()
277                         row = layout.row()
278                         split = row.split(percentage=0.3)
279                         split.itemL(text="Input:")
280                         split.itemR(mat, "diffuse_ramp_input", text="")
281                         split = row.split(percentage=0.3)
282                         split.itemL(text="Blend:")
283                         split.itemR(mat, "diffuse_ramp_blend", text="")
284                         
285                 
286 class MATERIAL_PT_specular(MaterialButtonsPanel):
287         __label__ = "Specular"
288         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
289
290         def poll(self, context):
291                 mat = context.material
292                 return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
293
294         def draw(self, context):
295                 layout = self.layout
296                 
297                 mat = context.material
298                 
299                 layout.active = (not mat.shadeless)
300                 
301                 split = layout.split()
302                 
303                 col = split.column()
304                 col.itemR(mat, "specular_color", text="")
305                 col.itemR(mat, "specular_reflection", text="Intensity", slider=True)
306
307                 col = split.column()
308                 col.itemR(mat, "specular_shader", text="")
309                 col.itemR(mat, "use_specular_ramp", text="Ramp")
310
311                 col = layout.column()
312                 if mat.specular_shader in ('COOKTORR', 'PHONG'):
313                         col.itemR(mat, "specular_hardness", text="Hardness")
314                 elif mat.specular_shader == 'BLINN':
315                         row = col.row()
316                         row.itemR(mat, "specular_hardness", text="Hardness")
317                         row.itemR(mat, "specular_ior", text="IOR")
318                 elif mat.specular_shader == 'WARDISO':
319                         col.itemR(mat, "specular_slope", text="Slope")
320                 elif mat.specular_shader == 'TOON':
321                         row = col.row()
322                         row.itemR(mat, "specular_toon_size", text="Size")
323                         row.itemR(mat, "specular_toon_smooth", text="Smooth", slider=True)
324                 
325                 if mat.use_specular_ramp:
326                         layout.itemS()
327                         layout.template_color_ramp(mat.specular_ramp, expand=True)
328                         layout.itemS()
329                         row = layout.row()
330                         split = row.split(percentage=0.3)
331                         split.itemL(text="Input:")
332                         split.itemR(mat, "specular_ramp_input", text="")
333                         split = row.split(percentage=0.3)
334                         split.itemL(text="Blend:")
335                         split.itemR(mat, "specular_ramp_blend", text="")
336                 
337 class MATERIAL_PT_sss(MaterialButtonsPanel):
338         __label__ = "Subsurface Scattering"
339         __default_closed__ = True
340         COMPAT_ENGINES = set(['BLENDER_RENDER'])
341         
342         def poll(self, context):
343                 mat = context.material
344                 return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
345
346         def draw_header(self, context):
347                 layout = self.layout
348                 sss = context.material.subsurface_scattering
349
350                 layout.itemR(sss, "enabled", text="")
351         
352         def draw(self, context):
353                 layout = self.layout
354                 
355                 mat = context.material
356                 sss = context.material.subsurface_scattering
357
358                 layout.active = sss.enabled     
359                 
360                 split = layout.split()
361                 split.active = (not mat.shadeless)
362                 
363                 col = split.column(align=True)
364                 col.itemR(sss, "color", text="")
365                 col.itemL(text="Blend:")
366                 col.itemR(sss, "color_factor", text="Color", slider=True)
367                 col.itemR(sss, "texture_factor", text="Texture", slider=True)
368                 col.itemL(text="Scattering Weight:")
369                 col.itemR(sss, "front")
370                 col.itemR(sss, "back")
371                 
372                 col = split.column()
373                 sub = col.column(align=True)
374                 sub.itemR(sss, "ior")
375                 sub.itemR(sss, "scale")
376                 col.itemR(sss, "radius", text="RGB Radius")
377                 col.itemR(sss, "error_tolerance")
378
379 class MATERIAL_PT_raymir(MaterialButtonsPanel):
380         __label__ = "Ray Mirror"
381         __default_closed__ = True
382         COMPAT_ENGINES = set(['BLENDER_RENDER'])
383         
384         def poll(self, context):
385                 mat = context.material
386                 return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
387         
388         def draw_header(self, context):
389                 layout = self.layout
390                 
391                 raym = context.material.raytrace_mirror
392
393                 layout.itemR(raym, "enabled", text="")
394         
395         def draw(self, context):
396                 layout = self.layout
397                 
398                 mat = context.material
399                 raym = context.material.raytrace_mirror
400                 
401                 layout.active = raym.enabled
402                 
403                 split = layout.split()
404                 
405                 col = split.column()
406                 col.itemR(raym, "reflect", text="Reflectivity", slider=True)
407                 col.itemR(mat, "mirror_color", text="")
408                 col.itemL(text="Fresnel:")
409                 col.itemR(raym, "fresnel", text="Amount")
410                 sub = col.column()
411                 sub.active = raym.fresnel > 0
412                 sub.itemR(raym, "fresnel_fac", text="Blend", slider=True)
413                 col.itemS()
414                 col.itemS()
415                 sub = col.split(percentage=0.4)
416                 sub.itemL(text="Fade To:")
417                 sub.itemR(raym, "fade_to", text="")
418                 
419                 col = split.column()
420                 col.itemR(raym, "depth")
421                 col.itemR(raym, "distance", text="Max Dist")
422                 col.itemL(text="Gloss:")
423                 col.itemR(raym, "gloss", text="Amount", slider=True)
424                 sub = col.column()
425                 sub.active = raym.gloss < 1
426                 sub.itemR(raym, "gloss_threshold", slider=True, text="Threshold")
427                 sub.itemR(raym, "gloss_samples", text="Samples")
428                 sub.itemR(raym, "gloss_anisotropic", slider=True, text="Anisotropic")
429                 
430                 
431 class MATERIAL_PT_raytransp(MaterialButtonsPanel):
432         __label__= "Ray Transparency"
433         __default_closed__ = True
434         COMPAT_ENGINES = set(['BLENDER_RENDER'])
435                 
436         def poll(self, context):
437                 mat = context.material
438                 return mat and (mat.type in ['SURFACE', 'WIRE']) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
439
440         def draw_header(self, context):
441                 layout = self.layout
442                 
443                 rayt = context.material.raytrace_transparency
444
445                 layout.itemR(rayt, "enabled", text="")
446
447         def draw(self, context):
448                 layout = self.layout
449                 
450                 mat = context.material
451                 rayt = context.material.raytrace_transparency
452                 
453                 layout.active = rayt.enabled and (not mat.shadeless)
454                 
455                 split = layout.split()
456                 
457                 col = split.column()
458                 col.itemR(rayt, "ior")
459                 col.itemR(rayt, "falloff")
460                 col.itemR(rayt, "limit")
461                 
462                 col = split.column()
463                 col.itemR(rayt, "depth")
464                 col.itemR(rayt, "filter", slider=True)
465                 col.itemR(rayt, "specular_opacity", slider=True, text="Spec Opacity")
466                 
467                 split = layout.split()
468                 
469                 col = split.column()
470                 col.itemL(text="Fresnel:")
471                 col.itemR(rayt, "fresnel", text="Amount")
472                 sub = col.column()
473                 sub.active = rayt.fresnel > 0
474                 sub.itemR(rayt, "fresnel_fac", text="Blend", slider=True)
475                 
476                 col = split.column()
477                 col.itemL(text="Gloss:")
478                 col.itemR(rayt, "gloss", text="Amount", slider=True)
479                 sub = col.column()
480                 sub.active = rayt.gloss < 1
481                 sub.itemR(rayt, "gloss_threshold", slider=True, text="Threshold")
482                 sub.itemR(rayt, "gloss_samples", text="Samples")
483
484 class MATERIAL_PT_volume(MaterialButtonsPanel):
485         __label__ = "Volume"
486         __default_closed__ = False
487         COMPAT_ENGINES = set(['BLENDER_RENDER'])
488         
489         def poll(self, context):
490                 return (context.material.type == 'VOLUME') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
491         
492         def draw(self, context):
493                 layout = self.layout
494                 
495                 mat = context.material
496                 vol = context.material.volume
497                 
498                 split = layout.split()
499                 
500                 col = split.column()
501                 col.itemR(vol, "step_calculation")
502                 col.itemR(vol, "step_size")
503                 col.itemR(vol, "shading_step_size")
504                 
505                 col.itemR(mat, "alpha", text="Density", slider=True)
506                 
507                 col.itemR(vol, "scattering_mode")
508                 if vol.scattering_mode == 'SINGLE':
509                         col.itemR(vol, "light_cache")
510                         sub = col.column()
511                         sub.active = vol.light_cache
512                         col.itemR(vol, "cache_resolution")
513                 elif vol.scattering_mode in ['MULTIPLE', 'SINGLE_PLUS_MULTIPLE']:
514                         col.itemR(vol, "cache_resolution")
515                         col.itemR(vol, "ms_diffusion")
516                         col.itemR(vol, "ms_spread")
517                         col.itemR(vol, "ms_intensity")
518                         
519                 col.itemR(vol, "density_scale")
520                 col.itemR(vol, "depth_cutoff")
521                 
522                 col = split.column()
523                 col.itemR(vol, "absorption")
524                 col.itemR(vol, "absorption_color")
525                 col.itemR(vol, "scattering")
526                 
527                 col.itemR(mat, "emit")
528                 col.itemR(mat, "diffuse_color")
529                 
530                 col.itemR(vol, "phase_function")
531                 col.itemR(vol, "asymmetry")
532                 
533
534
535 class MATERIAL_PT_halo(MaterialButtonsPanel):
536         __label__= "Halo"
537         COMPAT_ENGINES = set(['BLENDER_RENDER'])
538         
539         def poll(self, context):
540                 mat = context.material
541                 return mat and (mat.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
542         
543         def draw(self, context):
544                 layout = self.layout
545                 
546                 mat = context.material
547                 halo = mat.halo
548
549                 split = layout.split()
550                 
551                 col = split.column()
552                 col.itemR(mat, "diffuse_color", text="")
553                 col.itemR(halo, "size")
554                 col.itemR(halo, "hardness")
555                 col.itemR(halo, "add", slider=True)
556                 col.itemL(text="Options:")
557                 col.itemR(halo, "use_texture", text="Texture")
558                 col.itemR(halo, "use_vertex_normal", text="Vertex Normal")
559                 col.itemR(halo, "xalpha")
560                 col.itemR(halo, "shaded")
561                 col.itemR(halo, "soft")
562
563                 col = split.column()
564                 col.itemR(halo, "ring")
565                 sub = col.column()
566                 sub.active = halo.ring
567                 sub.itemR(halo, "rings")
568                 sub.itemR(mat, "mirror_color", text="")
569                 col.itemR(halo, "lines")
570                 sub = col.column()
571                 sub.active = halo.lines
572                 sub.itemR(halo, "line_number", text="Lines")
573                 sub.itemR(mat, "specular_color", text="")
574                 col.itemR(halo, "star")
575                 sub = col.column()
576                 sub.active = halo.star
577                 sub.itemR(halo, "star_tips")
578                 col.itemR(halo, "flare_mode")
579                 sub = col.column()
580                 sub.active = halo.flare_mode
581                 sub.itemR(halo, "flare_size", text="Size")
582                 sub.itemR(halo, "flare_subsize", text="Subsize")
583                 sub.itemR(halo, "flare_boost", text="Boost")
584                 sub.itemR(halo, "flare_seed", text="Seed")
585                 sub.itemR(halo, "flares_sub", text="Sub")
586
587 bpy.types.register(MATERIAL_PT_context_material)
588 bpy.types.register(MATERIAL_PT_preview)
589 bpy.types.register(MATERIAL_PT_material)
590 bpy.types.register(MATERIAL_PT_diffuse)
591 bpy.types.register(MATERIAL_PT_specular)
592 bpy.types.register(MATERIAL_PT_raymir)
593 bpy.types.register(MATERIAL_PT_raytransp)
594 bpy.types.register(MATERIAL_PT_sss)
595 bpy.types.register(MATERIAL_PT_volume)
596 bpy.types.register(MATERIAL_PT_halo)
597 bpy.types.register(MATERIAL_PT_physics)
598 bpy.types.register(MATERIAL_PT_strand)
599 bpy.types.register(MATERIAL_PT_options)
600 bpy.types.register(MATERIAL_PT_shadows)