056bd5d6c10a929719f1bebbf17638b4ff51e703
[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, "ray_shadow_bias", text="Auto Ray Bias")
214                 sub = col.column()
215                 subsub = sub.column()
216                 subsub.active = (not mat.ray_shadow_bias)
217                 subsub.itemR(mat, "shadow_ray_bias", text="Ray Shadow Bias")
218                 sub.itemR(mat, "cast_buffer_shadows")
219                 sub.itemR(mat, "shadow_buffer_bias", text="Buffer Bias")
220
221 class MATERIAL_PT_diffuse(MaterialButtonsPanel):
222         __label__ = "Diffuse"
223         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
224
225         def poll(self, context):
226                 mat = context.material
227                 return mat and (mat.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
228
229         def draw(self, context):
230                 layout = self.layout
231                 
232                 mat = context.material  
233                 
234                 split = layout.split()
235                 
236                 col = split.column()
237                 col.itemR(mat, "diffuse_color", text="")
238                 sub = col.column()
239                 sub.active = (not mat.shadeless)
240                 sub.itemR(mat, "diffuse_reflection", text="Intensity", slider=True)
241                 
242                 col = split.column()
243                 col.active = (not mat.shadeless)
244                 col.itemR(mat, "diffuse_shader", text="")
245                 col.itemR(mat, "use_diffuse_ramp", text="Ramp")
246                 
247                 col = layout.column()
248                 col.active = (not mat.shadeless)
249                 if mat.diffuse_shader == 'OREN_NAYAR':
250                         col.itemR(mat, "roughness")
251                 elif mat.diffuse_shader == 'MINNAERT':
252                         col.itemR(mat, "darkness")
253                 elif mat.diffuse_shader == 'TOON':
254                         row = col.row()
255                         row.itemR(mat, "diffuse_toon_size", text="Size")
256                         row.itemR(mat, "diffuse_toon_smooth", text="Smooth", slider=True)
257                 elif mat.diffuse_shader == 'FRESNEL':
258                         row = col.row()
259                         row.itemR(mat, "diffuse_fresnel", text="Fresnel")
260                         row.itemR(mat, "diffuse_fresnel_factor", text="Factor")
261                         
262                 if mat.use_diffuse_ramp:
263                         layout.itemS()
264                         layout.template_color_ramp(mat.diffuse_ramp, expand=True)
265                         layout.itemS()
266                         row = layout.row()
267                         split = row.split(percentage=0.3)
268                         split.itemL(text="Input:")
269                         split.itemR(mat, "diffuse_ramp_input", text="")
270                         split = row.split(percentage=0.3)
271                         split.itemL(text="Blend:")
272                         split.itemR(mat, "diffuse_ramp_blend", text="")
273                         
274                 
275 class MATERIAL_PT_specular(MaterialButtonsPanel):
276         __label__ = "Specular"
277         COMPAT_ENGINES = set(['BLENDER_RENDER', 'BLENDER_GAME'])
278
279         def poll(self, context):
280                 mat = context.material
281                 return mat and (mat.type != 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
282
283         def draw(self, context):
284                 layout = self.layout
285                 
286                 mat = context.material
287                 
288                 layout.active = (not mat.shadeless)
289                 
290                 split = layout.split()
291                 
292                 col = split.column()
293                 col.itemR(mat, "specular_color", text="")
294                 col.itemR(mat, "specular_reflection", text="Intensity", slider=True)
295
296                 col = split.column()
297                 col.itemR(mat, "specular_shader", text="")
298                 col.itemR(mat, "use_specular_ramp", text="Ramp")
299
300                 col = layout.column()
301                 if mat.specular_shader in ('COOKTORR', 'PHONG'):
302                         col.itemR(mat, "specular_hardness", text="Hardness")
303                 elif mat.specular_shader == 'BLINN':
304                         row = col.row()
305                         row.itemR(mat, "specular_hardness", text="Hardness")
306                         row.itemR(mat, "specular_ior", text="IOR")
307                 elif mat.specular_shader == 'WARDISO':
308                         col.itemR(mat, "specular_slope", text="Slope")
309                 elif mat.specular_shader == 'TOON':
310                         row = col.row()
311                         row.itemR(mat, "specular_toon_size", text="Size")
312                         row.itemR(mat, "specular_toon_smooth", text="Smooth", slider=True)
313                 
314                 if mat.use_specular_ramp:
315                         layout.itemS()
316                         layout.template_color_ramp(mat.specular_ramp, expand=True)
317                         layout.itemS()
318                         row = layout.row()
319                         split = row.split(percentage=0.3)
320                         split.itemL(text="Input:")
321                         split.itemR(mat, "specular_ramp_input", text="")
322                         split = row.split(percentage=0.3)
323                         split.itemL(text="Blend:")
324                         split.itemR(mat, "specular_ramp_blend", text="")
325                 
326 class MATERIAL_PT_sss(MaterialButtonsPanel):
327         __label__ = "Subsurface Scattering"
328         __default_closed__ = True
329         COMPAT_ENGINES = set(['BLENDER_RENDER'])
330         
331         def poll(self, context):
332                 mat = context.material
333                 return mat and (mat.type in ('SURFACE', 'WIRE')) and (context.scene.render_data.engine in self.COMPAT_ENGINES)
334
335         def draw_header(self, context):
336                 layout = self.layout
337                 sss = context.material.subsurface_scattering
338
339                 layout.itemR(sss, "enabled", text="")
340         
341         def draw(self, context):
342                 layout = self.layout
343                 
344                 mat = context.material
345                 sss = context.material.subsurface_scattering
346
347                 layout.active = sss.enabled     
348                 
349                 split = layout.split()
350                 split.active = (not mat.shadeless)
351                 
352                 col = split.column(align=True)
353                 col.itemR(sss, "color", text="")
354                 col.itemL(text="Blend:")
355                 col.itemR(sss, "color_factor", text="Color", slider=True)
356                 col.itemR(sss, "texture_factor", text="Texture", slider=True)
357                 col.itemL(text="Scattering Weight:")
358                 col.itemR(sss, "front")
359                 col.itemR(sss, "back")
360                 
361                 col = split.column()
362                 sub = col.column(align=True)
363                 sub.itemR(sss, "ior")
364                 sub.itemR(sss, "scale")
365                 col.itemR(sss, "radius", text="RGB Radius")
366                 col.itemR(sss, "error_tolerance")
367
368 class MATERIAL_PT_raymir(MaterialButtonsPanel):
369         __label__ = "Ray Mirror"
370         __default_closed__ = True
371         COMPAT_ENGINES = set(['BLENDER_RENDER'])
372         
373         def poll(self, context):
374                 mat = context.material
375                 return mat and (mat.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
376         
377         def draw_header(self, context):
378                 layout = self.layout
379                 
380                 raym = context.material.raytrace_mirror
381
382                 layout.itemR(raym, "enabled", text="")
383         
384         def draw(self, context):
385                 layout = self.layout
386                 
387                 mat = context.material
388                 raym = context.material.raytrace_mirror
389                 
390                 layout.active = raym.enabled
391                 
392                 split = layout.split()
393                 
394                 col = split.column()
395                 col.itemR(raym, "reflect", text="Reflectivity", slider=True)
396                 col.itemR(mat, "mirror_color", text="")
397                 col.itemL(text="Fresnel:")
398                 col.itemR(raym, "fresnel", text="Amount")
399                 sub = col.column()
400                 sub.active = raym.fresnel > 0
401                 sub.itemR(raym, "fresnel_fac", text="Blend", slider=True)
402                 col.itemS()
403                 col.itemS()
404                 sub = col.split(percentage=0.4)
405                 sub.itemL(text="Fade To:")
406                 sub.itemR(raym, "fade_to", text="")
407                 
408                 col = split.column()
409                 col.itemR(raym, "depth")
410                 col.itemR(raym, "distance", text="Max Dist")
411                 col.itemL(text="Gloss:")
412                 col.itemR(raym, "gloss", text="Amount", slider=True)
413                 sub = col.column()
414                 sub.active = raym.gloss < 1
415                 sub.itemR(raym, "gloss_threshold", slider=True, text="Threshold")
416                 sub.itemR(raym, "gloss_samples", text="Samples")
417                 sub.itemR(raym, "gloss_anisotropic", slider=True, text="Anisotropic")
418                 
419                 
420 class MATERIAL_PT_raytransp(MaterialButtonsPanel):
421         __label__= "Ray Transparency"
422         __default_closed__ = True
423         COMPAT_ENGINES = set(['BLENDER_RENDER'])
424                 
425         def poll(self, context):
426                 mat = context.material
427                 return mat and (mat.type in 'SURFACE', 'WIRE') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
428
429         def draw_header(self, context):
430                 layout = self.layout
431                 
432                 rayt = context.material.raytrace_transparency
433
434                 layout.itemR(rayt, "enabled", text="")
435
436         def draw(self, context):
437                 layout = self.layout
438                 
439                 mat = context.material
440                 rayt = context.material.raytrace_transparency
441                 
442                 layout.active = rayt.enabled and (not mat.shadeless)
443                 
444                 split = layout.split()
445                 
446                 col = split.column()
447                 col.itemR(rayt, "ior")
448                 col.itemR(rayt, "falloff")
449                 col.itemR(rayt, "limit")
450                 
451                 col = split.column()
452                 col.itemR(rayt, "depth")
453                 col.itemR(rayt, "filter", slider=True)
454                 col.itemR(rayt, "specular_opacity", slider=True, text="Spec Opacity")
455                 
456                 split = layout.split()
457                 
458                 col = split.column()
459                 col.itemL(text="Fresnel:")
460                 col.itemR(rayt, "fresnel", text="Amount")
461                 sub = col.column()
462                 sub.active = rayt.fresnel > 0
463                 sub.itemR(rayt, "fresnel_fac", text="Blend", slider=True)
464                 
465                 col = split.column()
466                 col.itemL(text="Gloss:")
467                 col.itemR(rayt, "gloss", text="Amount", slider=True)
468                 sub = col.column()
469                 sub.active = rayt.gloss < 1
470                 sub.itemR(rayt, "gloss_threshold", slider=True, text="Threshold")
471                 sub.itemR(rayt, "gloss_samples", text="Samples")
472                 
473 class MATERIAL_PT_halo(MaterialButtonsPanel):
474         __label__= "Halo"
475         COMPAT_ENGINES = set(['BLENDER_RENDER'])
476         
477         def poll(self, context):
478                 mat = context.material
479                 return mat and (mat.type == 'HALO') and (context.scene.render_data.engine in self.COMPAT_ENGINES)
480         
481         def draw(self, context):
482                 layout = self.layout
483                 
484                 mat = context.material
485                 halo = mat.halo
486
487                 split = layout.split()
488                 
489                 col = split.column()
490                 col.itemR(mat, "diffuse_color", text="")
491                 col.itemR(halo, "size")
492                 col.itemR(halo, "hardness")
493                 col.itemR(halo, "add", slider=True)
494                 col.itemL(text="Options:")
495                 col.itemR(halo, "use_texture", text="Texture")
496                 col.itemR(halo, "use_vertex_normal", text="Vertex Normal")
497                 col.itemR(halo, "xalpha")
498                 col.itemR(halo, "shaded")
499                 col.itemR(halo, "soft")
500
501                 col = split.column()
502                 col.itemR(halo, "ring")
503                 sub = col.column()
504                 sub.active = halo.ring
505                 sub.itemR(halo, "rings")
506                 sub.itemR(mat, "mirror_color", text="")
507                 col.itemR(halo, "lines")
508                 sub = col.column()
509                 sub.active = halo.lines
510                 sub.itemR(halo, "line_number", text="Lines")
511                 sub.itemR(mat, "specular_color", text="")
512                 col.itemR(halo, "star")
513                 sub = col.column()
514                 sub.active = halo.star
515                 sub.itemR(halo, "star_tips")
516                 col.itemR(halo, "flare_mode")
517                 sub = col.column()
518                 sub.active = halo.flare_mode
519                 sub.itemR(halo, "flare_size", text="Size")
520                 sub.itemR(halo, "flare_subsize", text="Subsize")
521                 sub.itemR(halo, "flare_boost", text="Boost")
522                 sub.itemR(halo, "flare_seed", text="Seed")
523                 sub.itemR(halo, "flares_sub", text="Sub")
524
525 bpy.types.register(MATERIAL_PT_context_material)
526 bpy.types.register(MATERIAL_PT_preview)
527 bpy.types.register(MATERIAL_PT_material)
528 bpy.types.register(MATERIAL_PT_diffuse)
529 bpy.types.register(MATERIAL_PT_specular)
530 bpy.types.register(MATERIAL_PT_raymir)
531 bpy.types.register(MATERIAL_PT_raytransp)
532 bpy.types.register(MATERIAL_PT_sss)
533 bpy.types.register(MATERIAL_PT_halo)
534 bpy.types.register(MATERIAL_PT_physics)
535 bpy.types.register(MATERIAL_PT_strand)
536 bpy.types.register(MATERIAL_PT_options)
537 bpy.types.register(MATERIAL_PT_shadows)