Fix C++11 building on MSVC 2015
[blender.git] / intern / cycles / blender / addon / ui.py
1 #
2 # Copyright 2011-2013 Blender Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 # <pep8 compliant>
18
19 import bpy
20
21 from bpy.types import (
22         Panel,
23         Menu,
24         Operator,
25         )
26
27
28 class CYCLES_MT_sampling_presets(Menu):
29     bl_label = "Sampling Presets"
30     preset_subdir = "cycles/sampling"
31     preset_operator = "script.execute_preset"
32     COMPAT_ENGINES = {'CYCLES'}
33     draw = Menu.draw_preset
34
35
36 class CYCLES_MT_integrator_presets(Menu):
37     bl_label = "Integrator Presets"
38     preset_subdir = "cycles/integrator"
39     preset_operator = "script.execute_preset"
40     COMPAT_ENGINES = {'CYCLES'}
41     draw = Menu.draw_preset
42
43
44 class CyclesButtonsPanel:
45     bl_space_type = "PROPERTIES"
46     bl_region_type = "WINDOW"
47     bl_context = "render"
48     COMPAT_ENGINES = {'CYCLES'}
49
50     @classmethod
51     def poll(cls, context):
52         rd = context.scene.render
53         return rd.engine in cls.COMPAT_ENGINES
54
55
56 def get_device_type(context):
57     return context.user_preferences.addons[__package__].preferences.compute_device_type
58
59
60 def use_cpu(context):
61     cscene = context.scene.cycles
62
63     return (get_device_type(context) == 'NONE' or cscene.device == 'CPU')
64
65
66 def use_opencl(context):
67     cscene = context.scene.cycles
68
69     return (get_device_type(context) == 'OPENCL' and cscene.device == 'GPU')
70
71
72 def use_cuda(context):
73     cscene = context.scene.cycles
74
75     return (get_device_type(context) == 'CUDA' and cscene.device == 'GPU')
76
77
78 def use_branched_path(context):
79     cscene = context.scene.cycles
80
81     return (cscene.progressive == 'BRANCHED_PATH' and not use_opencl(context))
82
83
84 def use_sample_all_lights(context):
85     cscene = context.scene.cycles
86
87     return cscene.sample_all_lights_direct or cscene.sample_all_lights_indirect
88
89 def show_device_selection(context):
90     type = get_device_type(context)
91     if type == 'NETWORK':
92         return True
93     if not type in {'CUDA', 'OPENCL'}:
94         return False
95     return context.user_preferences.addons[__package__].preferences.has_active_device()
96
97
98 def draw_samples_info(layout, context):
99     cscene = context.scene.cycles
100     integrator = cscene.progressive
101
102     # Calculate sample values
103     if integrator == 'PATH':
104         aa = cscene.samples
105         if cscene.use_square_samples:
106             aa = aa * aa
107     else:
108         aa = cscene.aa_samples
109         d = cscene.diffuse_samples
110         g = cscene.glossy_samples
111         t = cscene.transmission_samples
112         ao = cscene.ao_samples
113         ml = cscene.mesh_light_samples
114         sss = cscene.subsurface_samples
115         vol = cscene.volume_samples
116
117         if cscene.use_square_samples:
118             aa = aa * aa
119             d = d * d
120             g = g * g
121             t = t * t
122             ao = ao * ao
123             ml = ml * ml
124             sss = sss * sss
125             vol = vol * vol
126
127     # Draw interface
128     # Do not draw for progressive, when Square Samples are disabled
129     if use_branched_path(context) or (cscene.use_square_samples and integrator == 'PATH'):
130         col = layout.column(align=True)
131         col.scale_y = 0.6
132         col.label("Total Samples:")
133         col.separator()
134         if integrator == 'PATH':
135             col.label("%s AA" % aa)
136         else:
137             col.label("%s AA, %s Diffuse, %s Glossy, %s Transmission" %
138                       (aa, d * aa, g * aa, t * aa))
139             col.separator()
140             col.label("%s AO, %s Mesh Light, %s Subsurface, %s Volume" %
141                       (ao * aa, ml * aa, sss * aa, vol * aa))
142
143
144 class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel):
145     bl_label = "Sampling"
146     bl_options = {'DEFAULT_CLOSED'}
147
148     def draw(self, context):
149         layout = self.layout
150
151         scene = context.scene
152         cscene = scene.cycles
153
154         row = layout.row(align=True)
155         row.menu("CYCLES_MT_sampling_presets", text=bpy.types.CYCLES_MT_sampling_presets.bl_label)
156         row.operator("render.cycles_sampling_preset_add", text="", icon="ZOOMIN")
157         row.operator("render.cycles_sampling_preset_add", text="", icon="ZOOMOUT").remove_active = True
158
159         row = layout.row()
160         sub = row.row()
161         sub.active = get_device_type(context) != 'OPENCL' or use_cpu(context)
162         sub.prop(cscene, "progressive", text="")
163         row.prop(cscene, "use_square_samples")
164
165         split = layout.split()
166
167         col = split.column()
168         sub = col.column(align=True)
169         sub.label("Settings:")
170
171         seed_sub = sub.row(align=True)
172         seed_sub.prop(cscene, "seed")
173         seed_sub.prop(cscene, "use_animated_seed", text="", icon="TIME")
174
175         sub.prop(cscene, "sample_clamp_direct")
176         sub.prop(cscene, "sample_clamp_indirect")
177         sub.prop(cscene, "light_sampling_threshold")
178
179         if cscene.progressive == 'PATH' or use_branched_path(context) is False:
180             col = split.column()
181             sub = col.column(align=True)
182             sub.label(text="Samples:")
183             sub.prop(cscene, "samples", text="Render")
184             sub.prop(cscene, "preview_samples", text="Preview")
185         else:
186             sub.label(text="AA Samples:")
187             sub.prop(cscene, "aa_samples", text="Render")
188             sub.prop(cscene, "preview_aa_samples", text="Preview")
189             sub.separator()
190             sub.prop(cscene, "sample_all_lights_direct")
191             sub.prop(cscene, "sample_all_lights_indirect")
192
193             col = split.column()
194             sub = col.column(align=True)
195             sub.label(text="Samples:")
196             sub.prop(cscene, "diffuse_samples", text="Diffuse")
197             sub.prop(cscene, "glossy_samples", text="Glossy")
198             sub.prop(cscene, "transmission_samples", text="Transmission")
199             sub.prop(cscene, "ao_samples", text="AO")
200
201             subsub = sub.row(align=True)
202             subsub.active = use_sample_all_lights(context)
203             subsub.prop(cscene, "mesh_light_samples", text="Mesh Light")
204
205             sub.prop(cscene, "subsurface_samples", text="Subsurface")
206             sub.prop(cscene, "volume_samples", text="Volume")
207
208         if not (use_opencl(context) and cscene.feature_set != 'EXPERIMENTAL'):
209             layout.row().prop(cscene, "sampling_pattern", text="Pattern")
210
211         for rl in scene.render.layers:
212             if rl.samples > 0:
213                 layout.separator()
214                 layout.row().prop(cscene, "use_layer_samples")
215                 break
216
217         draw_samples_info(layout, context)
218
219
220 class CyclesRender_PT_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 CyclesRender_PT_CurveRendering(CyclesButtonsPanel, Panel):
1362     bl_label = "Cycles Hair Rendering"
1363     bl_context = "particle"
1364
1365     @classmethod
1366     def poll(cls, context):
1367         psys = context.particle_system
1368         return CyclesButtonsPanel.poll(context) and psys and psys.settings.type == 'HAIR'
1369
1370     def draw_header(self, context):
1371         ccscene = context.scene.cycles_curves
1372         self.layout.prop(ccscene, "use_curves", text="")
1373
1374     def draw(self, context):
1375         layout = self.layout
1376
1377         scene = context.scene
1378         ccscene = scene.cycles_curves
1379
1380         layout.active = ccscene.use_curves
1381
1382         layout.prop(ccscene, "primitive", text="Primitive")
1383         layout.prop(ccscene, "shape", text="Shape")
1384
1385         if not (ccscene.primitive in {'CURVE_SEGMENTS', 'LINE_SEGMENTS'} and ccscene.shape == 'RIBBONS'):
1386             layout.prop(ccscene, "cull_backfacing", text="Cull back-faces")
1387
1388         if ccscene.primitive == 'TRIANGLES' and ccscene.shape == 'THICK':
1389             layout.prop(ccscene, "resolution", text="Resolution")
1390         elif ccscene.primitive == 'CURVE_SEGMENTS':
1391             layout.prop(ccscene, "subdivisions", text="Curve subdivisions")
1392
1393         row = layout.row()
1394         row.prop(ccscene, "minimum_width", text="Min Pixels")
1395         row.prop(ccscene, "maximum_width", text="Max Ext.")
1396
1397
1398 class CyclesRender_PT_bake(CyclesButtonsPanel, Panel):
1399     bl_label = "Bake"
1400     bl_context = "render"
1401     bl_options = {'DEFAULT_CLOSED'}
1402     COMPAT_ENGINES = {'CYCLES'}
1403
1404     def draw(self, context):
1405         layout = self.layout
1406
1407         scene = context.scene
1408         cscene = scene.cycles
1409         cbk = scene.render.bake
1410
1411         layout.operator("object.bake", icon='RENDER_STILL').type = cscene.bake_type
1412
1413         col = layout.column()
1414         col.prop(cscene, "bake_type")
1415
1416         col = layout.column()
1417
1418         if cscene.bake_type == 'NORMAL':
1419             col.prop(cbk, "normal_space", text="Space")
1420
1421             row = col.row(align=True)
1422             row.label(text="Swizzle:")
1423             row.prop(cbk, "normal_r", text="")
1424             row.prop(cbk, "normal_g", text="")
1425             row.prop(cbk, "normal_b", text="")
1426
1427         elif cscene.bake_type == 'COMBINED':
1428             row = col.row(align=True)
1429             row.prop(cbk, "use_pass_direct", toggle=True)
1430             row.prop(cbk, "use_pass_indirect", toggle=True)
1431
1432             split = col.split()
1433             split.active = cbk.use_pass_direct or cbk.use_pass_indirect
1434
1435             col = split.column()
1436             col.prop(cbk, "use_pass_diffuse")
1437             col.prop(cbk, "use_pass_glossy")
1438             col.prop(cbk, "use_pass_transmission")
1439
1440             col = split.column()
1441             col.prop(cbk, "use_pass_subsurface")
1442             col.prop(cbk, "use_pass_ambient_occlusion")
1443             col.prop(cbk, "use_pass_emit")
1444
1445         elif cscene.bake_type in {'DIFFUSE', 'GLOSSY', 'TRANSMISSION', 'SUBSURFACE'}:
1446             row = col.row(align=True)
1447             row.prop(cbk, "use_pass_direct", toggle=True)
1448             row.prop(cbk, "use_pass_indirect", toggle=True)
1449             row.prop(cbk, "use_pass_color", toggle=True)
1450
1451         layout.separator()
1452
1453         split = layout.split()
1454
1455         col = split.column()
1456         col.prop(cbk, "margin")
1457         col.prop(cbk, "use_clear")
1458
1459         col = split.column()
1460         col.prop(cbk, "use_selected_to_active")
1461         sub = col.column()
1462         sub.active = cbk.use_selected_to_active
1463         sub.prop(cbk, "use_cage", text="Cage")
1464         if cbk.use_cage:
1465             sub.prop(cbk, "cage_extrusion", text="Extrusion")
1466             sub.prop_search(cbk, "cage_object", scene, "objects", text="")
1467         else:
1468             sub.prop(cbk, "cage_extrusion", text="Ray Distance")
1469
1470
1471 class CyclesRender_PT_debug(CyclesButtonsPanel, Panel):
1472     bl_label = "Debug"
1473     bl_context = "render"
1474     bl_options = {'DEFAULT_CLOSED'}
1475     COMPAT_ENGINES = {'CYCLES'}
1476
1477     @classmethod
1478     def poll(cls, context):
1479         return CyclesButtonsPanel.poll(context) and bpy.app.debug_value == 256
1480
1481     def draw(self, context):
1482         layout = self.layout
1483
1484         scene = context.scene
1485         cscene = scene.cycles
1486
1487         col = layout.column()
1488
1489         col.label('CPU Flags:')
1490         row = col.row(align=True)
1491         row.prop(cscene, "debug_use_cpu_sse2", toggle=True)
1492         row.prop(cscene, "debug_use_cpu_sse3", toggle=True)
1493         row.prop(cscene, "debug_use_cpu_sse41", toggle=True)
1494         row.prop(cscene, "debug_use_cpu_avx", toggle=True)
1495         row.prop(cscene, "debug_use_cpu_avx2", toggle=True)
1496         col.prop(cscene, "debug_use_qbvh")
1497
1498         col = layout.column()
1499         col.label('CUDA Flags:')
1500         col.prop(cscene, "debug_use_cuda_adaptive_compile")
1501
1502         col = layout.column()
1503         col.label('OpenCL Flags:')
1504         col.prop(cscene, "debug_opencl_kernel_type", text="Kernel")
1505         col.prop(cscene, "debug_opencl_device_type", text="Device")
1506         col.prop(cscene, "debug_use_opencl_debug", text="Debug")
1507
1508
1509 class CyclesScene_PT_simplify(CyclesButtonsPanel, Panel):
1510     bl_label = "Simplify"
1511     bl_context = "scene"
1512     COMPAT_ENGINES = {'CYCLES'}
1513
1514     def draw_header(self, context):
1515         rd = context.scene.render
1516         self.layout.prop(rd, "use_simplify", text="")
1517
1518     def draw(self, context):
1519         layout = self.layout
1520
1521         scene = context.scene
1522         rd = scene.render
1523         cscene = scene.cycles
1524
1525         layout.active = rd.use_simplify
1526         split = layout.split()
1527
1528         col = split.column()
1529         col.label(text="Viewport:")
1530         col.prop(rd, "simplify_subdivision", text="Subdivision")
1531
1532         col = split.column()
1533         col.label(text="Render:")
1534         col.prop(rd, "simplify_subdivision_render", text="Subdivision")
1535
1536         col = layout.column()
1537         col.prop(cscene, "use_camera_cull")
1538         subsub = col.column()
1539         subsub.active = cscene.use_camera_cull
1540         subsub.prop(cscene, "camera_cull_margin")
1541
1542
1543 def draw_device(self, context):
1544     scene = context.scene
1545     layout = self.layout
1546
1547     if scene.render.engine == 'CYCLES':
1548         from . import engine
1549         cscene = scene.cycles
1550
1551         layout.prop(cscene, "feature_set")
1552
1553         split = layout.split(percentage=1/3)
1554         split.label("Device:")
1555         row = split.row(align=True)
1556         sub = row.split(align=True)
1557         sub.active = show_device_selection(context)
1558         sub.prop(cscene, "device", text="")
1559         row.operator("wm.addon_userpref_show", text="", icon='PREFERENCES').module = __package__
1560
1561         if engine.with_osl() and use_cpu(context):
1562             layout.prop(cscene, "shading_system")
1563
1564
1565 def draw_pause(self, context):
1566     layout = self.layout
1567     scene = context.scene
1568
1569     if scene.render.engine == "CYCLES":
1570         view = context.space_data
1571
1572         if view.viewport_shade == 'RENDERED':
1573             cscene = scene.cycles
1574             layername = scene.render.layers.active.name
1575             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1576             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1577
1578
1579 def get_panels():
1580     exclude_panels = {
1581         'DATA_PT_area',
1582         'DATA_PT_camera_dof',
1583         'DATA_PT_falloff_curve',
1584         'DATA_PT_lamp',
1585         'DATA_PT_preview',
1586         'DATA_PT_shadow',
1587         'DATA_PT_spot',
1588         'DATA_PT_sunsky',
1589         'MATERIAL_PT_context_material',
1590         'MATERIAL_PT_diffuse',
1591         'MATERIAL_PT_flare',
1592         'MATERIAL_PT_halo',
1593         'MATERIAL_PT_mirror',
1594         'MATERIAL_PT_options',
1595         'MATERIAL_PT_pipeline',
1596         'MATERIAL_PT_preview',
1597         'MATERIAL_PT_shading',
1598         'MATERIAL_PT_shadow',
1599         'MATERIAL_PT_specular',
1600         'MATERIAL_PT_sss',
1601         'MATERIAL_PT_strand',
1602         'MATERIAL_PT_transp',
1603         'MATERIAL_PT_volume_density',
1604         'MATERIAL_PT_volume_integration',
1605         'MATERIAL_PT_volume_lighting',
1606         'MATERIAL_PT_volume_options',
1607         'MATERIAL_PT_volume_shading',
1608         'MATERIAL_PT_volume_transp',
1609         'RENDERLAYER_PT_layer_options',
1610         'RENDERLAYER_PT_layer_passes',
1611         'RENDERLAYER_PT_views',
1612         'RENDER_PT_antialiasing',
1613         'RENDER_PT_bake',
1614         'RENDER_PT_motion_blur',
1615         'RENDER_PT_performance',
1616         'RENDER_PT_post_processing',
1617         'RENDER_PT_shading',
1618         'SCENE_PT_simplify',
1619         'TEXTURE_PT_context_texture',
1620         'WORLD_PT_ambient_occlusion',
1621         'WORLD_PT_environment_lighting',
1622         'WORLD_PT_gather',
1623         'WORLD_PT_indirect_lighting',
1624         'WORLD_PT_mist',
1625         'WORLD_PT_preview',
1626         'WORLD_PT_world'
1627         }
1628
1629     panels = []
1630     for panel in bpy.types.Panel.__subclasses__():
1631         if hasattr(panel, 'COMPAT_ENGINES') and 'BLENDER_RENDER' in panel.COMPAT_ENGINES:
1632             if panel.__name__ not in exclude_panels:
1633                 panels.append(panel)
1634
1635     return panels
1636
1637 def register():
1638     bpy.types.RENDER_PT_render.append(draw_device)
1639     bpy.types.VIEW3D_HT_header.append(draw_pause)
1640
1641     for panel in get_panels():
1642         panel.COMPAT_ENGINES.add('CYCLES')
1643
1644 def unregister():
1645     bpy.types.RENDER_PT_render.remove(draw_device)
1646     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1647
1648     for panel in get_panels():
1649         if 'CYCLES' in panel.COMPAT_ENGINES:
1650             panel.COMPAT_ENGINES.remove('CYCLES')