Cycles: distance culling for objects.
[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         row.active = scene.render.use_simplify and cscene.use_distance_cull
773         row.prop(cob, "use_distance_cull")
774
775
776 class CYCLES_OT_use_shading_nodes(Operator):
777     """Enable nodes on a material, world or lamp"""
778     bl_idname = "cycles.use_shading_nodes"
779     bl_label = "Use Nodes"
780
781     @classmethod
782     def poll(cls, context):
783         return (getattr(context, "material", False) or getattr(context, "world", False) or
784                 getattr(context, "lamp", False))
785
786     def execute(self, context):
787         if context.material:
788             context.material.use_nodes = True
789         elif context.world:
790             context.world.use_nodes = True
791         elif context.lamp:
792             context.lamp.use_nodes = True
793
794         return {'FINISHED'}
795
796
797 def find_node(material, nodetype):
798     if material and material.node_tree:
799         ntree = material.node_tree
800
801         active_output_node = None
802         for node in ntree.nodes:
803             if getattr(node, "type", None) == nodetype:
804                 if getattr(node, "is_active_output", True):
805                     return node
806                 if not active_output_node:
807                     active_output_node = node
808         return active_output_node
809
810     return None
811
812
813 def find_node_input(node, name):
814     for input in node.inputs:
815         if input.name == name:
816             return input
817
818     return None
819
820
821 def panel_node_draw(layout, id_data, output_type, input_name):
822     if not id_data.use_nodes:
823         layout.operator("cycles.use_shading_nodes", icon='NODETREE')
824         return False
825
826     ntree = id_data.node_tree
827
828     node = find_node(id_data, output_type)
829     if not node:
830         layout.label(text="No output node")
831     else:
832         input = find_node_input(node, input_name)
833         layout.template_node_view(ntree, node, input)
834
835     return True
836
837
838 class CyclesLamp_PT_preview(CyclesButtonsPanel, Panel):
839     bl_label = "Preview"
840     bl_context = "data"
841     bl_options = {'DEFAULT_CLOSED'}
842
843     @classmethod
844     def poll(cls, context):
845         return context.lamp and \
846                not (context.lamp.type == 'AREA' and
847                     context.lamp.cycles.is_portal) \
848                and CyclesButtonsPanel.poll(context)
849
850     def draw(self, context):
851         self.layout.template_preview(context.lamp)
852
853
854 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
855     bl_label = "Lamp"
856     bl_context = "data"
857
858     @classmethod
859     def poll(cls, context):
860         return context.lamp and CyclesButtonsPanel.poll(context)
861
862     def draw(self, context):
863         layout = self.layout
864
865         lamp = context.lamp
866         clamp = lamp.cycles
867         # cscene = context.scene.cycles
868
869         layout.prop(lamp, "type", expand=True)
870
871         split = layout.split()
872         col = split.column(align=True)
873
874         if lamp.type in {'POINT', 'SUN', 'SPOT'}:
875             col.prop(lamp, "shadow_soft_size", text="Size")
876         elif lamp.type == 'AREA':
877             col.prop(lamp, "shape", text="")
878             sub = col.column(align=True)
879
880             if lamp.shape == 'SQUARE':
881                 sub.prop(lamp, "size")
882             elif lamp.shape == 'RECTANGLE':
883                 sub.prop(lamp, "size", text="Size X")
884                 sub.prop(lamp, "size_y", text="Size Y")
885
886         if not (lamp.type == 'AREA' and clamp.is_portal):
887             sub = col.column(align=True)
888             if use_branched_path(context):
889                 subsub = sub.row(align=True)
890                 subsub.active = use_sample_all_lights(context)
891                 subsub.prop(clamp, "samples")
892             sub.prop(clamp, "max_bounces")
893
894         col = split.column()
895
896         sub = col.column(align=True)
897         sub.active = not (lamp.type == 'AREA' and clamp.is_portal)
898         sub.prop(clamp, "cast_shadow")
899         sub.prop(clamp, "use_multiple_importance_sampling", text="Multiple Importance")
900
901         if lamp.type == 'AREA':
902             col.prop(clamp, "is_portal", text="Portal")
903
904         if lamp.type == 'HEMI':
905             layout.label(text="Not supported, interpreted as sun lamp")
906
907
908 class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
909     bl_label = "Nodes"
910     bl_context = "data"
911
912     @classmethod
913     def poll(cls, context):
914         return context.lamp and not (context.lamp.type == 'AREA' and
915                                      context.lamp.cycles.is_portal) and \
916                CyclesButtonsPanel.poll(context)
917
918     def draw(self, context):
919         layout = self.layout
920
921         lamp = context.lamp
922         if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
923             layout.prop(lamp, "color")
924
925
926 class CyclesLamp_PT_spot(CyclesButtonsPanel, Panel):
927     bl_label = "Spot Shape"
928     bl_context = "data"
929
930     @classmethod
931     def poll(cls, context):
932         lamp = context.lamp
933         return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context)
934
935     def draw(self, context):
936         layout = self.layout
937
938         lamp = context.lamp
939
940         split = layout.split()
941
942         col = split.column()
943         sub = col.column()
944         sub.prop(lamp, "spot_size", text="Size")
945         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
946
947         col = split.column()
948         col.prop(lamp, "show_cone")
949
950
951 class CyclesWorld_PT_preview(CyclesButtonsPanel, Panel):
952     bl_label = "Preview"
953     bl_context = "world"
954     bl_options = {'DEFAULT_CLOSED'}
955
956     @classmethod
957     def poll(cls, context):
958         return context.world and CyclesButtonsPanel.poll(context)
959
960     def draw(self, context):
961         self.layout.template_preview(context.world)
962
963
964 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
965     bl_label = "Surface"
966     bl_context = "world"
967
968     @classmethod
969     def poll(cls, context):
970         return context.world and CyclesButtonsPanel.poll(context)
971
972     def draw(self, context):
973         layout = self.layout
974
975         world = context.world
976
977         if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
978             layout.prop(world, "horizon_color", text="Color")
979
980
981 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
982     bl_label = "Volume"
983     bl_context = "world"
984     bl_options = {'DEFAULT_CLOSED'}
985
986     @classmethod
987     def poll(cls, context):
988         world = context.world
989         return world and world.node_tree and CyclesButtonsPanel.poll(context)
990
991     def draw(self, context):
992         layout = self.layout
993
994         world = context.world
995         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
996
997
998 class CyclesWorld_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
999     bl_label = "Ambient Occlusion"
1000     bl_context = "world"
1001
1002     @classmethod
1003     def poll(cls, context):
1004         return context.world and CyclesButtonsPanel.poll(context)
1005
1006     def draw_header(self, context):
1007         light = context.world.light_settings
1008         self.layout.prop(light, "use_ambient_occlusion", text="")
1009
1010     def draw(self, context):
1011         layout = self.layout
1012
1013         light = context.world.light_settings
1014
1015         row = layout.row()
1016         sub = row.row()
1017         sub.active = light.use_ambient_occlusion
1018         sub.prop(light, "ao_factor", text="Factor")
1019         row.prop(light, "distance", text="Distance")
1020
1021
1022 class CyclesWorld_PT_mist(CyclesButtonsPanel, Panel):
1023     bl_label = "Mist Pass"
1024     bl_context = "world"
1025     bl_options = {'DEFAULT_CLOSED'}
1026
1027     @classmethod
1028     def poll(cls, context):
1029         if CyclesButtonsPanel.poll(context):
1030             if context.world:
1031                 for rl in context.scene.render.layers:
1032                     if rl.use_pass_mist:
1033                         return True
1034
1035         return False
1036
1037     def draw(self, context):
1038         layout = self.layout
1039
1040         world = context.world
1041
1042         split = layout.split(align=True)
1043         split.prop(world.mist_settings, "start")
1044         split.prop(world.mist_settings, "depth")
1045
1046         layout.prop(world.mist_settings, "falloff")
1047
1048
1049 class CyclesWorld_PT_ray_visibility(CyclesButtonsPanel, Panel):
1050     bl_label = "Ray Visibility"
1051     bl_context = "world"
1052     bl_options = {'DEFAULT_CLOSED'}
1053
1054     @classmethod
1055     def poll(cls, context):
1056         return CyclesButtonsPanel.poll(context) and context.world
1057
1058     def draw(self, context):
1059         layout = self.layout
1060
1061         world = context.world
1062         visibility = world.cycles_visibility
1063
1064         flow = layout.column_flow()
1065
1066         flow.prop(visibility, "camera")
1067         flow.prop(visibility, "diffuse")
1068         flow.prop(visibility, "glossy")
1069         flow.prop(visibility, "transmission")
1070         flow.prop(visibility, "scatter")
1071
1072
1073 class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
1074     bl_label = "Settings"
1075     bl_context = "world"
1076     bl_options = {'DEFAULT_CLOSED'}
1077
1078     @classmethod
1079     def poll(cls, context):
1080         return context.world and CyclesButtonsPanel.poll(context)
1081
1082     def draw(self, context):
1083         layout = self.layout
1084
1085         world = context.world
1086         cworld = world.cycles
1087         # cscene = context.scene.cycles
1088
1089         split = layout.split()
1090
1091         col = split.column()
1092
1093         col.label(text="Surface:")
1094         col.prop(cworld, "sample_as_light", text="Multiple Importance")
1095
1096         sub = col.column(align=True)
1097         sub.active = cworld.sample_as_light
1098         sub.prop(cworld, "sample_map_resolution")
1099         if use_branched_path(context):
1100             subsub = sub.row(align=True)
1101             subsub.active = use_sample_all_lights(context)
1102             subsub.prop(cworld, "samples")
1103         sub.prop(cworld, "max_bounces")
1104
1105         col = split.column()
1106         col.label(text="Volume:")
1107         sub = col.column()
1108         sub.active = use_cpu(context)
1109         sub.prop(cworld, "volume_sampling", text="")
1110         sub.prop(cworld, "volume_interpolation", text="")
1111         col.prop(cworld, "homogeneous_volume", text="Homogeneous")
1112
1113
1114 class CyclesMaterial_PT_preview(CyclesButtonsPanel, Panel):
1115     bl_label = "Preview"
1116     bl_context = "material"
1117     bl_options = {'DEFAULT_CLOSED'}
1118
1119     @classmethod
1120     def poll(cls, context):
1121         return context.material and CyclesButtonsPanel.poll(context)
1122
1123     def draw(self, context):
1124         self.layout.template_preview(context.material)
1125
1126
1127 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
1128     bl_label = "Surface"
1129     bl_context = "material"
1130
1131     @classmethod
1132     def poll(cls, context):
1133         return context.material and CyclesButtonsPanel.poll(context)
1134
1135     def draw(self, context):
1136         layout = self.layout
1137
1138         mat = context.material
1139         if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
1140             layout.prop(mat, "diffuse_color")
1141
1142
1143 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
1144     bl_label = "Volume"
1145     bl_context = "material"
1146     bl_options = {'DEFAULT_CLOSED'}
1147
1148     @classmethod
1149     def poll(cls, context):
1150         mat = context.material
1151         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
1152
1153     def draw(self, context):
1154         layout = self.layout
1155
1156         mat = context.material
1157         # cmat = mat.cycles
1158
1159         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
1160
1161
1162 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
1163     bl_label = "Displacement"
1164     bl_context = "material"
1165
1166     @classmethod
1167     def poll(cls, context):
1168         mat = context.material
1169         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
1170
1171     def draw(self, context):
1172         layout = self.layout
1173
1174         mat = context.material
1175         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
1176
1177
1178 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
1179     bl_label = "Settings"
1180     bl_context = "material"
1181     bl_options = {'DEFAULT_CLOSED'}
1182
1183     @classmethod
1184     def poll(cls, context):
1185         return context.material and CyclesButtonsPanel.poll(context)
1186
1187     def draw(self, context):
1188         layout = self.layout
1189
1190         mat = context.material
1191         cmat = mat.cycles
1192
1193         split = layout.split()
1194         col = split.column()
1195         col.label(text="Surface:")
1196         col.prop(cmat, "sample_as_light", text="Multiple Importance")
1197         col.prop(cmat, "use_transparent_shadow")
1198
1199         if context.scene.cycles.feature_set == 'EXPERIMENTAL':
1200             col.separator()
1201             col.label(text="Displacement:")
1202             col.prop(cmat, "displacement_method", text="")
1203
1204         col = split.column()
1205         col.label(text="Volume:")
1206         sub = col.column()
1207         sub.active = use_cpu(context)
1208         sub.prop(cmat, "volume_sampling", text="")
1209         sub.prop(cmat, "volume_interpolation", text="")
1210         col.prop(cmat, "homogeneous_volume", text="Homogeneous")
1211
1212         layout.separator()
1213         split = layout.split()
1214
1215         col = split.column(align=True)
1216         col.label("Viewport Color:")
1217         col.prop(mat, "diffuse_color", text="")
1218         col.prop(mat, "alpha")
1219
1220         col.separator()
1221         col.label("Viewport Alpha:")
1222         col.prop(mat.game_settings, "alpha_blend", text="")
1223
1224         col = split.column(align=True)
1225         col.label("Viewport Specular:")
1226         col.prop(mat, "specular_color", text="")
1227         col.prop(mat, "specular_hardness", text="Hardness")
1228
1229         col.separator()
1230         col.prop(mat, "pass_index")
1231
1232
1233 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
1234     bl_label = ""
1235     bl_context = "texture"
1236     bl_options = {'HIDE_HEADER'}
1237     COMPAT_ENGINES = {'CYCLES'}
1238
1239     def draw(self, context):
1240         layout = self.layout
1241
1242         tex = context.texture
1243         space = context.space_data
1244         pin_id = space.pin_id
1245         use_pin_id = space.use_pin_id
1246         user = context.texture_user
1247
1248         space.use_limited_texture_context = False
1249
1250         if not (use_pin_id and isinstance(pin_id, bpy.types.Texture)):
1251             pin_id = None
1252
1253         if not pin_id:
1254             layout.template_texture_user()
1255
1256         if user or pin_id:
1257             layout.separator()
1258
1259             split = layout.split(percentage=0.65)
1260             col = split.column()
1261
1262             if pin_id:
1263                 col.template_ID(space, "pin_id")
1264             else:
1265                 propname = context.texture_user_property.identifier
1266                 col.template_ID(user, propname, new="texture.new")
1267
1268             if tex:
1269                 split = layout.split(percentage=0.2)
1270                 split.label(text="Type:")
1271                 split.prop(tex, "type", text="")
1272
1273
1274 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
1275     bl_label = "Node"
1276     bl_context = "texture"
1277
1278     @classmethod
1279     def poll(cls, context):
1280         node = context.texture_node
1281         return node and CyclesButtonsPanel.poll(context)
1282
1283     def draw(self, context):
1284         layout = self.layout
1285
1286         node = context.texture_node
1287         ntree = node.id_data
1288         layout.template_node_view(ntree, node, None)
1289
1290
1291 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
1292     bl_label = "Mapping"
1293     bl_context = "texture"
1294
1295     @classmethod
1296     def poll(cls, context):
1297         node = context.texture_node
1298         # TODO(sergey): perform a faster/nicer check?
1299         return node and hasattr(node, 'texture_mapping') and CyclesButtonsPanel.poll(context)
1300
1301     def draw(self, context):
1302         layout = self.layout
1303
1304         node = context.texture_node
1305
1306         mapping = node.texture_mapping
1307
1308         layout.prop(mapping, "vector_type", expand=True)
1309
1310         row = layout.row()
1311
1312         row.column().prop(mapping, "translation")
1313         row.column().prop(mapping, "rotation")
1314         row.column().prop(mapping, "scale")
1315
1316         layout.label(text="Projection:")
1317
1318         row = layout.row()
1319         row.prop(mapping, "mapping_x", text="")
1320         row.prop(mapping, "mapping_y", text="")
1321         row.prop(mapping, "mapping_z", text="")
1322
1323
1324 class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
1325     bl_label = "Color"
1326     bl_context = "texture"
1327     bl_options = {'DEFAULT_CLOSED'}
1328
1329     @classmethod
1330     def poll(cls, context):
1331         # node = context.texture_node
1332         return False
1333         # return node and CyclesButtonsPanel.poll(context)
1334
1335     def draw(self, context):
1336         layout = self.layout
1337
1338         node = context.texture_node
1339
1340         mapping = node.color_mapping
1341
1342         split = layout.split()
1343
1344         col = split.column()
1345         col.label(text="Blend:")
1346         col.prop(mapping, "blend_type", text="")
1347         col.prop(mapping, "blend_factor", text="Factor")
1348         col.prop(mapping, "blend_color", text="")
1349
1350         col = split.column()
1351         col.label(text="Adjust:")
1352         col.prop(mapping, "brightness")
1353         col.prop(mapping, "contrast")
1354         col.prop(mapping, "saturation")
1355
1356         layout.separator()
1357
1358         layout.prop(mapping, "use_color_ramp", text="Ramp")
1359         if mapping.use_color_ramp:
1360             layout.template_color_ramp(mapping, "color_ramp", expand=True)
1361
1362
1363 class CyclesParticle_PT_textures(CyclesButtonsPanel, Panel):
1364     bl_label = "Textures"
1365     bl_context = "particle"
1366     bl_options = {'DEFAULT_CLOSED'}
1367
1368     @classmethod
1369     def poll(cls, context):
1370         psys = context.particle_system
1371         return psys and CyclesButtonsPanel.poll(context)
1372
1373     def draw(self, context):
1374         layout = self.layout
1375
1376         psys = context.particle_system
1377         part = psys.settings
1378
1379         row = layout.row()
1380         row.template_list("TEXTURE_UL_texslots", "", part, "texture_slots", part, "active_texture_index", rows=2)
1381
1382         col = row.column(align=True)
1383         col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
1384         col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
1385         col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
1386
1387         if not part.active_texture:
1388             layout.template_ID(part, "active_texture", new="texture.new")
1389         else:
1390             slot = part.texture_slots[part.active_texture_index]
1391             layout.template_ID(slot, "texture", new="texture.new")
1392
1393
1394 class CyclesRender_PT_CurveRendering(CyclesButtonsPanel, Panel):
1395     bl_label = "Cycles Hair Rendering"
1396     bl_context = "particle"
1397
1398     @classmethod
1399     def poll(cls, context):
1400         psys = context.particle_system
1401         return CyclesButtonsPanel.poll(context) and psys and psys.settings.type == 'HAIR'
1402
1403     def draw_header(self, context):
1404         ccscene = context.scene.cycles_curves
1405         self.layout.prop(ccscene, "use_curves", text="")
1406
1407     def draw(self, context):
1408         layout = self.layout
1409
1410         scene = context.scene
1411         ccscene = scene.cycles_curves
1412
1413         layout.active = ccscene.use_curves
1414
1415         layout.prop(ccscene, "primitive", text="Primitive")
1416         layout.prop(ccscene, "shape", text="Shape")
1417
1418         if not (ccscene.primitive in {'CURVE_SEGMENTS', 'LINE_SEGMENTS'} and ccscene.shape == 'RIBBONS'):
1419             layout.prop(ccscene, "cull_backfacing", text="Cull back-faces")
1420
1421         if ccscene.primitive == 'TRIANGLES' and ccscene.shape == 'THICK':
1422             layout.prop(ccscene, "resolution", text="Resolution")
1423         elif ccscene.primitive == 'CURVE_SEGMENTS':
1424             layout.prop(ccscene, "subdivisions", text="Curve subdivisions")
1425
1426         row = layout.row()
1427         row.prop(ccscene, "minimum_width", text="Min Pixels")
1428         row.prop(ccscene, "maximum_width", text="Max Ext.")
1429
1430
1431 class CyclesRender_PT_bake(CyclesButtonsPanel, Panel):
1432     bl_label = "Bake"
1433     bl_context = "render"
1434     bl_options = {'DEFAULT_CLOSED'}
1435     COMPAT_ENGINES = {'CYCLES'}
1436
1437     def draw(self, context):
1438         layout = self.layout
1439
1440         scene = context.scene
1441         cscene = scene.cycles
1442         cbk = scene.render.bake
1443
1444         layout.operator("object.bake", icon='RENDER_STILL').type = cscene.bake_type
1445
1446         col = layout.column()
1447         col.prop(cscene, "bake_type")
1448
1449         col = layout.column()
1450
1451         if cscene.bake_type == 'NORMAL':
1452             col.prop(cbk, "normal_space", text="Space")
1453
1454             row = col.row(align=True)
1455             row.label(text="Swizzle:")
1456             row.prop(cbk, "normal_r", text="")
1457             row.prop(cbk, "normal_g", text="")
1458             row.prop(cbk, "normal_b", text="")
1459
1460         elif cscene.bake_type == 'COMBINED':
1461             row = col.row(align=True)
1462             row.prop(cbk, "use_pass_direct", toggle=True)
1463             row.prop(cbk, "use_pass_indirect", toggle=True)
1464
1465             split = col.split()
1466             split.active = cbk.use_pass_direct or cbk.use_pass_indirect
1467
1468             col = split.column()
1469             col.prop(cbk, "use_pass_diffuse")
1470             col.prop(cbk, "use_pass_glossy")
1471             col.prop(cbk, "use_pass_transmission")
1472
1473             col = split.column()
1474             col.prop(cbk, "use_pass_subsurface")
1475             col.prop(cbk, "use_pass_ambient_occlusion")
1476             col.prop(cbk, "use_pass_emit")
1477
1478         elif cscene.bake_type in {'DIFFUSE', 'GLOSSY', 'TRANSMISSION', 'SUBSURFACE'}:
1479             row = col.row(align=True)
1480             row.prop(cbk, "use_pass_direct", toggle=True)
1481             row.prop(cbk, "use_pass_indirect", toggle=True)
1482             row.prop(cbk, "use_pass_color", toggle=True)
1483
1484         layout.separator()
1485
1486         split = layout.split()
1487
1488         col = split.column()
1489         col.prop(cbk, "margin")
1490         col.prop(cbk, "use_clear")
1491
1492         col = split.column()
1493         col.prop(cbk, "use_selected_to_active")
1494         sub = col.column()
1495         sub.active = cbk.use_selected_to_active
1496         sub.prop(cbk, "use_cage", text="Cage")
1497         if cbk.use_cage:
1498             sub.prop(cbk, "cage_extrusion", text="Extrusion")
1499             sub.prop_search(cbk, "cage_object", scene, "objects", text="")
1500         else:
1501             sub.prop(cbk, "cage_extrusion", text="Ray Distance")
1502
1503
1504 class CyclesRender_PT_debug(CyclesButtonsPanel, Panel):
1505     bl_label = "Debug"
1506     bl_context = "render"
1507     bl_options = {'DEFAULT_CLOSED'}
1508     COMPAT_ENGINES = {'CYCLES'}
1509
1510     @classmethod
1511     def poll(cls, context):
1512         return CyclesButtonsPanel.poll(context) and bpy.app.debug_value == 256
1513
1514     def draw(self, context):
1515         layout = self.layout
1516
1517         scene = context.scene
1518         cscene = scene.cycles
1519
1520         col = layout.column()
1521
1522         col.label('CPU Flags:')
1523         row = col.row(align=True)
1524         row.prop(cscene, "debug_use_cpu_sse2", toggle=True)
1525         row.prop(cscene, "debug_use_cpu_sse3", toggle=True)
1526         row.prop(cscene, "debug_use_cpu_sse41", toggle=True)
1527         row.prop(cscene, "debug_use_cpu_avx", toggle=True)
1528         row.prop(cscene, "debug_use_cpu_avx2", toggle=True)
1529         col.prop(cscene, "debug_use_qbvh")
1530
1531         col = layout.column()
1532         col.label('CUDA Flags:')
1533         col.prop(cscene, "debug_use_cuda_adaptive_compile")
1534
1535         col = layout.column()
1536         col.label('OpenCL Flags:')
1537         col.prop(cscene, "debug_opencl_kernel_type", text="Kernel")
1538         col.prop(cscene, "debug_opencl_device_type", text="Device")
1539         col.prop(cscene, "debug_use_opencl_debug", text="Debug")
1540
1541
1542 class CyclesParticle_PT_CurveSettings(CyclesButtonsPanel, Panel):
1543     bl_label = "Cycles Hair Settings"
1544     bl_context = "particle"
1545
1546     @classmethod
1547     def poll(cls, context):
1548         scene = context.scene
1549         ccscene = scene.cycles_curves
1550         psys = context.particle_system
1551         use_curves = ccscene.use_curves and psys
1552         return CyclesButtonsPanel.poll(context) and use_curves and psys.settings.type == 'HAIR'
1553
1554     def draw(self, context):
1555         layout = self.layout
1556
1557         psys = context.particle_settings
1558         cpsys = psys.cycles
1559
1560         row = layout.row()
1561         row.prop(cpsys, "shape", text="Shape")
1562
1563         layout.label(text="Thickness:")
1564         row = layout.row()
1565         row.prop(cpsys, "root_width", text="Root")
1566         row.prop(cpsys, "tip_width", text="Tip")
1567
1568         row = layout.row()
1569         row.prop(cpsys, "radius_scale", text="Scaling")
1570         row.prop(cpsys, "use_closetip", text="Close tip")
1571
1572
1573 class CyclesScene_PT_simplify(CyclesButtonsPanel, Panel):
1574     bl_label = "Simplify"
1575     bl_context = "scene"
1576     COMPAT_ENGINES = {'CYCLES'}
1577
1578     def draw_header(self, context):
1579         rd = context.scene.render
1580         self.layout.prop(rd, "use_simplify", text="")
1581
1582     def draw(self, context):
1583         layout = self.layout
1584
1585         scene = context.scene
1586         rd = scene.render
1587         cscene = scene.cycles
1588
1589         layout.active = rd.use_simplify
1590         split = layout.split()
1591
1592         col = split.column()
1593         col.label(text="Viewport:")
1594         col.prop(rd, "simplify_subdivision", text="Subdivision")
1595         col.prop(rd, "simplify_child_particles", text="Child Particles")
1596
1597         col = split.column()
1598         col.label(text="Render:")
1599         col.prop(rd, "simplify_subdivision_render", text="Subdivision")
1600         col.prop(rd, "simplify_child_particles_render", text="Child Particles")
1601
1602         layout.separator()
1603
1604         split = layout.split()
1605
1606         col = split.column()
1607         col.prop(cscene, "use_camera_cull")
1608         col.prop(cscene, "camera_cull_margin", text="Margin")
1609
1610         col = split.column()
1611         col.prop(cscene, "use_distance_cull")
1612         col.prop(cscene, "distance_cull_margin", text="Distance")
1613
1614 def draw_device(self, context):
1615     scene = context.scene
1616     layout = self.layout
1617
1618     if scene.render.engine == 'CYCLES':
1619         from . import engine
1620         cscene = scene.cycles
1621
1622         layout.prop(cscene, "feature_set")
1623
1624         split = layout.split(percentage=1/3)
1625         split.label("Device:")
1626         row = split.row(align=True)
1627         sub = row.split(align=True)
1628         sub.active = show_device_selection(context)
1629         sub.prop(cscene, "device", text="")
1630         row.operator("wm.addon_userpref_show", text="", icon='PREFERENCES').module = __package__
1631
1632         if engine.with_osl() and use_cpu(context):
1633             layout.prop(cscene, "shading_system")
1634
1635
1636 def draw_pause(self, context):
1637     layout = self.layout
1638     scene = context.scene
1639
1640     if scene.render.engine == "CYCLES":
1641         view = context.space_data
1642
1643         if view.viewport_shade == 'RENDERED':
1644             cscene = scene.cycles
1645             layername = scene.render.layers.active.name
1646             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1647             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1648
1649
1650 def get_panels():
1651     exclude_panels = {
1652         'DATA_PT_area',
1653         'DATA_PT_camera_dof',
1654         'DATA_PT_falloff_curve',
1655         'DATA_PT_lamp',
1656         'DATA_PT_preview',
1657         'DATA_PT_shadow',
1658         'DATA_PT_spot',
1659         'DATA_PT_sunsky',
1660         'MATERIAL_PT_context_material',
1661         'MATERIAL_PT_diffuse',
1662         'MATERIAL_PT_flare',
1663         'MATERIAL_PT_halo',
1664         'MATERIAL_PT_mirror',
1665         'MATERIAL_PT_options',
1666         'MATERIAL_PT_pipeline',
1667         'MATERIAL_PT_preview',
1668         'MATERIAL_PT_shading',
1669         'MATERIAL_PT_shadow',
1670         'MATERIAL_PT_specular',
1671         'MATERIAL_PT_sss',
1672         'MATERIAL_PT_strand',
1673         'MATERIAL_PT_transp',
1674         'MATERIAL_PT_volume_density',
1675         'MATERIAL_PT_volume_integration',
1676         'MATERIAL_PT_volume_lighting',
1677         'MATERIAL_PT_volume_options',
1678         'MATERIAL_PT_volume_shading',
1679         'MATERIAL_PT_volume_transp',
1680         'RENDERLAYER_PT_layer_options',
1681         'RENDERLAYER_PT_layer_passes',
1682         'RENDERLAYER_PT_views',
1683         'RENDER_PT_antialiasing',
1684         'RENDER_PT_bake',
1685         'RENDER_PT_motion_blur',
1686         'RENDER_PT_performance',
1687         'RENDER_PT_post_processing',
1688         'RENDER_PT_shading',
1689         'SCENE_PT_simplify',
1690         'TEXTURE_PT_context_texture',
1691         'WORLD_PT_ambient_occlusion',
1692         'WORLD_PT_environment_lighting',
1693         'WORLD_PT_gather',
1694         'WORLD_PT_indirect_lighting',
1695         'WORLD_PT_mist',
1696         'WORLD_PT_preview',
1697         'WORLD_PT_world'
1698         }
1699
1700     panels = []
1701     for panel in bpy.types.Panel.__subclasses__():
1702         if hasattr(panel, 'COMPAT_ENGINES') and 'BLENDER_RENDER' in panel.COMPAT_ENGINES:
1703             if panel.__name__ not in exclude_panels:
1704                 panels.append(panel)
1705
1706     return panels
1707
1708 def register():
1709     bpy.types.RENDER_PT_render.append(draw_device)
1710     bpy.types.VIEW3D_HT_header.append(draw_pause)
1711
1712     for panel in get_panels():
1713         panel.COMPAT_ENGINES.add('CYCLES')
1714
1715 def unregister():
1716     bpy.types.RENDER_PT_render.remove(draw_device)
1717     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1718
1719     for panel in get_panels():
1720         if 'CYCLES' in panel.COMPAT_ENGINES:
1721             panel.COMPAT_ENGINES.remove('CYCLES')