542262000b689eb5325e7c9eb74c53d00b0f20f1
[blender.git] / intern / cycles / blender / addon / ui.py
1 #
2 # Copyright 2011, Blender Foundation.
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18
19 # <pep8 compliant>
20
21 import bpy
22
23 from bpy.types import Panel, Menu
24
25
26 class CYCLES_MT_integrator_presets(Menu):
27     bl_label = "Integrator Presets"
28     preset_subdir = "cycles/integrator"
29     preset_operator = "script.execute_preset"
30     COMPAT_ENGINES = {'CYCLES'}
31     draw = Menu.draw_preset
32
33
34 class CyclesButtonsPanel():
35     bl_space_type = "PROPERTIES"
36     bl_region_type = "WINDOW"
37     bl_context = "render"
38
39     @classmethod
40     def poll(cls, context):
41         rd = context.scene.render
42         return rd.engine == 'CYCLES'
43
44
45 class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel):
46     bl_label = "Sampling"
47     bl_options = {'DEFAULT_CLOSED'}
48
49     def draw(self, context):
50         layout = self.layout
51
52         scene = context.scene
53         cscene = scene.cycles
54         device_type = context.user_preferences.system.compute_device_type
55
56         split = layout.split()
57
58         col = split.column()
59         sub = col.column()
60         sub.active = (device_type == 'NONE' or cscene.device == 'CPU')
61         sub.prop(cscene, "progressive")
62
63         sub = col.column(align=True)
64         sub.prop(cscene, "seed")
65         sub.prop(cscene, "sample_clamp")
66
67         if cscene.progressive or (device_type != 'NONE' and cscene.device == 'GPU'):
68             col = split.column()
69             col.label(text="Samples:")
70             sub = col.column(align=True)
71             sub.prop(cscene, "samples", text="Render")
72             sub.prop(cscene, "preview_samples", text="Preview")
73         else:
74             sub.label(text="AA Samples:")
75             sub.prop(cscene, "aa_samples", text="Render")
76             sub.prop(cscene, "preview_aa_samples", text="Preview")
77
78             col = split.column()
79             col.label(text="Samples:")
80             sub = col.column(align=True)
81             sub.prop(cscene, "diffuse_samples", text="Diffuse")
82             sub.prop(cscene, "glossy_samples", text="Glossy")
83             sub.prop(cscene, "transmission_samples", text="Transmission")
84             sub.prop(cscene, "ao_samples", text="AO")
85             sub.prop(cscene, "mesh_light_samples", text="Mesh Light")
86
87
88 class CyclesRender_PT_light_paths(CyclesButtonsPanel, Panel):
89     bl_label = "Light Paths"
90     bl_options = {'DEFAULT_CLOSED'}
91
92     def draw(self, context):
93         layout = self.layout
94
95         scene = context.scene
96         cscene = scene.cycles
97
98         row = layout.row(align=True)
99         row.menu("CYCLES_MT_integrator_presets", text=bpy.types.CYCLES_MT_integrator_presets.bl_label)
100         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMIN")
101         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMOUT").remove_active = True
102
103         split = layout.split()
104
105         col = split.column()
106
107         sub = col.column(align=True)
108         sub.label("Transparency:")
109         sub.prop(cscene, "transparent_max_bounces", text="Max")
110         sub.prop(cscene, "transparent_min_bounces", text="Min")
111         sub.prop(cscene, "use_transparent_shadows", text="Shadows")
112
113         col.separator()
114
115         col.prop(cscene, "no_caustics")
116         col.prop(cscene, "blur_glossy")
117
118         col = split.column()
119
120         sub = col.column(align=True)
121         sub.label(text="Bounces:")
122         sub.prop(cscene, "max_bounces", text="Max")
123         sub.prop(cscene, "min_bounces", text="Min")
124
125         sub = col.column(align=True)
126         sub.prop(cscene, "diffuse_bounces", text="Diffuse")
127         sub.prop(cscene, "glossy_bounces", text="Glossy")
128         sub.prop(cscene, "transmission_bounces", text="Transmission")
129
130
131 class CyclesRender_PT_motion_blur(CyclesButtonsPanel, Panel):
132     bl_label = "Motion Blur"
133     bl_options = {'DEFAULT_CLOSED'}
134
135     def draw_header(self, context):
136         rd = context.scene.render
137
138         self.layout.prop(rd, "use_motion_blur", text="")
139
140     def draw(self, context):
141         layout = self.layout
142
143         rd = context.scene.render
144         layout.active = rd.use_motion_blur
145
146         row = layout.row()
147         row.prop(rd, "motion_blur_shutter")
148
149
150 class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
151     bl_label = "Film"
152
153     def draw(self, context):
154         layout = self.layout
155
156         scene = context.scene
157         cscene = scene.cycles
158
159         split = layout.split()
160
161         col = split.column()
162         col.prop(cscene, "film_exposure")
163         col.prop(cscene, "film_transparent")
164
165         col = split.column()
166         sub = col.column(align=True)
167         sub.prop(cscene, "filter_type", text="")
168         if cscene.filter_type != 'BOX':
169             sub.prop(cscene, "filter_width", text="Width")
170
171
172 class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
173     bl_label = "Performance"
174     bl_options = {'DEFAULT_CLOSED'}
175
176     def draw(self, context):
177         layout = self.layout
178
179         scene = context.scene
180         rd = scene.render
181         cscene = scene.cycles
182
183         split = layout.split()
184
185         col = split.column(align=True)
186
187         col.label(text="Threads:")
188         col.row().prop(rd, "threads_mode", expand=True)
189         sub = col.column()
190         sub.enabled = rd.threads_mode == 'FIXED'
191         sub.prop(rd, "threads")
192
193         sub = col.column(align=True)
194         sub.label(text="Tiles:")
195         sub.prop(cscene, "tile_order", text="")
196
197         sub.prop(rd, "tile_x", text="X")
198         sub.prop(rd, "tile_y", text="Y")
199
200         sub.prop(cscene, "use_progressive_refine")
201
202         subsub = sub.column()
203         subsub.enabled = not rd.use_border
204         subsub.prop(rd, "use_save_buffers")
205
206         col = split.column()
207
208         sub = col.column(align=True)
209         sub.label(text="Acceleration structure:")
210         sub.prop(cscene, "debug_bvh_type", text="")
211         sub.prop(cscene, "debug_use_spatial_splits")
212         sub.prop(cscene, "use_cache")
213
214         sub = col.column(align=True)
215         sub.label(text="Viewport:")
216         sub.prop(cscene, "preview_start_resolution")
217
218         sub = col.column(align=True)
219         sub.label(text="Final Render:")
220         sub.prop(rd, "use_persistent_data", text="Persistent Images")
221
222
223 class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
224     bl_label = "Layers"
225     bl_options = {'DEFAULT_CLOSED'}
226     COMPAT_ENGINES = {'BLENDER_RENDER'}
227
228     def draw(self, context):
229         layout = self.layout
230
231         scene = context.scene
232         rd = scene.render
233
234         row = layout.row()
235         row.template_list("RENDER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
236
237         col = row.column(align=True)
238         col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
239         col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
240
241         row = layout.row()
242         rl = rd.layers.active
243         row.prop(rl, "name")
244         row.prop(rd, "use_single_layer", text="", icon_only=True)
245
246         split = layout.split()
247
248         col = split.column()
249         col.prop(scene, "layers", text="Scene")
250         col.prop(rl, "layers_exclude", text="Exclude")
251
252         col = split.column()
253         col.prop(rl, "layers", text="Layer")
254         col.label(text="Mask Layers:")
255         col.prop(rl, "layers_zmask", text="")
256
257         split = layout.split()
258
259         col = split.column()
260         col.label(text="Material:")
261         col.prop(rl, "material_override", text="")
262
263         col = split.column()
264         col.prop(rl, "samples")
265         col.prop(rl, "use_sky", "Use Environment")
266
267         split = layout.split()
268
269         col = split.column()
270         col.label(text="Passes:")
271         col.prop(rl, "use_pass_combined")
272         col.prop(rl, "use_pass_z")
273         col.prop(rl, "use_pass_normal")
274         col.prop(rl, "use_pass_vector")
275         col.prop(rl, "use_pass_uv")
276         col.prop(rl, "use_pass_object_index")
277         col.prop(rl, "use_pass_material_index")
278         col.prop(rl, "use_pass_ambient_occlusion")
279         col.prop(rl, "use_pass_shadow")
280
281         col = split.column()
282         col.label()
283         col.label(text="Diffuse:")
284         row = col.row(align=True)
285         row.prop(rl, "use_pass_diffuse_direct", text="Direct", toggle=True)
286         row.prop(rl, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
287         row.prop(rl, "use_pass_diffuse_color", text="Color", toggle=True)
288         col.label(text="Glossy:")
289         row = col.row(align=True)
290         row.prop(rl, "use_pass_glossy_direct", text="Direct", toggle=True)
291         row.prop(rl, "use_pass_glossy_indirect", text="Indirect", toggle=True)
292         row.prop(rl, "use_pass_glossy_color", text="Color", toggle=True)
293         col.label(text="Transmission:")
294         row = col.row(align=True)
295         row.prop(rl, "use_pass_transmission_direct", text="Direct", toggle=True)
296         row.prop(rl, "use_pass_transmission_indirect", text="Indirect", toggle=True)
297         row.prop(rl, "use_pass_transmission_color", text="Color", toggle=True)
298
299         col.prop(rl, "use_pass_emit", text="Emission")
300         col.prop(rl, "use_pass_environment")
301
302
303 class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
304     bl_label = "Post Processing"
305     bl_options = {'DEFAULT_CLOSED'}
306
307     def draw(self, context):
308         layout = self.layout
309
310         rd = context.scene.render
311
312         split = layout.split()
313
314         col = split.column()
315         col.prop(rd, "use_compositing")
316         col.prop(rd, "use_sequencer")
317
318         col = split.column()
319         col.prop(rd, "dither_intensity", text="Dither", slider=True)
320
321
322 class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
323     bl_label = "Depth of Field"
324     bl_context = "data"
325
326     @classmethod
327     def poll(cls, context):
328         return context.camera and CyclesButtonsPanel.poll(context)
329
330     def draw(self, context):
331         layout = self.layout
332
333         cam = context.camera
334         ccam = cam.cycles
335
336         split = layout.split()
337
338         col = split.column()
339         col.label("Focus:")
340         col.prop(cam, "dof_object", text="")
341
342         sub = col.row()
343         sub.active = cam.dof_object is None
344         sub.prop(cam, "dof_distance", text="Distance")
345
346         col = split.column()
347
348         col.label("Aperture:")
349         sub = col.column(align=True)
350         sub.prop(ccam, "aperture_type", text="")
351         if ccam.aperture_type == 'RADIUS':
352             sub.prop(ccam, "aperture_size", text="Size")
353         elif ccam.aperture_type == 'FSTOP':
354             sub.prop(ccam, "aperture_fstop", text="Number")
355
356         sub = col.column(align=True)
357         sub.prop(ccam, "aperture_blades", text="Blades")
358         sub.prop(ccam, "aperture_rotation", text="Rotation")
359
360
361 class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
362     bl_label = ""
363     bl_context = "material"
364     bl_options = {'HIDE_HEADER'}
365
366     @classmethod
367     def poll(cls, context):
368         return (context.material or context.object) and CyclesButtonsPanel.poll(context)
369
370     def draw(self, context):
371         layout = self.layout
372
373         mat = context.material
374         ob = context.object
375         slot = context.material_slot
376         space = context.space_data
377
378         if ob:
379             row = layout.row()
380
381             row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=2)
382
383             col = row.column(align=True)
384             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
385             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
386
387             col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
388
389             if ob.mode == 'EDIT':
390                 row = layout.row(align=True)
391                 row.operator("object.material_slot_assign", text="Assign")
392                 row.operator("object.material_slot_select", text="Select")
393                 row.operator("object.material_slot_deselect", text="Deselect")
394
395         split = layout.split(percentage=0.65)
396
397         if ob:
398             split.template_ID(ob, "active_material", new="material.new")
399             row = split.row()
400
401             if slot:
402                 row.prop(slot, "link", text="")
403             else:
404                 row.label()
405         elif mat:
406             split.template_ID(space, "pin_id")
407             split.separator()
408
409
410 class Cycles_PT_mesh_displacement(CyclesButtonsPanel, Panel):
411     bl_label = "Displacement"
412     bl_context = "data"
413
414     @classmethod
415     def poll(cls, context):
416         if CyclesButtonsPanel.poll(context):
417             if context.mesh or context.curve or context.meta_ball:
418                 if context.scene.cycles.feature_set == 'EXPERIMENTAL':
419                     return True
420
421         return False
422
423     def draw(self, context):
424         layout = self.layout
425
426         mesh = context.mesh
427         curve = context.curve
428         mball = context.meta_ball
429
430         if mesh:
431             cdata = mesh.cycles
432         elif curve:
433             cdata = curve.cycles
434         elif mball:
435             cdata = mball.cycles
436
437         layout.prop(cdata, "displacement_method", text="Method")
438         layout.prop(cdata, "use_subdivision")
439         layout.prop(cdata, "dicing_rate")
440
441
442 class Cycles_PT_mesh_normals(CyclesButtonsPanel, Panel):
443     bl_label = "Normals"
444     bl_context = "data"
445
446     @classmethod
447     def poll(cls, context):
448         return CyclesButtonsPanel.poll(context) and context.mesh
449
450     def draw(self, context):
451         layout = self.layout
452
453         mesh = context.mesh
454
455         split = layout.split()
456
457         col = split.column()
458         col.prop(mesh, "show_double_sided")
459
460         col = split.column()
461         col.label()
462
463
464 class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
465     bl_label = "Ray Visibility"
466     bl_context = "object"
467     bl_options = {'DEFAULT_CLOSED'}
468
469     @classmethod
470     def poll(cls, context):
471         ob = context.object
472         return CyclesButtonsPanel.poll(context) and ob and ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META'}  # todo: 'LAMP'
473
474     def draw(self, context):
475         layout = self.layout
476
477         ob = context.object
478         visibility = ob.cycles_visibility
479
480         flow = layout.column_flow()
481
482         flow.prop(visibility, "camera")
483         flow.prop(visibility, "diffuse")
484         flow.prop(visibility, "glossy")
485         flow.prop(visibility, "transmission")
486         flow.prop(visibility, "shadow")
487
488
489 def find_node(material, nodetype):
490     if material and material.node_tree:
491         ntree = material.node_tree
492
493         for node in ntree.nodes:
494             if getattr(node, "type", None) == nodetype:
495                 return node
496
497     return None
498
499
500 def find_node_input(node, name):
501     for input in node.inputs:
502         if input.name == name:
503             return input
504
505     return None
506
507
508 def panel_node_draw(layout, id_data, output_type, input_name):
509     if not id_data.use_nodes:
510         layout.prop(id_data, "use_nodes", icon='NODETREE')
511         return False
512
513     ntree = id_data.node_tree
514
515     node = find_node(id_data, output_type)
516     if not node:
517         layout.label(text="No output node.")
518     else:
519         input = find_node_input(node, input_name)
520         layout.template_node_view(ntree, node, input)
521
522     return True
523
524
525 class CyclesLamp_PT_preview(CyclesButtonsPanel, Panel):
526     bl_label = "Preview"
527     bl_context = "data"
528     bl_options = {'DEFAULT_CLOSED'}
529
530     @classmethod
531     def poll(cls, context):
532         return context.lamp and CyclesButtonsPanel.poll(context)
533
534     def draw(self, context):
535         self.layout.template_preview(context.lamp)
536
537
538 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
539     bl_label = "Lamp"
540     bl_context = "data"
541
542     @classmethod
543     def poll(cls, context):
544         return context.lamp and CyclesButtonsPanel.poll(context)
545
546     def draw(self, context):
547         layout = self.layout
548
549         lamp = context.lamp
550         clamp = lamp.cycles
551         cscene = context.scene.cycles
552         device_type = context.user_preferences.system.compute_device_type
553
554         layout.prop(lamp, "type", expand=True)
555
556         split = layout.split()
557         col = split.column(align=True)
558
559         if lamp.type in {'POINT', 'SUN', 'SPOT'}:
560             col.prop(lamp, "shadow_soft_size", text="Size")
561         elif lamp.type == 'AREA':
562             col.prop(lamp, "shape", text="")
563             sub = col.column(align=True)
564
565             if lamp.shape == 'SQUARE':
566                 sub.prop(lamp, "size")
567             elif lamp.shape == 'RECTANGLE':
568                 sub.prop(lamp, "size", text="Size X")
569                 sub.prop(lamp, "size_y", text="Size Y")
570
571         if not cscene.progressive and (device_type == 'NONE' or cscene.device == 'CPU'):
572             col.prop(clamp, "samples")
573
574         col = split.column()
575         col.prop(clamp, "cast_shadow")
576
577         layout.prop(clamp, "use_multiple_importance_sampling")
578
579         if lamp.type == 'HEMI':
580             layout.label(text="Not supported, interpreted as sun lamp.")
581
582
583 class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
584     bl_label = "Nodes"
585     bl_context = "data"
586
587     @classmethod
588     def poll(cls, context):
589         return context.lamp and CyclesButtonsPanel.poll(context)
590
591     def draw(self, context):
592         layout = self.layout
593
594         lamp = context.lamp
595         if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
596             layout.prop(lamp, "color")
597
598
599 class CyclesLamp_PT_spot(CyclesButtonsPanel, Panel):
600     bl_label = "Spot Shape"
601     bl_context = "data"
602
603     @classmethod
604     def poll(cls, context):
605         lamp = context.lamp
606         return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context)
607
608     def draw(self, context):
609         layout = self.layout
610
611         lamp = context.lamp
612
613         split = layout.split()
614
615         col = split.column()
616         sub = col.column()
617         sub.prop(lamp, "spot_size", text="Size")
618         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
619
620         col = split.column()
621         col.prop(lamp, "show_cone")
622
623
624 class CyclesWorld_PT_preview(CyclesButtonsPanel, Panel):
625     bl_label = "Preview"
626     bl_context = "world"
627     bl_options = {'DEFAULT_CLOSED'}
628
629     @classmethod
630     def poll(cls, context):
631         return context.world and CyclesButtonsPanel.poll(context)
632
633     def draw(self, context):
634         self.layout.template_preview(context.world)
635
636
637 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
638     bl_label = "Surface"
639     bl_context = "world"
640
641     @classmethod
642     def poll(cls, context):
643         return context.world and CyclesButtonsPanel.poll(context)
644
645     def draw(self, context):
646         layout = self.layout
647
648         world = context.world
649
650         if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
651             layout.prop(world, "horizon_color", text="Color")
652
653
654 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
655     bl_label = "Volume"
656     bl_context = "world"
657     bl_options = {'DEFAULT_CLOSED'}
658
659     @classmethod
660     def poll(cls, context):
661         # world = context.world
662         # world and world.node_tree and CyclesButtonsPanel.poll(context)
663         return False
664
665     def draw(self, context):
666         layout = self.layout
667         layout.active = False
668
669         world = context.world
670         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
671
672
673 class CyclesWorld_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
674     bl_label = "Ambient Occlusion"
675     bl_context = "world"
676
677     @classmethod
678     def poll(cls, context):
679         return context.world and CyclesButtonsPanel.poll(context)
680
681     def draw_header(self, context):
682         light = context.world.light_settings
683         self.layout.prop(light, "use_ambient_occlusion", text="")
684
685     def draw(self, context):
686         layout = self.layout
687         light = context.world.light_settings
688
689         layout.active = light.use_ambient_occlusion
690
691         row = layout.row()
692         row.prop(light, "ao_factor", text="Factor")
693         row.prop(light, "distance", text="Distance")
694
695
696 class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
697     bl_label = "Settings"
698     bl_context = "world"
699     bl_options = {'DEFAULT_CLOSED'}
700
701     @classmethod
702     def poll(cls, context):
703         return context.world and CyclesButtonsPanel.poll(context)
704
705     def draw(self, context):
706         layout = self.layout
707
708         world = context.world
709         cworld = world.cycles
710         cscene = context.scene.cycles
711         device_type = context.user_preferences.system.compute_device_type
712
713         col = layout.column()
714
715         col.prop(cworld, "sample_as_light")
716         sub = col.row(align=True)
717         sub.active = cworld.sample_as_light
718         sub.prop(cworld, "sample_map_resolution")
719         if not cscene.progressive and (device_type == 'NONE' or cscene.device == 'CPU'):
720             sub.prop(cworld, "samples")
721
722
723 class CyclesMaterial_PT_preview(CyclesButtonsPanel, Panel):
724     bl_label = "Preview"
725     bl_context = "material"
726     bl_options = {'DEFAULT_CLOSED'}
727
728     @classmethod
729     def poll(cls, context):
730         return context.material and CyclesButtonsPanel.poll(context)
731
732     def draw(self, context):
733         self.layout.template_preview(context.material)
734
735
736 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
737     bl_label = "Surface"
738     bl_context = "material"
739
740     @classmethod
741     def poll(cls, context):
742         return context.material and CyclesButtonsPanel.poll(context)
743
744     def draw(self, context):
745         layout = self.layout
746
747         mat = context.material
748         if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
749             layout.prop(mat, "diffuse_color")
750
751
752 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
753     bl_label = "Volume"
754     bl_context = "material"
755     bl_options = {'DEFAULT_CLOSED'}
756
757     @classmethod
758     def poll(cls, context):
759         # mat = context.material
760         # mat and mat.node_tree and CyclesButtonsPanel.poll(context)
761         return False
762
763     def draw(self, context):
764         layout = self.layout
765         layout.active = False
766
767         mat = context.material
768         cmat = mat.cycles
769
770         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
771
772         layout.prop(cmat, "homogeneous_volume")
773
774
775 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
776     bl_label = "Displacement"
777     bl_context = "material"
778
779     @classmethod
780     def poll(cls, context):
781         mat = context.material
782         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
783
784     def draw(self, context):
785         layout = self.layout
786
787         mat = context.material
788         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
789
790
791 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
792     bl_label = "Settings"
793     bl_context = "material"
794     bl_options = {'DEFAULT_CLOSED'}
795
796     @classmethod
797     def poll(cls, context):
798         return context.material and CyclesButtonsPanel.poll(context)
799
800     def draw(self, context):
801         layout = self.layout
802
803         mat = context.material
804         cmat = mat.cycles
805
806         split = layout.split()
807
808         col = split.column()
809         col.prop(mat, "diffuse_color", text="Viewport Color")
810
811         col = split.column()
812         col.prop(mat, "pass_index")
813
814         layout.prop(cmat, "sample_as_light")
815
816
817 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
818     bl_label = ""
819     bl_context = "texture"
820     bl_options = {'HIDE_HEADER'}
821     COMPAT_ENGINES = {'CYCLES'}
822
823     def draw(self, context):
824         layout = self.layout
825
826         tex = context.texture
827         space = context.space_data
828         pin_id = space.pin_id
829         use_pin_id = space.use_pin_id
830         user = context.texture_user
831
832         if not use_pin_id or not isinstance(pin_id, bpy.types.Texture):
833             pin_id = None
834
835         if not pin_id:
836             layout.template_texture_user()
837
838         if user:
839             layout.separator()
840
841             split = layout.split(percentage=0.65)
842             col = split.column()
843
844             if pin_id:
845                 col.template_ID(space, "pin_id")
846             elif user:
847                 col.template_ID(user, "texture", new="texture.new")
848
849             if tex:
850                 split = layout.split(percentage=0.2)
851                 split.label(text="Type:")
852                 split.prop(tex, "type", text="")
853                 
854                 
855 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
856     bl_label = "Node"
857     bl_context = "texture"
858
859     @classmethod
860     def poll(cls, context):
861         node = context.texture_node
862         return node and CyclesButtonsPanel.poll(context)
863
864     def draw(self, context):
865         layout = self.layout
866
867         node = context.texture_node
868         ntree = node.id_data
869         layout.template_node_view(ntree, node, None)
870
871
872 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
873     bl_label = "Mapping"
874     bl_context = "texture"
875
876     @classmethod
877     def poll(cls, context):
878         node = context.texture_node
879         return node and CyclesButtonsPanel.poll(context)
880
881     def draw(self, context):
882         layout = self.layout
883         
884         node = context.texture_node
885
886         mapping = node.texture_mapping
887
888         row = layout.row()
889
890         row.column().prop(mapping, "translation")
891         row.column().prop(mapping, "rotation")
892         row.column().prop(mapping, "scale")
893
894         layout.label(text="Projection:")
895
896         row = layout.row()
897         row.prop(mapping, "mapping_x", text="")
898         row.prop(mapping, "mapping_y", text="")
899         row.prop(mapping, "mapping_z", text="")
900
901
902 class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
903     bl_label = "Color"
904     bl_context = "texture"
905     bl_options = {'DEFAULT_CLOSED'}
906
907     @classmethod
908     def poll(cls, context):
909         # node = context.texture_node
910         return False
911         #return node and CyclesButtonsPanel.poll(context)
912
913     def draw(self, context):
914         layout = self.layout
915         
916         node = context.texture_node
917
918         mapping = node.color_mapping
919
920         split = layout.split()
921
922         col = split.column()
923         col.label(text="Blend:")
924         col.prop(mapping, "blend_type", text="")
925         col.prop(mapping, "blend_factor", text="Factor")
926         col.prop(mapping, "blend_color", text="")
927
928         col = split.column()
929         col.label(text="Adjust:")
930         col.prop(mapping, "brightness")
931         col.prop(mapping, "contrast")
932         col.prop(mapping, "saturation")
933
934         layout.separator()
935
936         layout.prop(mapping, "use_color_ramp", text="Ramp")
937         if mapping.use_color_ramp:
938             layout.template_color_ramp(mapping, "color_ramp", expand=True)
939
940
941 class CyclesParticle_PT_textures(CyclesButtonsPanel, Panel):
942     bl_label = "Textures"
943     bl_context = "particle"
944     bl_options = {'DEFAULT_CLOSED'}
945
946     @classmethod
947     def poll(cls, context):
948         psys = context.particle_system
949         return psys and CyclesButtonsPanel.poll(context)
950
951     def draw(self, context):
952         layout = self.layout
953
954         psys = context.particle_system
955         part = psys.settings
956
957         row = layout.row()
958         row.template_list("TEXTURE_UL_texslots", "", part, "texture_slots", part, "active_texture_index", rows=2)
959
960         col = row.column(align=True)
961         col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
962         col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
963         col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
964
965         if not part.active_texture:
966             layout.template_ID(part, "active_texture", new="texture.new")
967         else:
968             slot = part.texture_slots[part.active_texture_index]
969             layout.template_ID(slot, "texture", new="texture.new")
970
971
972 class CyclesRender_PT_CurveRendering(CyclesButtonsPanel, Panel):
973     bl_label = "Cycles Hair Rendering"
974     bl_context = "particle"
975
976     @classmethod
977     def poll(cls, context):
978         scene = context.scene
979         cscene = scene.cycles
980         psys = context.particle_system
981         device_type = context.user_preferences.system.compute_device_type
982         experimental = ((cscene.feature_set == 'EXPERIMENTAL') and (cscene.device == 'CPU' or device_type == 'NONE'))
983         return CyclesButtonsPanel.poll(context) and experimental and psys
984
985     def draw_header(self, context):
986         ccscene = context.scene.cycles_curves
987         self.layout.prop(ccscene, "use_curves", text="")
988
989     def draw(self, context):
990         layout = self.layout
991
992         scene = context.scene
993         ccscene = scene.cycles_curves
994
995         layout.active = ccscene.use_curves
996
997         layout.prop(ccscene, "preset", text="Mode")
998
999         if ccscene.preset == 'CUSTOM':
1000             layout.prop(ccscene, "primitive", text="Primitive")
1001
1002             if ccscene.primitive == 'TRIANGLES':
1003                 layout.prop(ccscene, "triangle_method", text="Method")
1004                 if ccscene.triangle_method == 'TESSELLATED_TRIANGLES':
1005                     layout.prop(ccscene, "resolution", text="Resolution")
1006                 layout.prop(ccscene, "use_smooth", text="Smooth")
1007             elif ccscene.primitive == 'LINE_SEGMENTS':
1008                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
1009
1010                 row = layout.row()
1011                 row.prop(ccscene, "use_encasing", text="Exclude encasing")
1012                 sub = row.row()
1013                 sub.active = ccscene.use_encasing
1014                 sub.prop(ccscene, "encasing_ratio", text="Ratio for encasing")
1015
1016                 layout.prop(ccscene, "line_method", text="Method")
1017                 layout.prop(ccscene, "use_tangent_normal", text="Use tangent normal as default")
1018                 layout.prop(ccscene, "use_tangent_normal_geometry", text="Use tangent normal geometry")
1019                 layout.prop(ccscene, "use_tangent_normal_correction", text="Correct tangent normal for slope")
1020                 layout.prop(ccscene, "interpolation", text="Interpolation")
1021
1022                 row = layout.row()
1023                 row.prop(ccscene, "segments", text="Segments")
1024                 row.prop(ccscene, "normalmix", text="Ray Mix")
1025             elif ccscene.primitive in {'CURVE_SEGMENTS', 'CURVE_RIBBONS'}:
1026                 layout.prop(ccscene, "subdivisions", text="Curve subdivisions")
1027                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
1028
1029                 layout.prop(ccscene, "interpolation", text="Interpolation")
1030                 row = layout.row()
1031                 row.prop(ccscene, "segments", text="Segments")
1032
1033             row = layout.row()
1034             row.prop(ccscene, "use_parents", text="Include parents")
1035
1036
1037 class CyclesParticle_PT_CurveSettings(CyclesButtonsPanel, Panel):
1038     bl_label = "Cycles Hair Settings"
1039     bl_context = "particle"
1040
1041     @classmethod
1042     def poll(cls, context):
1043         scene = context.scene
1044         cscene = scene.cycles
1045         ccscene = scene.cycles_curves
1046         use_curves = ccscene.use_curves and context.particle_system
1047         device_type = context.user_preferences.system.compute_device_type
1048         experimental = cscene.feature_set == 'EXPERIMENTAL' and (cscene.device == 'CPU' or device_type == 'NONE')
1049         return CyclesButtonsPanel.poll(context) and experimental and use_curves
1050
1051     def draw(self, context):
1052         layout = self.layout
1053
1054         psys = context.particle_settings
1055         cpsys = psys.cycles
1056
1057         row = layout.row()
1058         row.prop(cpsys, "shape", text="Shape")
1059         row.prop(cpsys, "use_closetip", text="Close tip")
1060
1061         layout.label(text="Width multiplier:")
1062         row = layout.row()
1063         row.prop(cpsys, "root_width", text="Root")
1064         row.prop(cpsys, "tip_width", text="Tip")
1065
1066
1067 class CyclesScene_PT_simplify(CyclesButtonsPanel, Panel):
1068     bl_label = "Simplify"
1069     bl_context = "scene"
1070     COMPAT_ENGINES = {'CYCLES'}
1071
1072     def draw_header(self, context):
1073         rd = context.scene.render
1074         self.layout.prop(rd, "use_simplify", text="")
1075
1076     def draw(self, context):
1077         layout = self.layout
1078
1079         rd = context.scene.render
1080
1081         layout.active = rd.use_simplify
1082
1083         split = layout.split()
1084
1085         col = split.column()
1086         col.prop(rd, "simplify_subdivision", text="Subdivision")
1087
1088         col = split.column()
1089         col.prop(rd, "simplify_child_particles", text="Child Particles")
1090
1091
1092 def draw_device(self, context):
1093     scene = context.scene
1094     layout = self.layout
1095
1096     if scene.render.engine == 'CYCLES':
1097         from . import engine
1098         cscene = scene.cycles
1099
1100         layout.prop(cscene, "feature_set")
1101
1102         device_type = context.user_preferences.system.compute_device_type
1103         if device_type == 'CUDA':
1104             layout.prop(cscene, "device")
1105         elif device_type == 'OPENCL' and cscene.feature_set == 'EXPERIMENTAL':
1106             layout.prop(cscene, "device")
1107
1108         if engine.with_osl() and (cscene.device == 'CPU' or device_type == 'NONE'):
1109             layout.prop(cscene, "shading_system")
1110
1111
1112 def draw_pause(self, context):
1113     layout = self.layout
1114     scene = context.scene
1115
1116     if scene.render.engine == "CYCLES":
1117         view = context.space_data
1118
1119         if view.viewport_shade == 'RENDERED':
1120             cscene = scene.cycles
1121             layername = scene.render.layers.active.name
1122             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1123             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1124
1125
1126 def get_panels():
1127     types = bpy.types
1128     return (
1129         types.RENDER_PT_render,
1130         types.RENDER_PT_output,
1131         types.RENDER_PT_encoding,
1132         types.RENDER_PT_dimensions,
1133         types.RENDER_PT_stamp,
1134         types.SCENE_PT_scene,
1135         types.SCENE_PT_color_management,
1136         types.SCENE_PT_custom_props,
1137         types.SCENE_PT_audio,
1138         types.SCENE_PT_unit,
1139         types.SCENE_PT_keying_sets,
1140         types.SCENE_PT_keying_set_paths,
1141         types.SCENE_PT_physics,
1142         types.WORLD_PT_context_world,
1143         types.WORLD_PT_custom_props,
1144         types.DATA_PT_context_mesh,
1145         types.DATA_PT_context_camera,
1146         types.DATA_PT_context_lamp,
1147         types.DATA_PT_context_speaker,
1148         types.DATA_PT_texture_space,
1149         types.DATA_PT_curve_texture_space,
1150         types.DATA_PT_mball_texture_space,
1151         types.DATA_PT_vertex_groups,
1152         types.DATA_PT_shape_keys,
1153         types.DATA_PT_uv_texture,
1154         types.DATA_PT_vertex_colors,
1155         types.DATA_PT_camera,
1156         types.DATA_PT_camera_display,
1157         types.DATA_PT_lens,
1158         types.DATA_PT_speaker,
1159         types.DATA_PT_distance,
1160         types.DATA_PT_cone,
1161         types.DATA_PT_customdata,
1162         types.DATA_PT_custom_props_mesh,
1163         types.DATA_PT_custom_props_camera,
1164         types.DATA_PT_custom_props_lamp,
1165         types.DATA_PT_custom_props_speaker,
1166         types.DATA_PT_custom_props_arm,
1167         types.DATA_PT_custom_props_curve,
1168         types.DATA_PT_custom_props_lattice,
1169         types.DATA_PT_custom_props_metaball,
1170         types.TEXTURE_PT_custom_props,
1171         types.TEXTURE_PT_clouds,
1172         types.TEXTURE_PT_wood,
1173         types.TEXTURE_PT_marble,
1174         types.TEXTURE_PT_magic,
1175         types.TEXTURE_PT_blend,
1176         types.TEXTURE_PT_stucci,
1177         types.TEXTURE_PT_image,
1178         types.TEXTURE_PT_image_sampling,
1179         types.TEXTURE_PT_image_mapping,
1180         types.TEXTURE_PT_musgrave,
1181         types.TEXTURE_PT_voronoi,
1182         types.TEXTURE_PT_distortednoise,
1183         types.TEXTURE_PT_voxeldata,
1184         types.TEXTURE_PT_pointdensity,
1185         types.TEXTURE_PT_pointdensity_turbulence,
1186         types.TEXTURE_PT_mapping,
1187         types.TEXTURE_PT_influence,
1188         types.TEXTURE_PT_colors,
1189         types.PARTICLE_PT_context_particles,
1190         types.PARTICLE_PT_custom_props,
1191         types.PARTICLE_PT_emission,
1192         types.PARTICLE_PT_hair_dynamics,
1193         types.PARTICLE_PT_cache,
1194         types.PARTICLE_PT_velocity,
1195         types.PARTICLE_PT_rotation,
1196         types.PARTICLE_PT_physics,
1197         types.SCENE_PT_rigid_body_world,
1198         types.SCENE_PT_rigid_body_cache,
1199         types.SCENE_PT_rigid_body_field_weights,
1200         types.PARTICLE_PT_boidbrain,
1201         types.PARTICLE_PT_render,
1202         types.PARTICLE_PT_draw,
1203         types.PARTICLE_PT_children,
1204         types.PARTICLE_PT_field_weights,
1205         types.PARTICLE_PT_force_fields,
1206         types.PARTICLE_PT_vertexgroups,
1207         types.MATERIAL_PT_custom_props,
1208         types.BONE_PT_custom_props,
1209         types.OBJECT_PT_custom_props,
1210         )
1211
1212
1213 def register():
1214     bpy.types.RENDER_PT_render.append(draw_device)
1215     bpy.types.VIEW3D_HT_header.append(draw_pause)
1216
1217     for panel in get_panels():
1218         panel.COMPAT_ENGINES.add('CYCLES')
1219
1220
1221 def unregister():
1222     bpy.types.RENDER_PT_render.remove(draw_device)
1223     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1224
1225     for panel in get_panels():
1226         panel.COMPAT_ENGINES.remove('CYCLES')