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