Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / blender / addon / ui.py
1 #
2 # Copyright 2011-2013 Blender Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 # <pep8 compliant>
18
19 import bpy
20
21 from bpy.types import (
22         Panel,
23         Menu,
24         Operator,
25         )
26
27
28 class CYCLES_MT_sampling_presets(Menu):
29     bl_label = "Sampling Presets"
30     preset_subdir = "cycles/sampling"
31     preset_operator = "script.execute_preset"
32     COMPAT_ENGINES = {'CYCLES'}
33     draw = Menu.draw_preset
34
35
36 class CYCLES_MT_integrator_presets(Menu):
37     bl_label = "Integrator Presets"
38     preset_subdir = "cycles/integrator"
39     preset_operator = "script.execute_preset"
40     COMPAT_ENGINES = {'CYCLES'}
41     draw = Menu.draw_preset
42
43
44 class CyclesButtonsPanel:
45     bl_space_type = "PROPERTIES"
46     bl_region_type = "WINDOW"
47     bl_context = "render"
48     COMPAT_ENGINES = {'CYCLES'}
49
50     @classmethod
51     def poll(cls, context):
52         rd = context.scene.render
53         return rd.engine in cls.COMPAT_ENGINES
54
55
56 def get_device_type(context):
57     return context.user_preferences.addons[__package__].preferences.compute_device_type
58
59
60 def use_cpu(context):
61     cscene = context.scene.cycles
62
63     return (get_device_type(context) == 'NONE' or cscene.device == 'CPU')
64
65
66 def use_opencl(context):
67     cscene = context.scene.cycles
68
69     return (get_device_type(context) == 'OPENCL' and cscene.device == 'GPU')
70
71
72 def use_cuda(context):
73     cscene = context.scene.cycles
74
75     return (get_device_type(context) == 'CUDA' and cscene.device == 'GPU')
76
77
78 def use_branched_path(context):
79     cscene = context.scene.cycles
80
81     return (cscene.progressive == 'BRANCHED_PATH' and not use_opencl(context))
82
83
84 def use_sample_all_lights(context):
85     cscene = context.scene.cycles
86
87     return cscene.sample_all_lights_direct or cscene.sample_all_lights_indirect
88
89 def show_device_selection(context):
90     type = get_device_type(context)
91     if type == 'NETWORK':
92         return True
93     if not type in {'CUDA', 'OPENCL'}:
94         return False
95     return context.user_preferences.addons[__package__].preferences.has_active_device()
96
97
98 def draw_samples_info(layout, context):
99     cscene = context.scene.cycles
100     integrator = cscene.progressive
101
102     # Calculate sample values
103     if integrator == 'PATH':
104         aa = cscene.samples
105         if cscene.use_square_samples:
106             aa = aa * aa
107     else:
108         aa = cscene.aa_samples
109         d = cscene.diffuse_samples
110         g = cscene.glossy_samples
111         t = cscene.transmission_samples
112         ao = cscene.ao_samples
113         ml = cscene.mesh_light_samples
114         sss = cscene.subsurface_samples
115         vol = cscene.volume_samples
116
117         if cscene.use_square_samples:
118             aa = aa * aa
119             d = d * d
120             g = g * g
121             t = t * t
122             ao = ao * ao
123             ml = ml * ml
124             sss = sss * sss
125             vol = vol * vol
126
127     # Draw interface
128     # Do not draw for progressive, when Square Samples are disabled
129     if use_branched_path(context) or (cscene.use_square_samples and integrator == 'PATH'):
130         col = layout.column(align=True)
131         col.scale_y = 0.6
132         col.label("Total Samples:")
133         col.separator()
134         if integrator == 'PATH':
135             col.label("%s AA" % aa)
136         else:
137             col.label("%s AA, %s Diffuse, %s Glossy, %s Transmission" %
138                       (aa, d * aa, g * aa, t * aa))
139             col.separator()
140             col.label("%s AO, %s Mesh Light, %s Subsurface, %s Volume" %
141                       (ao * aa, ml * aa, sss * aa, vol * aa))
142
143
144 class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel):
145     bl_label = "Sampling"
146     bl_options = {'DEFAULT_CLOSED'}
147
148     def draw(self, context):
149         layout = self.layout
150
151         scene = context.scene
152         cscene = scene.cycles
153
154         row = layout.row(align=True)
155         row.menu("CYCLES_MT_sampling_presets", text=bpy.types.CYCLES_MT_sampling_presets.bl_label)
156         row.operator("render.cycles_sampling_preset_add", text="", icon="ZOOMIN")
157         row.operator("render.cycles_sampling_preset_add", text="", icon="ZOOMOUT").remove_active = True
158
159         row = layout.row()
160         sub = row.row()
161         sub.active = get_device_type(context) != 'OPENCL' or use_cpu(context)
162         sub.prop(cscene, "progressive", text="")
163         row.prop(cscene, "use_square_samples")
164
165         split = layout.split()
166
167         col = split.column()
168         sub = col.column(align=True)
169         sub.label("Settings:")
170
171         seed_sub = sub.row(align=True)
172         seed_sub.prop(cscene, "seed")
173         seed_sub.prop(cscene, "use_animated_seed", text="", icon="TIME")
174
175         sub.prop(cscene, "sample_clamp_direct")
176         sub.prop(cscene, "sample_clamp_indirect")
177         sub.prop(cscene, "light_sampling_threshold")
178
179         if cscene.progressive == 'PATH' or use_branched_path(context) is False:
180             col = split.column()
181             sub = col.column(align=True)
182             sub.label(text="Samples:")
183             sub.prop(cscene, "samples", text="Render")
184             sub.prop(cscene, "preview_samples", text="Preview")
185         else:
186             sub.label(text="AA Samples:")
187             sub.prop(cscene, "aa_samples", text="Render")
188             sub.prop(cscene, "preview_aa_samples", text="Preview")
189             sub.separator()
190             sub.prop(cscene, "sample_all_lights_direct")
191             sub.prop(cscene, "sample_all_lights_indirect")
192
193             col = split.column()
194             sub = col.column(align=True)
195             sub.label(text="Samples:")
196             sub.prop(cscene, "diffuse_samples", text="Diffuse")
197             sub.prop(cscene, "glossy_samples", text="Glossy")
198             sub.prop(cscene, "transmission_samples", text="Transmission")
199             sub.prop(cscene, "ao_samples", text="AO")
200
201             subsub = sub.row(align=True)
202             subsub.active = use_sample_all_lights(context)
203             subsub.prop(cscene, "mesh_light_samples", text="Mesh Light")
204
205             sub.prop(cscene, "subsurface_samples", text="Subsurface")
206             sub.prop(cscene, "volume_samples", text="Volume")
207
208         if not (use_opencl(context) and cscene.feature_set != 'EXPERIMENTAL'):
209             layout.row().prop(cscene, "sampling_pattern", text="Pattern")
210
211         for rl in scene.render.layers:
212             if rl.samples > 0:
213                 layout.separator()
214                 layout.row().prop(cscene, "use_layer_samples")
215                 break
216
217         draw_samples_info(layout, context)
218
219
220 class CyclesRender_PT_geometry(CyclesButtonsPanel, Panel):
221     bl_label = "Geometry"
222     bl_options = {'DEFAULT_CLOSED'}
223
224     def draw(self, context):
225         layout = self.layout
226
227         scene = context.scene
228         cscene = scene.cycles
229         ccscene = scene.cycles_curves
230
231         if cscene.feature_set == 'EXPERIMENTAL':
232             split = layout.split()
233
234             col = split.column()
235
236             sub = col.column(align=True)
237             sub.label("Volume Sampling:")
238             sub.prop(cscene, "volume_step_size")
239             sub.prop(cscene, "volume_max_steps")
240
241             col = split.column()
242
243             sub = col.column(align=True)
244             sub.label("Subdivision Rate:")
245             sub.prop(cscene, "dicing_rate", text="Render")
246             sub.prop(cscene, "preview_dicing_rate", text="Preview")
247             sub.separator()
248             sub.prop(cscene, "max_subdivisions")
249         else:
250             row = layout.row()
251             row.label("Volume Sampling:")
252             row = layout.row()
253             row.prop(cscene, "volume_step_size")
254             row.prop(cscene, "volume_max_steps")
255
256         layout.prop(ccscene, "use_curves", text="Use Hair")
257         col = layout.column()
258         col.active = ccscene.use_curves
259
260         col.prop(ccscene, "primitive", text="Primitive")
261         col.prop(ccscene, "shape", text="Shape")
262
263         if not (ccscene.primitive in {'CURVE_SEGMENTS', 'LINE_SEGMENTS'} and ccscene.shape == 'RIBBONS'):
264             col.prop(ccscene, "cull_backfacing", text="Cull back-faces")
265
266         if ccscene.primitive == 'TRIANGLES' and ccscene.shape == 'THICK':
267             col.prop(ccscene, "resolution", text="Resolution")
268         elif ccscene.primitive == 'CURVE_SEGMENTS':
269             col.prop(ccscene, "subdivisions", text="Curve subdivisions")
270
271         row = col.row()
272         row.prop(ccscene, "minimum_width", text="Min Pixels")
273         row.prop(ccscene, "maximum_width", text="Max Ext.")
274
275
276 class CyclesRender_PT_light_paths(CyclesButtonsPanel, Panel):
277     bl_label = "Light Paths"
278     bl_options = {'DEFAULT_CLOSED'}
279
280     def draw(self, context):
281         layout = self.layout
282
283         scene = context.scene
284         cscene = scene.cycles
285
286         row = layout.row(align=True)
287         row.menu("CYCLES_MT_integrator_presets", text=bpy.types.CYCLES_MT_integrator_presets.bl_label)
288         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMIN")
289         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMOUT").remove_active = True
290
291         split = layout.split()
292
293         col = split.column()
294
295         sub = col.column(align=True)
296         sub.label("Transparency:")
297         sub.prop(cscene, "transparent_max_bounces", text="Max")
298         sub.prop(cscene, "transparent_min_bounces", text="Min")
299         sub.prop(cscene, "use_transparent_shadows", text="Shadows")
300
301         col.separator()
302
303         col.prop(cscene, "caustics_reflective")
304         col.prop(cscene, "caustics_refractive")
305         col.prop(cscene, "blur_glossy")
306
307         col = split.column()
308
309         sub = col.column(align=True)
310         sub.label(text="Bounces:")
311         sub.prop(cscene, "max_bounces", text="Max")
312         sub.prop(cscene, "min_bounces", text="Min")
313
314         sub = col.column(align=True)
315         sub.prop(cscene, "diffuse_bounces", text="Diffuse")
316         sub.prop(cscene, "glossy_bounces", text="Glossy")
317         sub.prop(cscene, "transmission_bounces", text="Transmission")
318         sub.prop(cscene, "volume_bounces", text="Volume")
319
320
321 class CyclesRender_PT_motion_blur(CyclesButtonsPanel, Panel):
322     bl_label = "Motion Blur"
323     bl_options = {'DEFAULT_CLOSED'}
324
325     def draw_header(self, context):
326         rd = context.scene.render
327
328         self.layout.prop(rd, "use_motion_blur", text="")
329
330     def draw(self, context):
331         layout = self.layout
332
333         scene = context.scene
334         cscene = scene.cycles
335         rd = scene.render
336         layout.active = rd.use_motion_blur
337
338         col = layout.column()
339         col.prop(cscene, "motion_blur_position", text="Position")
340         col.prop(rd, "motion_blur_shutter")
341
342         col = layout.column()
343         col.label("Shutter curve:")
344         col.template_curve_mapping(rd, "motion_blur_shutter_curve")
345
346         col = layout.column(align=True)
347         row = col.row(align=True)
348         row.operator("render.shutter_curve_preset", icon='SMOOTHCURVE', text="").shape = 'SMOOTH'
349         row.operator("render.shutter_curve_preset", icon='SPHERECURVE', text="").shape = 'ROUND'
350         row.operator("render.shutter_curve_preset", icon='ROOTCURVE', text="").shape = 'ROOT'
351         row.operator("render.shutter_curve_preset", icon='SHARPCURVE', text="").shape = 'SHARP'
352         row.operator("render.shutter_curve_preset", icon='LINCURVE', text="").shape = 'LINE'
353         row.operator("render.shutter_curve_preset", icon='NOCURVE', text="").shape = 'MAX'
354
355         col = layout.column()
356         col.prop(cscene, "rolling_shutter_type")
357         row = col.row()
358         row.active = cscene.rolling_shutter_type != 'NONE'
359         row.prop(cscene, "rolling_shutter_duration")
360
361
362 class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
363     bl_label = "Film"
364
365     def draw(self, context):
366         layout = self.layout
367
368         scene = context.scene
369         cscene = scene.cycles
370
371         split = layout.split()
372
373         col = split.column()
374         col.prop(cscene, "film_exposure")
375         col.prop(cscene, "film_transparent")
376
377         col = split.column()
378         sub = col.column(align=True)
379         sub.prop(cscene, "pixel_filter_type", text="")
380         if cscene.pixel_filter_type != 'BOX':
381             sub.prop(cscene, "filter_width", text="Width")
382
383
384 class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
385     bl_label = "Performance"
386     bl_options = {'DEFAULT_CLOSED'}
387
388     def draw(self, context):
389         layout = self.layout
390
391         scene = context.scene
392         rd = scene.render
393         cscene = scene.cycles
394
395         split = layout.split()
396
397         col = split.column(align=True)
398
399         col.label(text="Threads:")
400         col.row(align=True).prop(rd, "threads_mode", expand=True)
401         sub = col.column(align=True)
402         sub.enabled = rd.threads_mode == 'FIXED'
403         sub.prop(rd, "threads")
404
405         sub = col.column(align=True)
406         sub.label(text="Tiles:")
407         sub.prop(cscene, "tile_order", text="")
408
409         sub.prop(rd, "tile_x", text="X")
410         sub.prop(rd, "tile_y", text="Y")
411
412         sub.prop(cscene, "use_progressive_refine")
413
414         subsub = sub.column(align=True)
415         subsub.prop(rd, "use_save_buffers")
416
417         col = split.column(align=True)
418
419         col.label(text="Viewport:")
420         col.prop(cscene, "debug_bvh_type", text="")
421         col.separator()
422         col.prop(cscene, "preview_start_resolution")
423
424         col.separator()
425
426         col.label(text="Final Render:")
427         col.prop(rd, "use_persistent_data", text="Persistent Images")
428
429         col.separator()
430
431         col.label(text="Acceleration structure:")
432         col.prop(cscene, "debug_use_spatial_splits")
433         col.prop(cscene, "debug_use_hair_bvh")
434
435         row = col.row()
436         row.active = not cscene.debug_use_spatial_splits
437         row.prop(cscene, "debug_bvh_time_steps")
438
439
440 class CyclesRender_PT_layer_options(CyclesButtonsPanel, Panel):
441     bl_label = "Layer"
442     bl_context = "render_layer"
443
444     def draw(self, context):
445         layout = self.layout
446
447         scene = context.scene
448         rd = scene.render
449         rl = rd.layers.active
450
451         split = layout.split()
452
453         col = split.column()
454         col.prop(scene, "layers", text="Scene")
455         col.prop(rl, "layers_exclude", text="Exclude")
456
457         col = split.column()
458         col.prop(rl, "layers", text="Layer")
459         col.prop(rl, "layers_zmask", text="Mask Layer")
460
461         split = layout.split()
462
463         col = split.column()
464         col.label(text="Material:")
465         col.prop(rl, "material_override", text="")
466         col.separator()
467         col.prop(rl, "samples")
468
469         col = split.column()
470         col.prop(rl, "use_sky", "Use Environment")
471         col.prop(rl, "use_ao", "Use AO")
472         col.prop(rl, "use_solid", "Use Surfaces")
473         col.prop(rl, "use_strand", "Use Hair")
474
475
476 class CyclesRender_PT_layer_passes(CyclesButtonsPanel, Panel):
477     bl_label = "Passes"
478     bl_context = "render_layer"
479     bl_options = {'DEFAULT_CLOSED'}
480
481     def draw(self, context):
482         layout = self.layout
483
484         scene = context.scene
485         rd = scene.render
486         rl = rd.layers.active
487
488         split = layout.split()
489
490         col = split.column()
491         col.prop(rl, "use_pass_combined")
492         col.prop(rl, "use_pass_z")
493         col.prop(rl, "use_pass_mist")
494         col.prop(rl, "use_pass_normal")
495         row = col.row()
496         row.prop(rl, "use_pass_vector")
497         row.active = not rd.use_motion_blur
498         col.prop(rl, "use_pass_uv")
499         col.prop(rl, "use_pass_object_index")
500         col.prop(rl, "use_pass_material_index")
501         col.separator()
502         col.prop(rl, "use_pass_shadow")
503         col.prop(rl, "use_pass_ambient_occlusion")
504         col.separator()
505         col.prop(rl, "pass_alpha_threshold")
506
507         col = split.column()
508         col.label(text="Diffuse:")
509         row = col.row(align=True)
510         row.prop(rl, "use_pass_diffuse_direct", text="Direct", toggle=True)
511         row.prop(rl, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
512         row.prop(rl, "use_pass_diffuse_color", text="Color", toggle=True)
513         col.label(text="Glossy:")
514         row = col.row(align=True)
515         row.prop(rl, "use_pass_glossy_direct", text="Direct", toggle=True)
516         row.prop(rl, "use_pass_glossy_indirect", text="Indirect", toggle=True)
517         row.prop(rl, "use_pass_glossy_color", text="Color", toggle=True)
518         col.label(text="Transmission:")
519         row = col.row(align=True)
520         row.prop(rl, "use_pass_transmission_direct", text="Direct", toggle=True)
521         row.prop(rl, "use_pass_transmission_indirect", text="Indirect", toggle=True)
522         row.prop(rl, "use_pass_transmission_color", text="Color", toggle=True)
523         col.label(text="Subsurface:")
524         row = col.row(align=True)
525         row.prop(rl, "use_pass_subsurface_direct", text="Direct", toggle=True)
526         row.prop(rl, "use_pass_subsurface_indirect", text="Indirect", toggle=True)
527         row.prop(rl, "use_pass_subsurface_color", text="Color", toggle=True)
528
529         col.separator()
530         col.prop(rl, "use_pass_emit", text="Emission")
531         col.prop(rl, "use_pass_environment")
532
533         if hasattr(rd, "debug_pass_type"):
534             layout.prop(rd, "debug_pass_type")
535
536
537 class CyclesRender_PT_views(CyclesButtonsPanel, Panel):
538     bl_label = "Views"
539     bl_context = "render_layer"
540     bl_options = {'DEFAULT_CLOSED'}
541
542     def draw_header(self, context):
543         rd = context.scene.render
544         self.layout.prop(rd, "use_multiview", text="")
545
546     def draw(self, context):
547         layout = self.layout
548
549         scene = context.scene
550         rd = scene.render
551         rv = rd.views.active
552
553         layout.active = rd.use_multiview
554         basic_stereo = (rd.views_format == 'STEREO_3D')
555
556         row = layout.row()
557         row.prop(rd, "views_format", expand=True)
558
559         if basic_stereo:
560             row = layout.row()
561             row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
562
563             row = layout.row()
564             row.label(text="File Suffix:")
565             row.prop(rv, "file_suffix", text="")
566
567         else:
568             row = layout.row()
569             row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
570
571             col = row.column(align=True)
572             col.operator("scene.render_view_add", icon='ZOOMIN', text="")
573             col.operator("scene.render_view_remove", icon='ZOOMOUT', text="")
574
575             row = layout.row()
576             row.label(text="Camera Suffix:")
577             row.prop(rv, "camera_suffix", text="")
578
579
580 class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
581     bl_label = "Post Processing"
582     bl_options = {'DEFAULT_CLOSED'}
583
584     def draw(self, context):
585         layout = self.layout
586
587         rd = context.scene.render
588
589         split = layout.split()
590
591         col = split.column()
592         col.prop(rd, "use_compositing")
593         col.prop(rd, "use_sequencer")
594
595         col = split.column()
596         col.prop(rd, "dither_intensity", text="Dither", slider=True)
597
598
599 class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
600     bl_label = "Depth of Field"
601     bl_context = "data"
602
603     @classmethod
604     def poll(cls, context):
605         return context.camera and CyclesButtonsPanel.poll(context)
606
607     def draw(self, context):
608         layout = self.layout
609
610         cam = context.camera
611         ccam = cam.cycles
612         dof_options = cam.gpu_dof
613
614         split = layout.split()
615
616         col = split.column()
617         col.label("Focus:")
618         col.prop(cam, "dof_object", text="")
619
620         sub = col.row()
621         sub.active = cam.dof_object is None
622         sub.prop(cam, "dof_distance", text="Distance")
623
624         hq_support = dof_options.is_hq_supported
625         sub = col.column(align=True)
626         sub.label("Viewport:")
627         subhq = sub.column()
628         subhq.active = hq_support
629         subhq.prop(dof_options, "use_high_quality")
630         sub.prop(dof_options, "fstop")
631         if dof_options.use_high_quality and hq_support:
632             sub.prop(dof_options, "blades")
633
634         col = split.column()
635
636         col.label("Aperture:")
637         sub = col.column(align=True)
638         sub.prop(ccam, "aperture_type", text="")
639         if ccam.aperture_type == 'RADIUS':
640             sub.prop(ccam, "aperture_size", text="Size")
641         elif ccam.aperture_type == 'FSTOP':
642             sub.prop(ccam, "aperture_fstop", text="Number")
643
644         sub = col.column(align=True)
645         sub.prop(ccam, "aperture_blades", text="Blades")
646         sub.prop(ccam, "aperture_rotation", text="Rotation")
647         sub.prop(ccam, "aperture_ratio", text="Ratio")
648
649
650 class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
651     bl_label = ""
652     bl_context = "material"
653     bl_options = {'HIDE_HEADER'}
654
655     @classmethod
656     def poll(cls, context):
657         return (context.material or context.object) and CyclesButtonsPanel.poll(context)
658
659     def draw(self, context):
660         layout = self.layout
661
662         mat = context.material
663         ob = context.object
664         slot = context.material_slot
665         space = context.space_data
666
667         if ob:
668             is_sortable = len(ob.material_slots) > 1
669             rows = 1
670             if (is_sortable):
671                 rows = 4
672
673             row = layout.row()
674
675             row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
676
677             col = row.column(align=True)
678             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
679             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
680
681             col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
682
683             if is_sortable:
684                 col.separator()
685
686                 col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
687                 col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
688
689             if ob.mode == 'EDIT':
690                 row = layout.row(align=True)
691                 row.operator("object.material_slot_assign", text="Assign")
692                 row.operator("object.material_slot_select", text="Select")
693                 row.operator("object.material_slot_deselect", text="Deselect")
694
695         split = layout.split(percentage=0.65)
696
697         if ob:
698             split.template_ID(ob, "active_material", new="material.new")
699             row = split.row()
700
701             if slot:
702                 row.prop(slot, "link", text="")
703             else:
704                 row.label()
705         elif mat:
706             split.template_ID(space, "pin_id")
707             split.separator()
708
709
710 class CyclesObject_PT_motion_blur(CyclesButtonsPanel, Panel):
711     bl_label = "Motion Blur"
712     bl_context = "object"
713     bl_options = {'DEFAULT_CLOSED'}
714
715     @classmethod
716     def poll(cls, context):
717         ob = context.object
718         if CyclesButtonsPanel.poll(context) and ob:
719             if ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META'}:
720                 return True
721             if ob.dupli_type == 'GROUP' and ob.dupli_group:
722                 return True
723             # TODO(sergey): More duplicator types here?
724         return False
725
726     def draw_header(self, context):
727         layout = self.layout
728
729         rd = context.scene.render
730         # scene = context.scene
731
732         layout.active = rd.use_motion_blur
733
734         ob = context.object
735         cob = ob.cycles
736
737         layout.prop(cob, "use_motion_blur", text="")
738
739     def draw(self, context):
740         layout = self.layout
741
742         rd = context.scene.render
743         # scene = context.scene
744
745         ob = context.object
746         cob = ob.cycles
747
748         layout.active = (rd.use_motion_blur and cob.use_motion_blur)
749
750         row = layout.row()
751         row.prop(cob, "use_deform_motion", text="Deformation")
752
753         sub = row.row()
754         sub.active = cob.use_deform_motion
755         sub.prop(cob, "motion_steps", text="Steps")
756
757
758 class CyclesObject_PT_cycles_settings(CyclesButtonsPanel, Panel):
759     bl_label = "Cycles Settings"
760     bl_context = "object"
761     bl_options = {'DEFAULT_CLOSED'}
762
763     @classmethod
764     def poll(cls, context):
765         ob = context.object
766         return (CyclesButtonsPanel.poll(context) and
767                 ob and ((ob.type in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'META', 'LAMP'}) or
768                         (ob.dupli_type == 'GROUP' and ob.dupli_group)))
769
770     def draw(self, context):
771         layout = self.layout
772
773         scene = context.scene
774         cscene = scene.cycles
775         ob = context.object
776         cob = ob.cycles
777         visibility = ob.cycles_visibility
778
779         layout.label(text="Ray Visibility:")
780         flow = layout.column_flow()
781
782         flow.prop(visibility, "camera")
783         flow.prop(visibility, "diffuse")
784         flow.prop(visibility, "glossy")
785         flow.prop(visibility, "transmission")
786         flow.prop(visibility, "scatter")
787
788         if ob.type != 'LAMP':
789             flow.prop(visibility, "shadow")
790
791         col = layout.column()
792         col.label(text="Performance:")
793         row = col.row()
794         sub = row.row()
795         sub.active = scene.render.use_simplify and cscene.use_camera_cull
796         sub.prop(cob, "use_camera_cull")
797
798         sub = row.row()
799         sub.active = scene.render.use_simplify and cscene.use_distance_cull
800         sub.prop(cob, "use_distance_cull")
801
802
803 class CYCLES_OT_use_shading_nodes(Operator):
804     """Enable nodes on a material, world or lamp"""
805     bl_idname = "cycles.use_shading_nodes"
806     bl_label = "Use Nodes"
807
808     @classmethod
809     def poll(cls, context):
810         return (getattr(context, "material", False) or getattr(context, "world", False) or
811                 getattr(context, "lamp", False))
812
813     def execute(self, context):
814         if context.material:
815             context.material.use_nodes = True
816         elif context.world:
817             context.world.use_nodes = True
818         elif context.lamp:
819             context.lamp.use_nodes = True
820
821         return {'FINISHED'}
822
823
824 def find_node(material, nodetype):
825     if material and material.node_tree:
826         ntree = material.node_tree
827
828         active_output_node = None
829         for node in ntree.nodes:
830             if getattr(node, "type", None) == nodetype:
831                 if getattr(node, "is_active_output", True):
832                     return node
833                 if not active_output_node:
834                     active_output_node = node
835         return active_output_node
836
837     return None
838
839
840 def find_node_input(node, name):
841     for input in node.inputs:
842         if input.name == name:
843             return input
844
845     return None
846
847
848 def panel_node_draw(layout, id_data, output_type, input_name):
849     if not id_data.use_nodes:
850         layout.operator("cycles.use_shading_nodes", icon='NODETREE')
851         return False
852
853     ntree = id_data.node_tree
854
855     node = find_node(id_data, output_type)
856     if not node:
857         layout.label(text="No output node")
858     else:
859         input = find_node_input(node, input_name)
860         layout.template_node_view(ntree, node, input)
861
862     return True
863
864
865 class CyclesLamp_PT_preview(CyclesButtonsPanel, Panel):
866     bl_label = "Preview"
867     bl_context = "data"
868     bl_options = {'DEFAULT_CLOSED'}
869
870     @classmethod
871     def poll(cls, context):
872         return context.lamp and \
873                not (context.lamp.type == 'AREA' and
874                     context.lamp.cycles.is_portal) \
875                and CyclesButtonsPanel.poll(context)
876
877     def draw(self, context):
878         self.layout.template_preview(context.lamp)
879
880
881 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
882     bl_label = "Lamp"
883     bl_context = "data"
884
885     @classmethod
886     def poll(cls, context):
887         return context.lamp and CyclesButtonsPanel.poll(context)
888
889     def draw(self, context):
890         layout = self.layout
891
892         lamp = context.lamp
893         clamp = lamp.cycles
894         # cscene = context.scene.cycles
895
896         layout.prop(lamp, "type", expand=True)
897
898         split = layout.split()
899         col = split.column(align=True)
900
901         if lamp.type in {'POINT', 'SUN', 'SPOT'}:
902             col.prop(lamp, "shadow_soft_size", text="Size")
903         elif lamp.type == 'AREA':
904             col.prop(lamp, "shape", text="")
905             sub = col.column(align=True)
906
907             if lamp.shape == 'SQUARE':
908                 sub.prop(lamp, "size")
909             elif lamp.shape == 'RECTANGLE':
910                 sub.prop(lamp, "size", text="Size X")
911                 sub.prop(lamp, "size_y", text="Size Y")
912
913         if not (lamp.type == 'AREA' and clamp.is_portal):
914             sub = col.column(align=True)
915             if use_branched_path(context):
916                 subsub = sub.row(align=True)
917                 subsub.active = use_sample_all_lights(context)
918                 subsub.prop(clamp, "samples")
919             sub.prop(clamp, "max_bounces")
920
921         col = split.column()
922
923         sub = col.column(align=True)
924         sub.active = not (lamp.type == 'AREA' and clamp.is_portal)
925         sub.prop(clamp, "cast_shadow")
926         sub.prop(clamp, "use_multiple_importance_sampling", text="Multiple Importance")
927
928         if lamp.type == 'AREA':
929             col.prop(clamp, "is_portal", text="Portal")
930
931         if lamp.type == 'HEMI':
932             layout.label(text="Not supported, interpreted as sun lamp")
933
934
935 class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
936     bl_label = "Nodes"
937     bl_context = "data"
938
939     @classmethod
940     def poll(cls, context):
941         return context.lamp and not (context.lamp.type == 'AREA' and
942                                      context.lamp.cycles.is_portal) and \
943                CyclesButtonsPanel.poll(context)
944
945     def draw(self, context):
946         layout = self.layout
947
948         lamp = context.lamp
949         if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
950             layout.prop(lamp, "color")
951
952
953 class CyclesLamp_PT_spot(CyclesButtonsPanel, Panel):
954     bl_label = "Spot Shape"
955     bl_context = "data"
956
957     @classmethod
958     def poll(cls, context):
959         lamp = context.lamp
960         return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context)
961
962     def draw(self, context):
963         layout = self.layout
964
965         lamp = context.lamp
966
967         split = layout.split()
968
969         col = split.column()
970         sub = col.column()
971         sub.prop(lamp, "spot_size", text="Size")
972         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
973
974         col = split.column()
975         col.prop(lamp, "show_cone")
976
977
978 class CyclesWorld_PT_preview(CyclesButtonsPanel, Panel):
979     bl_label = "Preview"
980     bl_context = "world"
981     bl_options = {'DEFAULT_CLOSED'}
982
983     @classmethod
984     def poll(cls, context):
985         return context.world and CyclesButtonsPanel.poll(context)
986
987     def draw(self, context):
988         self.layout.template_preview(context.world)
989
990
991 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
992     bl_label = "Surface"
993     bl_context = "world"
994
995     @classmethod
996     def poll(cls, context):
997         return context.world and CyclesButtonsPanel.poll(context)
998
999     def draw(self, context):
1000         layout = self.layout
1001
1002         world = context.world
1003
1004         if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
1005             layout.prop(world, "horizon_color", text="Color")
1006
1007
1008 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
1009     bl_label = "Volume"
1010     bl_context = "world"
1011     bl_options = {'DEFAULT_CLOSED'}
1012
1013     @classmethod
1014     def poll(cls, context):
1015         world = context.world
1016         return world and world.node_tree and CyclesButtonsPanel.poll(context)
1017
1018     def draw(self, context):
1019         layout = self.layout
1020
1021         world = context.world
1022         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
1023
1024
1025 class CyclesWorld_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
1026     bl_label = "Ambient Occlusion"
1027     bl_context = "world"
1028
1029     @classmethod
1030     def poll(cls, context):
1031         return context.world and CyclesButtonsPanel.poll(context)
1032
1033     def draw_header(self, context):
1034         light = context.world.light_settings
1035         self.layout.prop(light, "use_ambient_occlusion", text="")
1036
1037     def draw(self, context):
1038         layout = self.layout
1039
1040         light = context.world.light_settings
1041
1042         row = layout.row()
1043         sub = row.row()
1044         sub.active = light.use_ambient_occlusion
1045         sub.prop(light, "ao_factor", text="Factor")
1046         row.prop(light, "distance", text="Distance")
1047
1048
1049 class CyclesWorld_PT_mist(CyclesButtonsPanel, Panel):
1050     bl_label = "Mist Pass"
1051     bl_context = "world"
1052     bl_options = {'DEFAULT_CLOSED'}
1053
1054     @classmethod
1055     def poll(cls, context):
1056         if CyclesButtonsPanel.poll(context):
1057             if context.world:
1058                 for rl in context.scene.render.layers:
1059                     if rl.use_pass_mist:
1060                         return True
1061
1062         return False
1063
1064     def draw(self, context):
1065         layout = self.layout
1066
1067         world = context.world
1068
1069         split = layout.split(align=True)
1070         split.prop(world.mist_settings, "start")
1071         split.prop(world.mist_settings, "depth")
1072
1073         layout.prop(world.mist_settings, "falloff")
1074
1075
1076 class CyclesWorld_PT_ray_visibility(CyclesButtonsPanel, Panel):
1077     bl_label = "Ray Visibility"
1078     bl_context = "world"
1079     bl_options = {'DEFAULT_CLOSED'}
1080
1081     @classmethod
1082     def poll(cls, context):
1083         return CyclesButtonsPanel.poll(context) and context.world
1084
1085     def draw(self, context):
1086         layout = self.layout
1087
1088         world = context.world
1089         visibility = world.cycles_visibility
1090
1091         flow = layout.column_flow()
1092
1093         flow.prop(visibility, "camera")
1094         flow.prop(visibility, "diffuse")
1095         flow.prop(visibility, "glossy")
1096         flow.prop(visibility, "transmission")
1097         flow.prop(visibility, "scatter")
1098
1099
1100 class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
1101     bl_label = "Settings"
1102     bl_context = "world"
1103     bl_options = {'DEFAULT_CLOSED'}
1104
1105     @classmethod
1106     def poll(cls, context):
1107         return context.world and CyclesButtonsPanel.poll(context)
1108
1109     def draw(self, context):
1110         layout = self.layout
1111
1112         world = context.world
1113         cworld = world.cycles
1114         # cscene = context.scene.cycles
1115
1116         split = layout.split()
1117
1118         col = split.column()
1119
1120         col.label(text="Surface:")
1121         col.prop(cworld, "sample_as_light", text="Multiple Importance")
1122
1123         sub = col.column(align=True)
1124         sub.active = cworld.sample_as_light
1125         sub.prop(cworld, "sample_map_resolution")
1126         if use_branched_path(context):
1127             subsub = sub.row(align=True)
1128             subsub.active = use_sample_all_lights(context)
1129             subsub.prop(cworld, "samples")
1130         sub.prop(cworld, "max_bounces")
1131
1132         col = split.column()
1133         col.label(text="Volume:")
1134         sub = col.column()
1135         sub.active = use_cpu(context)
1136         sub.prop(cworld, "volume_sampling", text="")
1137         sub.prop(cworld, "volume_interpolation", text="")
1138         col.prop(cworld, "homogeneous_volume", text="Homogeneous")
1139
1140
1141 class CyclesMaterial_PT_preview(CyclesButtonsPanel, Panel):
1142     bl_label = "Preview"
1143     bl_context = "material"
1144     bl_options = {'DEFAULT_CLOSED'}
1145
1146     @classmethod
1147     def poll(cls, context):
1148         return context.material and CyclesButtonsPanel.poll(context)
1149
1150     def draw(self, context):
1151         self.layout.template_preview(context.material)
1152
1153
1154 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
1155     bl_label = "Surface"
1156     bl_context = "material"
1157
1158     @classmethod
1159     def poll(cls, context):
1160         return context.material and CyclesButtonsPanel.poll(context)
1161
1162     def draw(self, context):
1163         layout = self.layout
1164
1165         mat = context.material
1166         if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
1167             layout.prop(mat, "diffuse_color")
1168
1169
1170 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
1171     bl_label = "Volume"
1172     bl_context = "material"
1173     bl_options = {'DEFAULT_CLOSED'}
1174
1175     @classmethod
1176     def poll(cls, context):
1177         mat = context.material
1178         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
1179
1180     def draw(self, context):
1181         layout = self.layout
1182
1183         mat = context.material
1184         # cmat = mat.cycles
1185
1186         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
1187
1188
1189 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
1190     bl_label = "Displacement"
1191     bl_context = "material"
1192
1193     @classmethod
1194     def poll(cls, context):
1195         mat = context.material
1196         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
1197
1198     def draw(self, context):
1199         layout = self.layout
1200
1201         mat = context.material
1202         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
1203
1204
1205 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
1206     bl_label = "Settings"
1207     bl_context = "material"
1208     bl_options = {'DEFAULT_CLOSED'}
1209
1210     @classmethod
1211     def poll(cls, context):
1212         return context.material and CyclesButtonsPanel.poll(context)
1213
1214     def draw(self, context):
1215         layout = self.layout
1216
1217         mat = context.material
1218         cmat = mat.cycles
1219
1220         split = layout.split()
1221         col = split.column()
1222         col.label(text="Surface:")
1223         col.prop(cmat, "sample_as_light", text="Multiple Importance")
1224         col.prop(cmat, "use_transparent_shadow")
1225
1226         if context.scene.cycles.feature_set == 'EXPERIMENTAL':
1227             col.separator()
1228             col.label(text="Displacement:")
1229             col.prop(cmat, "displacement_method", text="")
1230
1231         col = split.column()
1232         col.label(text="Volume:")
1233         sub = col.column()
1234         sub.active = use_cpu(context)
1235         sub.prop(cmat, "volume_sampling", text="")
1236         sub.prop(cmat, "volume_interpolation", text="")
1237         col.prop(cmat, "homogeneous_volume", text="Homogeneous")
1238
1239         layout.separator()
1240         split = layout.split()
1241
1242         col = split.column(align=True)
1243         col.label("Viewport Color:")
1244         col.prop(mat, "diffuse_color", text="")
1245         col.prop(mat, "alpha")
1246
1247         col.separator()
1248         col.label("Viewport Alpha:")
1249         col.prop(mat.game_settings, "alpha_blend", text="")
1250
1251         col = split.column(align=True)
1252         col.label("Viewport Specular:")
1253         col.prop(mat, "specular_color", text="")
1254         col.prop(mat, "specular_hardness", text="Hardness")
1255
1256         col.separator()
1257         col.prop(mat, "pass_index")
1258
1259
1260 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
1261     bl_label = ""
1262     bl_context = "texture"
1263     bl_options = {'HIDE_HEADER'}
1264     COMPAT_ENGINES = {'CYCLES'}
1265
1266     def draw(self, context):
1267         layout = self.layout
1268
1269         tex = context.texture
1270         space = context.space_data
1271         pin_id = space.pin_id
1272         use_pin_id = space.use_pin_id
1273         user = context.texture_user
1274
1275         space.use_limited_texture_context = False
1276
1277         if not (use_pin_id and isinstance(pin_id, bpy.types.Texture)):
1278             pin_id = None
1279
1280         if not pin_id:
1281             layout.template_texture_user()
1282
1283         if user or pin_id:
1284             layout.separator()
1285
1286             split = layout.split(percentage=0.65)
1287             col = split.column()
1288
1289             if pin_id:
1290                 col.template_ID(space, "pin_id")
1291             else:
1292                 propname = context.texture_user_property.identifier
1293                 col.template_ID(user, propname, new="texture.new")
1294
1295             if tex:
1296                 split = layout.split(percentage=0.2)
1297                 split.label(text="Type:")
1298                 split.prop(tex, "type", text="")
1299
1300
1301 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
1302     bl_label = "Node"
1303     bl_context = "texture"
1304
1305     @classmethod
1306     def poll(cls, context):
1307         node = context.texture_node
1308         return node and CyclesButtonsPanel.poll(context)
1309
1310     def draw(self, context):
1311         layout = self.layout
1312
1313         node = context.texture_node
1314         ntree = node.id_data
1315         layout.template_node_view(ntree, node, None)
1316
1317
1318 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
1319     bl_label = "Mapping"
1320     bl_context = "texture"
1321
1322     @classmethod
1323     def poll(cls, context):
1324         node = context.texture_node
1325         # TODO(sergey): perform a faster/nicer check?
1326         return node and hasattr(node, 'texture_mapping') and CyclesButtonsPanel.poll(context)
1327
1328     def draw(self, context):
1329         layout = self.layout
1330
1331         node = context.texture_node
1332
1333         mapping = node.texture_mapping
1334
1335         layout.prop(mapping, "vector_type", expand=True)
1336
1337         row = layout.row()
1338
1339         row.column().prop(mapping, "translation")
1340         row.column().prop(mapping, "rotation")
1341         row.column().prop(mapping, "scale")
1342
1343         layout.label(text="Projection:")
1344
1345         row = layout.row()
1346         row.prop(mapping, "mapping_x", text="")
1347         row.prop(mapping, "mapping_y", text="")
1348         row.prop(mapping, "mapping_z", text="")
1349
1350
1351 class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
1352     bl_label = "Color"
1353     bl_context = "texture"
1354     bl_options = {'DEFAULT_CLOSED'}
1355
1356     @classmethod
1357     def poll(cls, context):
1358         # node = context.texture_node
1359         return False
1360         # return node and CyclesButtonsPanel.poll(context)
1361
1362     def draw(self, context):
1363         layout = self.layout
1364
1365         node = context.texture_node
1366
1367         mapping = node.color_mapping
1368
1369         split = layout.split()
1370
1371         col = split.column()
1372         col.label(text="Blend:")
1373         col.prop(mapping, "blend_type", text="")
1374         col.prop(mapping, "blend_factor", text="Factor")
1375         col.prop(mapping, "blend_color", text="")
1376
1377         col = split.column()
1378         col.label(text="Adjust:")
1379         col.prop(mapping, "brightness")
1380         col.prop(mapping, "contrast")
1381         col.prop(mapping, "saturation")
1382
1383         layout.separator()
1384
1385         layout.prop(mapping, "use_color_ramp", text="Ramp")
1386         if mapping.use_color_ramp:
1387             layout.template_color_ramp(mapping, "color_ramp", expand=True)
1388
1389
1390 class CyclesParticle_PT_textures(CyclesButtonsPanel, Panel):
1391     bl_label = "Textures"
1392     bl_context = "particle"
1393     bl_options = {'DEFAULT_CLOSED'}
1394
1395     @classmethod
1396     def poll(cls, context):
1397         psys = context.particle_system
1398         return psys and CyclesButtonsPanel.poll(context)
1399
1400     def draw(self, context):
1401         layout = self.layout
1402
1403         psys = context.particle_system
1404         part = psys.settings
1405
1406         row = layout.row()
1407         row.template_list("TEXTURE_UL_texslots", "", part, "texture_slots", part, "active_texture_index", rows=2)
1408
1409         col = row.column(align=True)
1410         col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
1411         col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
1412         col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
1413
1414         if not part.active_texture:
1415             layout.template_ID(part, "active_texture", new="texture.new")
1416         else:
1417             slot = part.texture_slots[part.active_texture_index]
1418             layout.template_ID(slot, "texture", new="texture.new")
1419
1420
1421 class CyclesRender_PT_bake(CyclesButtonsPanel, Panel):
1422     bl_label = "Bake"
1423     bl_context = "render"
1424     bl_options = {'DEFAULT_CLOSED'}
1425     COMPAT_ENGINES = {'CYCLES'}
1426
1427     def draw(self, context):
1428         layout = self.layout
1429
1430         scene = context.scene
1431         cscene = scene.cycles
1432         cbk = scene.render.bake
1433
1434         layout.operator("object.bake", icon='RENDER_STILL').type = cscene.bake_type
1435
1436         col = layout.column()
1437         col.prop(cscene, "bake_type")
1438
1439         col = layout.column()
1440
1441         if cscene.bake_type == 'NORMAL':
1442             col.prop(cbk, "normal_space", text="Space")
1443
1444             row = col.row(align=True)
1445             row.label(text="Swizzle:")
1446             row.prop(cbk, "normal_r", text="")
1447             row.prop(cbk, "normal_g", text="")
1448             row.prop(cbk, "normal_b", text="")
1449
1450         elif cscene.bake_type == 'COMBINED':
1451             row = col.row(align=True)
1452             row.prop(cbk, "use_pass_direct", toggle=True)
1453             row.prop(cbk, "use_pass_indirect", toggle=True)
1454
1455             split = col.split()
1456             split.active = cbk.use_pass_direct or cbk.use_pass_indirect
1457
1458             col = split.column()
1459             col.prop(cbk, "use_pass_diffuse")
1460             col.prop(cbk, "use_pass_glossy")
1461             col.prop(cbk, "use_pass_transmission")
1462
1463             col = split.column()
1464             col.prop(cbk, "use_pass_subsurface")
1465             col.prop(cbk, "use_pass_ambient_occlusion")
1466             col.prop(cbk, "use_pass_emit")
1467
1468         elif cscene.bake_type in {'DIFFUSE', 'GLOSSY', 'TRANSMISSION', 'SUBSURFACE'}:
1469             row = col.row(align=True)
1470             row.prop(cbk, "use_pass_direct", toggle=True)
1471             row.prop(cbk, "use_pass_indirect", toggle=True)
1472             row.prop(cbk, "use_pass_color", toggle=True)
1473
1474         layout.separator()
1475
1476         split = layout.split()
1477
1478         col = split.column()
1479         col.prop(cbk, "margin")
1480         col.prop(cbk, "use_clear")
1481
1482         col = split.column()
1483         col.prop(cbk, "use_selected_to_active")
1484         sub = col.column()
1485         sub.active = cbk.use_selected_to_active
1486         sub.prop(cbk, "use_cage", text="Cage")
1487         if cbk.use_cage:
1488             sub.prop(cbk, "cage_extrusion", text="Extrusion")
1489             sub.prop_search(cbk, "cage_object", scene, "objects", text="")
1490         else:
1491             sub.prop(cbk, "cage_extrusion", text="Ray Distance")
1492
1493
1494 class CyclesRender_PT_debug(CyclesButtonsPanel, Panel):
1495     bl_label = "Debug"
1496     bl_context = "render"
1497     bl_options = {'DEFAULT_CLOSED'}
1498     COMPAT_ENGINES = {'CYCLES'}
1499
1500     @classmethod
1501     def poll(cls, context):
1502         return CyclesButtonsPanel.poll(context) and bpy.app.debug_value == 256
1503
1504     def draw(self, context):
1505         layout = self.layout
1506
1507         scene = context.scene
1508         cscene = scene.cycles
1509
1510         col = layout.column()
1511
1512         col.label('CPU Flags:')
1513         row = col.row(align=True)
1514         row.prop(cscene, "debug_use_cpu_sse2", toggle=True)
1515         row.prop(cscene, "debug_use_cpu_sse3", toggle=True)
1516         row.prop(cscene, "debug_use_cpu_sse41", toggle=True)
1517         row.prop(cscene, "debug_use_cpu_avx", toggle=True)
1518         row.prop(cscene, "debug_use_cpu_avx2", toggle=True)
1519         col.prop(cscene, "debug_use_qbvh")
1520
1521         col = layout.column()
1522         col.label('CUDA Flags:')
1523         col.prop(cscene, "debug_use_cuda_adaptive_compile")
1524
1525         col = layout.column()
1526         col.label('OpenCL Flags:')
1527         col.prop(cscene, "debug_opencl_kernel_type", text="Kernel")
1528         col.prop(cscene, "debug_opencl_device_type", text="Device")
1529         col.prop(cscene, "debug_use_opencl_debug", text="Debug")
1530
1531
1532 class CyclesParticle_PT_CurveSettings(CyclesButtonsPanel, Panel):
1533     bl_label = "Cycles Hair Settings"
1534     bl_context = "particle"
1535
1536     @classmethod
1537     def poll(cls, context):
1538         scene = context.scene
1539         ccscene = scene.cycles_curves
1540         psys = context.particle_system
1541         use_curves = ccscene.use_curves and psys
1542         return CyclesButtonsPanel.poll(context) and use_curves and psys.settings.type == 'HAIR'
1543
1544     def draw(self, context):
1545         layout = self.layout
1546
1547         psys = context.particle_settings
1548         cpsys = psys.cycles
1549
1550         row = layout.row()
1551         row.prop(cpsys, "shape", text="Shape")
1552
1553         layout.label(text="Thickness:")
1554         row = layout.row()
1555         row.prop(cpsys, "root_width", text="Root")
1556         row.prop(cpsys, "tip_width", text="Tip")
1557
1558         row = layout.row()
1559         row.prop(cpsys, "radius_scale", text="Scaling")
1560         row.prop(cpsys, "use_closetip", text="Close tip")
1561
1562
1563 class CyclesScene_PT_simplify(CyclesButtonsPanel, Panel):
1564     bl_label = "Simplify"
1565     bl_context = "scene"
1566     COMPAT_ENGINES = {'CYCLES'}
1567
1568     def draw_header(self, context):
1569         rd = context.scene.render
1570         self.layout.prop(rd, "use_simplify", text="")
1571
1572     def draw(self, context):
1573         layout = self.layout
1574
1575         scene = context.scene
1576         rd = scene.render
1577         cscene = scene.cycles
1578
1579         layout.active = rd.use_simplify
1580
1581         col = layout.column(align=True)
1582         col.label(text="Subdivision")
1583         row = col.row(align=True)
1584         row.prop(rd, "simplify_subdivision", text="Viewport")
1585         row.prop(rd, "simplify_subdivision_render", text="Render")
1586
1587
1588         col = layout.column(align=True)
1589         col.label(text="Child Particles")
1590         row = col.row(align=True)
1591         row.prop(rd, "simplify_child_particles", text="Viewport")
1592         row.prop(rd, "simplify_child_particles_render", text="Render")
1593
1594         col = layout.column(align=True)
1595         split = col.split()
1596         sub = split.column()
1597         sub.label(text="Texture Limit Viewport")
1598         sub.prop(cscene, "texture_limit", text="")
1599         sub = split.column()
1600         sub.label(text="Texture Limit Render")
1601         sub.prop(cscene, "texture_limit_render", text="")
1602
1603         split = layout.split()
1604         col = split.column()
1605         col.prop(cscene, "use_camera_cull")
1606         row = col.row()
1607         row.active = cscene.use_camera_cull
1608         row.prop(cscene, "camera_cull_margin")
1609
1610         col = split.column()
1611         col.prop(cscene, "use_distance_cull")
1612         row = col.row()
1613         row.active = cscene.use_distance_cull
1614         row.prop(cscene, "distance_cull_margin", text="Distance")
1615
1616 def draw_device(self, context):
1617     scene = context.scene
1618     layout = self.layout
1619
1620     if scene.render.engine == 'CYCLES':
1621         from . import engine
1622         cscene = scene.cycles
1623
1624         layout.prop(cscene, "feature_set")
1625
1626         split = layout.split(percentage=1/3)
1627         split.label("Device:")
1628         row = split.row()
1629         row.active = show_device_selection(context)
1630         row.prop(cscene, "device", text="")
1631
1632         if engine.with_osl() and use_cpu(context):
1633             layout.prop(cscene, "shading_system")
1634
1635
1636 def draw_pause(self, context):
1637     layout = self.layout
1638     scene = context.scene
1639
1640     if scene.render.engine == "CYCLES":
1641         view = context.space_data
1642
1643         if view.viewport_shade == 'RENDERED':
1644             cscene = scene.cycles
1645             layername = scene.render.layers.active.name
1646             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1647             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1648
1649
1650 def get_panels():
1651     exclude_panels = {
1652         'DATA_PT_area',
1653         'DATA_PT_camera_dof',
1654         'DATA_PT_falloff_curve',
1655         'DATA_PT_lamp',
1656         'DATA_PT_preview',
1657         'DATA_PT_shadow',
1658         'DATA_PT_spot',
1659         'DATA_PT_sunsky',
1660         'MATERIAL_PT_context_material',
1661         'MATERIAL_PT_diffuse',
1662         'MATERIAL_PT_flare',
1663         'MATERIAL_PT_halo',
1664         'MATERIAL_PT_mirror',
1665         'MATERIAL_PT_options',
1666         'MATERIAL_PT_pipeline',
1667         'MATERIAL_PT_preview',
1668         'MATERIAL_PT_shading',
1669         'MATERIAL_PT_shadow',
1670         'MATERIAL_PT_specular',
1671         'MATERIAL_PT_sss',
1672         'MATERIAL_PT_strand',
1673         'MATERIAL_PT_transp',
1674         'MATERIAL_PT_volume_density',
1675         'MATERIAL_PT_volume_integration',
1676         'MATERIAL_PT_volume_lighting',
1677         'MATERIAL_PT_volume_options',
1678         'MATERIAL_PT_volume_shading',
1679         'MATERIAL_PT_volume_transp',
1680         'RENDERLAYER_PT_layer_options',
1681         'RENDERLAYER_PT_layer_passes',
1682         'RENDERLAYER_PT_views',
1683         'RENDER_PT_antialiasing',
1684         'RENDER_PT_bake',
1685         'RENDER_PT_motion_blur',
1686         'RENDER_PT_performance',
1687         'RENDER_PT_post_processing',
1688         'RENDER_PT_shading',
1689         'SCENE_PT_simplify',
1690         'TEXTURE_PT_context_texture',
1691         'WORLD_PT_ambient_occlusion',
1692         'WORLD_PT_environment_lighting',
1693         'WORLD_PT_gather',
1694         'WORLD_PT_indirect_lighting',
1695         'WORLD_PT_mist',
1696         'WORLD_PT_preview',
1697         'WORLD_PT_world'
1698         }
1699
1700     panels = []
1701     for panel in bpy.types.Panel.__subclasses__():
1702         if hasattr(panel, 'COMPAT_ENGINES') and 'BLENDER_RENDER' in panel.COMPAT_ENGINES:
1703             if panel.__name__ not in exclude_panels:
1704                 panels.append(panel)
1705
1706     return panels
1707
1708 def register():
1709     bpy.types.RENDER_PT_render.append(draw_device)
1710     bpy.types.VIEW3D_HT_header.append(draw_pause)
1711
1712     for panel in get_panels():
1713         panel.COMPAT_ENGINES.add('CYCLES')
1714
1715 def unregister():
1716     bpy.types.RENDER_PT_render.remove(draw_device)
1717     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1718
1719     for panel in get_panels():
1720         if 'CYCLES' in panel.COMPAT_ENGINES:
1721             panel.COMPAT_ENGINES.remove('CYCLES')