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