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