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