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