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