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