Fix build error on Windows 32bit, alignment was wrong.
[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(crl, "denoising_store_passes", text="Denoising Data")
521         col.separator()
522         col.prop(rl, "pass_alpha_threshold")
523
524         col = split.column()
525         col.label(text="Diffuse:")
526         row = col.row(align=True)
527         row.prop(rl, "use_pass_diffuse_direct", text="Direct", toggle=True)
528         row.prop(rl, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
529         row.prop(rl, "use_pass_diffuse_color", text="Color", toggle=True)
530         col.label(text="Glossy:")
531         row = col.row(align=True)
532         row.prop(rl, "use_pass_glossy_direct", text="Direct", toggle=True)
533         row.prop(rl, "use_pass_glossy_indirect", text="Indirect", toggle=True)
534         row.prop(rl, "use_pass_glossy_color", text="Color", toggle=True)
535         col.label(text="Transmission:")
536         row = col.row(align=True)
537         row.prop(rl, "use_pass_transmission_direct", text="Direct", toggle=True)
538         row.prop(rl, "use_pass_transmission_indirect", text="Indirect", toggle=True)
539         row.prop(rl, "use_pass_transmission_color", text="Color", toggle=True)
540         col.label(text="Subsurface:")
541         row = col.row(align=True)
542         row.prop(rl, "use_pass_subsurface_direct", text="Direct", toggle=True)
543         row.prop(rl, "use_pass_subsurface_indirect", text="Indirect", toggle=True)
544         row.prop(rl, "use_pass_subsurface_color", text="Color", toggle=True)
545         col.label(text="Volume:")
546         row = col.row(align=True)
547         row.prop(crl, "use_pass_volume_direct", text="Direct", toggle=True)
548         row.prop(crl, "use_pass_volume_indirect", text="Indirect", toggle=True)
549
550         col.separator()
551         col.prop(rl, "use_pass_emit", text="Emission")
552         col.prop(rl, "use_pass_environment")
553
554         col = layout.column()
555         col.prop(crl, "pass_debug_render_time")
556         if _cycles.with_cycles_debug:
557             col.prop(crl, "pass_debug_bvh_traversed_nodes")
558             col.prop(crl, "pass_debug_bvh_traversed_instances")
559             col.prop(crl, "pass_debug_bvh_intersections")
560             col.prop(crl, "pass_debug_ray_bounces")
561
562         crl = rl.cycles
563         layout.label("Cryptomatte:")
564         row = layout.row(align=True)
565         row.prop(crl, "use_pass_crypto_object", text="Object", toggle=True)
566         row.prop(crl, "use_pass_crypto_material", text="Material", toggle=True)
567         row.prop(crl, "use_pass_crypto_asset", text="Asset", toggle=True)
568         row = layout.row(align=True)
569         row.prop(crl, "pass_crypto_depth")
570         row = layout.row(align=True)
571         row.active = use_cpu(context)
572         row.prop(crl, "pass_crypto_accurate", text="Accurate Mode")
573
574 class CYCLES_RENDER_PT_views(CyclesButtonsPanel, Panel):
575     bl_label = "Views"
576     bl_context = "render_layer"
577     bl_options = {'DEFAULT_CLOSED'}
578
579     def draw_header(self, context):
580         rd = context.scene.render
581         self.layout.prop(rd, "use_multiview", text="")
582
583     def draw(self, context):
584         layout = self.layout
585
586         scene = context.scene
587         rd = scene.render
588         rv = rd.views.active
589
590         layout.active = rd.use_multiview
591         basic_stereo = (rd.views_format == 'STEREO_3D')
592
593         row = layout.row()
594         row.prop(rd, "views_format", expand=True)
595
596         if basic_stereo:
597             row = layout.row()
598             row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "stereo_views", rd.views, "active_index", rows=2)
599
600             row = layout.row()
601             row.label(text="File Suffix:")
602             row.prop(rv, "file_suffix", text="")
603
604         else:
605             row = layout.row()
606             row.template_list("RENDERLAYER_UL_renderviews", "name", rd, "views", rd.views, "active_index", rows=2)
607
608             col = row.column(align=True)
609             col.operator("scene.render_view_add", icon='ZOOMIN', text="")
610             col.operator("scene.render_view_remove", icon='ZOOMOUT', text="")
611
612             row = layout.row()
613             row.label(text="Camera Suffix:")
614             row.prop(rv, "camera_suffix", text="")
615
616
617 class CYCLES_RENDER_PT_denoising(CyclesButtonsPanel, Panel):
618     bl_label = "Denoising"
619     bl_context = "render_layer"
620     bl_options = {'DEFAULT_CLOSED'}
621
622     def draw_header(self, context):
623         rd = context.scene.render
624         rl = rd.layers.active
625         crl = rl.cycles
626         cscene = context.scene.cycles
627         layout = self.layout
628
629         layout.prop(crl, "use_denoising", text="")
630
631     def draw(self, context):
632         layout = self.layout
633
634         scene = context.scene
635         cscene = scene.cycles
636         rd = scene.render
637         rl = rd.layers.active
638         crl = rl.cycles
639
640         split = layout.split()
641         split.active = crl.use_denoising
642
643         col = split.column()
644         sub = col.column(align=True)
645         sub.prop(crl, "denoising_radius", text="Radius")
646         sub.prop(crl, "denoising_strength", slider=True, text="Strength")
647
648         col = split.column()
649         sub = col.column(align=True)
650         sub.prop(crl, "denoising_feature_strength", slider=True, text="Feature Strength")
651         sub.prop(crl, "denoising_relative_pca")
652
653         layout.separator()
654
655         row = layout.row()
656         row.active = crl.use_denoising or crl.denoising_store_passes
657         row.label(text="Diffuse:")
658         sub = row.row(align=True)
659         sub.prop(crl, "denoising_diffuse_direct", text="Direct", toggle=True)
660         sub.prop(crl, "denoising_diffuse_indirect", text="Indirect", toggle=True)
661
662         row = layout.row()
663         row.active = crl.use_denoising or crl.denoising_store_passes
664         row.label(text="Glossy:")
665         sub = row.row(align=True)
666         sub.prop(crl, "denoising_glossy_direct", text="Direct", toggle=True)
667         sub.prop(crl, "denoising_glossy_indirect", text="Indirect", toggle=True)
668
669         row = layout.row()
670         row.active = crl.use_denoising or crl.denoising_store_passes
671         row.label(text="Transmission:")
672         sub = row.row(align=True)
673         sub.prop(crl, "denoising_transmission_direct", text="Direct", toggle=True)
674         sub.prop(crl, "denoising_transmission_indirect", text="Indirect", toggle=True)
675
676         row = layout.row()
677         row.active = crl.use_denoising or crl.denoising_store_passes
678         row.label(text="Subsurface:")
679         sub = row.row(align=True)
680         sub.prop(crl, "denoising_subsurface_direct", text="Direct", toggle=True)
681         sub.prop(crl, "denoising_subsurface_indirect", text="Indirect", toggle=True)
682
683
684 class CYCLES_PT_post_processing(CyclesButtonsPanel, Panel):
685     bl_label = "Post Processing"
686     bl_options = {'DEFAULT_CLOSED'}
687
688     def draw(self, context):
689         layout = self.layout
690
691         rd = context.scene.render
692
693         split = layout.split()
694
695         col = split.column()
696         col.prop(rd, "use_compositing")
697         col.prop(rd, "use_sequencer")
698
699         col = split.column()
700         col.prop(rd, "dither_intensity", text="Dither", slider=True)
701
702
703 class CYCLES_CAMERA_PT_dof(CyclesButtonsPanel, Panel):
704     bl_label = "Depth of Field"
705     bl_context = "data"
706
707     @classmethod
708     def poll(cls, context):
709         return context.camera and CyclesButtonsPanel.poll(context)
710
711     def draw(self, context):
712         layout = self.layout
713
714         cam = context.camera
715         ccam = cam.cycles
716         dof_options = cam.gpu_dof
717
718         split = layout.split()
719
720         col = split.column()
721         col.label("Focus:")
722         col.prop(cam, "dof_object", text="")
723
724         sub = col.row()
725         sub.active = cam.dof_object is None
726         sub.prop(cam, "dof_distance", text="Distance")
727
728         hq_support = dof_options.is_hq_supported
729         sub = col.column(align=True)
730         sub.label("Viewport:")
731         subhq = sub.column()
732         subhq.active = hq_support
733         subhq.prop(dof_options, "use_high_quality")
734         sub.prop(dof_options, "fstop")
735         if dof_options.use_high_quality and hq_support:
736             sub.prop(dof_options, "blades")
737
738         col = split.column()
739
740         col.label("Aperture:")
741         sub = col.column(align=True)
742         sub.prop(ccam, "aperture_type", text="")
743         if ccam.aperture_type == 'RADIUS':
744             sub.prop(ccam, "aperture_size", text="Size")
745         elif ccam.aperture_type == 'FSTOP':
746             sub.prop(ccam, "aperture_fstop", text="Number")
747
748         sub = col.column(align=True)
749         sub.prop(ccam, "aperture_blades", text="Blades")
750         sub.prop(ccam, "aperture_rotation", text="Rotation")
751         sub.prop(ccam, "aperture_ratio", text="Ratio")
752
753
754 class CYCLES_PT_context_material(CyclesButtonsPanel, Panel):
755     bl_label = ""
756     bl_context = "material"
757     bl_options = {'HIDE_HEADER'}
758
759     @classmethod
760     def poll(cls, context):
761         return (context.material or context.object) and CyclesButtonsPanel.poll(context)
762
763     def draw(self, context):
764         layout = self.layout
765
766         mat = context.material
767         ob = context.object
768         slot = context.material_slot
769         space = context.space_data
770
771         if ob:
772             is_sortable = len(ob.material_slots) > 1
773             rows = 1
774             if (is_sortable):
775                 rows = 4
776
777             row = layout.row()
778
779             row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=rows)
780
781             col = row.column(align=True)
782             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
783             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
784
785             col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
786
787             if is_sortable:
788                 col.separator()
789
790                 col.operator("object.material_slot_move", icon='TRIA_UP', text="").direction = 'UP'
791                 col.operator("object.material_slot_move", icon='TRIA_DOWN', text="").direction = 'DOWN'
792
793             if ob.mode == 'EDIT':
794                 row = layout.row(align=True)
795                 row.operator("object.material_slot_assign", text="Assign")
796                 row.operator("object.material_slot_select", text="Select")
797                 row.operator("object.material_slot_deselect", text="Deselect")
798
799         split = layout.split(percentage=0.65)
800
801         if ob:
802             split.template_ID(ob, "active_material", new="material.new")
803             row = split.row()
804
805             if slot:
806                 row.prop(slot, "link", text="")
807             else:
808                 row.label()
809         elif mat:
810             split.template_ID(space, "pin_id")
811             split.separator()
812
813
814 class CYCLES_OBJECT_PT_motion_blur(CyclesButtonsPanel, Panel):
815     bl_label = "Motion Blur"
816     bl_context = "object"
817     bl_options = {'DEFAULT_CLOSED'}
818
819     @classmethod
820     def poll(cls, context):
821         ob = context.object
822         if CyclesButtonsPanel.poll(context) and ob:
823             if ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META', 'CAMERA'}:
824                 return True
825             if ob.dupli_type == 'GROUP' and ob.dupli_group:
826                 return True
827             # TODO(sergey): More duplicator types here?
828         return False
829
830     def draw_header(self, context):
831         layout = self.layout
832
833         rd = context.scene.render
834         # scene = context.scene
835
836         layout.active = rd.use_motion_blur
837
838         ob = context.object
839         cob = ob.cycles
840
841         layout.prop(cob, "use_motion_blur", text="")
842
843     def draw(self, context):
844         layout = self.layout
845
846         rd = context.scene.render
847         # scene = context.scene
848
849         ob = context.object
850         cob = ob.cycles
851
852         layout.active = (rd.use_motion_blur and cob.use_motion_blur)
853
854         row = layout.row()
855         if ob.type != 'CAMERA':
856             row.prop(cob, "use_deform_motion", text="Deformation")
857         row.prop(cob, "motion_steps", text="Steps")
858
859
860 class CYCLES_OBJECT_PT_cycles_settings(CyclesButtonsPanel, Panel):
861     bl_label = "Cycles Settings"
862     bl_context = "object"
863     bl_options = {'DEFAULT_CLOSED'}
864
865     @classmethod
866     def poll(cls, context):
867         ob = context.object
868         return (CyclesButtonsPanel.poll(context) and
869                 ob and ((ob.type in {'MESH', 'CURVE', 'SURFACE', 'FONT', 'META', 'LAMP'}) or
870                         (ob.dupli_type == 'GROUP' and ob.dupli_group)))
871
872     def draw(self, context):
873         layout = self.layout
874
875         scene = context.scene
876         cscene = scene.cycles
877         ob = context.object
878         cob = ob.cycles
879         visibility = ob.cycles_visibility
880
881         layout.label(text="Ray Visibility:")
882         flow = layout.column_flow()
883
884         flow.prop(visibility, "camera")
885         flow.prop(visibility, "diffuse")
886         flow.prop(visibility, "glossy")
887         flow.prop(visibility, "transmission")
888         flow.prop(visibility, "scatter")
889
890         if ob.type != 'LAMP':
891             flow.prop(visibility, "shadow")
892
893         row = layout.row()
894         row.prop(cob, "is_shadow_catcher")
895         row.prop(cob, "is_holdout")
896
897         col = layout.column()
898         col.label(text="Performance:")
899         row = col.row()
900         sub = row.row()
901         sub.active = scene.render.use_simplify and cscene.use_camera_cull
902         sub.prop(cob, "use_camera_cull")
903
904         sub = row.row()
905         sub.active = scene.render.use_simplify and cscene.use_distance_cull
906         sub.prop(cob, "use_distance_cull")
907
908
909 class CYCLES_OT_use_shading_nodes(Operator):
910     """Enable nodes on a material, world or lamp"""
911     bl_idname = "cycles.use_shading_nodes"
912     bl_label = "Use Nodes"
913
914     @classmethod
915     def poll(cls, context):
916         return (getattr(context, "material", False) or getattr(context, "world", False) or
917                 getattr(context, "lamp", False))
918
919     def execute(self, context):
920         if context.material:
921             context.material.use_nodes = True
922         elif context.world:
923             context.world.use_nodes = True
924         elif context.lamp:
925             context.lamp.use_nodes = True
926
927         return {'FINISHED'}
928
929
930 def find_node(material, nodetype):
931     if material and material.node_tree:
932         ntree = material.node_tree
933
934         active_output_node = None
935         for node in ntree.nodes:
936             if getattr(node, "type", None) == nodetype:
937                 if getattr(node, "is_active_output", True):
938                     return node
939                 if not active_output_node:
940                     active_output_node = node
941         return active_output_node
942
943     return None
944
945
946 def find_node_input(node, name):
947     for input in node.inputs:
948         if input.name == name:
949             return input
950
951     return None
952
953
954 def panel_node_draw(layout, id_data, output_type, input_name):
955     if not id_data.use_nodes:
956         layout.operator("cycles.use_shading_nodes", icon='NODETREE')
957         return False
958
959     ntree = id_data.node_tree
960
961     node = find_node(id_data, output_type)
962     if not node:
963         layout.label(text="No output node")
964     else:
965         input = find_node_input(node, input_name)
966         layout.template_node_view(ntree, node, input)
967
968     return True
969
970
971 class CYCLES_LAMP_PT_preview(CyclesButtonsPanel, Panel):
972     bl_label = "Preview"
973     bl_context = "data"
974     bl_options = {'DEFAULT_CLOSED'}
975
976     @classmethod
977     def poll(cls, context):
978         return context.lamp and \
979             not (context.lamp.type == 'AREA' and
980                  context.lamp.cycles.is_portal) \
981             and CyclesButtonsPanel.poll(context)
982
983     def draw(self, context):
984         self.layout.template_preview(context.lamp)
985
986
987 class CYCLES_LAMP_PT_lamp(CyclesButtonsPanel, Panel):
988     bl_label = "Lamp"
989     bl_context = "data"
990
991     @classmethod
992     def poll(cls, context):
993         return context.lamp and CyclesButtonsPanel.poll(context)
994
995     def draw(self, context):
996         layout = self.layout
997
998         lamp = context.lamp
999         clamp = lamp.cycles
1000         # cscene = context.scene.cycles
1001
1002         layout.prop(lamp, "type", expand=True)
1003
1004         split = layout.split()
1005         col = split.column(align=True)
1006
1007         if lamp.type in {'POINT', 'SUN', 'SPOT'}:
1008             col.prop(lamp, "shadow_soft_size", text="Size")
1009         elif lamp.type == 'AREA':
1010             col.prop(lamp, "shape", text="")
1011             sub = col.column(align=True)
1012
1013             if lamp.shape == 'SQUARE':
1014                 sub.prop(lamp, "size")
1015             elif lamp.shape == 'RECTANGLE':
1016                 sub.prop(lamp, "size", text="Size X")
1017                 sub.prop(lamp, "size_y", text="Size Y")
1018
1019         if not (lamp.type == 'AREA' and clamp.is_portal):
1020             sub = col.column(align=True)
1021             if use_branched_path(context):
1022                 subsub = sub.row(align=True)
1023                 subsub.active = use_sample_all_lights(context)
1024                 subsub.prop(clamp, "samples")
1025             sub.prop(clamp, "max_bounces")
1026
1027         col = split.column()
1028
1029         sub = col.column(align=True)
1030         sub.active = not (lamp.type == 'AREA' and clamp.is_portal)
1031         sub.prop(clamp, "cast_shadow")
1032         sub.prop(clamp, "use_multiple_importance_sampling", text="Multiple Importance")
1033
1034         if lamp.type == 'AREA':
1035             col.prop(clamp, "is_portal", text="Portal")
1036
1037         if lamp.type == 'HEMI':
1038             layout.label(text="Not supported, interpreted as sun lamp")
1039
1040
1041 class CYCLES_LAMP_PT_nodes(CyclesButtonsPanel, Panel):
1042     bl_label = "Nodes"
1043     bl_context = "data"
1044
1045     @classmethod
1046     def poll(cls, context):
1047         return context.lamp and not (context.lamp.type == 'AREA' and
1048                                      context.lamp.cycles.is_portal) and \
1049             CyclesButtonsPanel.poll(context)
1050
1051     def draw(self, context):
1052         layout = self.layout
1053
1054         lamp = context.lamp
1055         if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
1056             layout.prop(lamp, "color")
1057
1058
1059 class CYCLES_LAMP_PT_spot(CyclesButtonsPanel, Panel):
1060     bl_label = "Spot Shape"
1061     bl_context = "data"
1062
1063     @classmethod
1064     def poll(cls, context):
1065         lamp = context.lamp
1066         return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context)
1067
1068     def draw(self, context):
1069         layout = self.layout
1070
1071         lamp = context.lamp
1072
1073         split = layout.split()
1074
1075         col = split.column()
1076         sub = col.column()
1077         sub.prop(lamp, "spot_size", text="Size")
1078         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
1079
1080         col = split.column()
1081         col.prop(lamp, "show_cone")
1082
1083
1084 class CYCLES_WORLD_PT_preview(CyclesButtonsPanel, Panel):
1085     bl_label = "Preview"
1086     bl_context = "world"
1087     bl_options = {'DEFAULT_CLOSED'}
1088
1089     @classmethod
1090     def poll(cls, context):
1091         return context.world and CyclesButtonsPanel.poll(context)
1092
1093     def draw(self, context):
1094         self.layout.template_preview(context.world)
1095
1096
1097 class CYCLES_WORLD_PT_surface(CyclesButtonsPanel, Panel):
1098     bl_label = "Surface"
1099     bl_context = "world"
1100
1101     @classmethod
1102     def poll(cls, context):
1103         return context.world and CyclesButtonsPanel.poll(context)
1104
1105     def draw(self, context):
1106         layout = self.layout
1107
1108         world = context.world
1109
1110         if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
1111             layout.prop(world, "horizon_color", text="Color")
1112
1113
1114 class CYCLES_WORLD_PT_volume(CyclesButtonsPanel, Panel):
1115     bl_label = "Volume"
1116     bl_context = "world"
1117     bl_options = {'DEFAULT_CLOSED'}
1118
1119     @classmethod
1120     def poll(cls, context):
1121         world = context.world
1122         return world and world.node_tree and CyclesButtonsPanel.poll(context)
1123
1124     def draw(self, context):
1125         layout = self.layout
1126
1127         world = context.world
1128         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
1129
1130
1131 class CYCLES_WORLD_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
1132     bl_label = "Ambient Occlusion"
1133     bl_context = "world"
1134
1135     @classmethod
1136     def poll(cls, context):
1137         return context.world and CyclesButtonsPanel.poll(context)
1138
1139     def draw_header(self, context):
1140         light = context.world.light_settings
1141         self.layout.prop(light, "use_ambient_occlusion", text="")
1142
1143     def draw(self, context):
1144         layout = self.layout
1145
1146         light = context.world.light_settings
1147         scene = context.scene
1148
1149         row = layout.row()
1150         sub = row.row()
1151         sub.active = light.use_ambient_occlusion or scene.render.use_simplify
1152         sub.prop(light, "ao_factor", text="Factor")
1153         row.prop(light, "distance", text="Distance")
1154
1155
1156 class CYCLES_WORLD_PT_mist(CyclesButtonsPanel, Panel):
1157     bl_label = "Mist Pass"
1158     bl_context = "world"
1159     bl_options = {'DEFAULT_CLOSED'}
1160
1161     @classmethod
1162     def poll(cls, context):
1163         if CyclesButtonsPanel.poll(context):
1164             if context.world:
1165                 for rl in context.scene.render.layers:
1166                     if rl.use_pass_mist:
1167                         return True
1168
1169         return False
1170
1171     def draw(self, context):
1172         layout = self.layout
1173
1174         world = context.world
1175
1176         split = layout.split(align=True)
1177         split.prop(world.mist_settings, "start")
1178         split.prop(world.mist_settings, "depth")
1179
1180         layout.prop(world.mist_settings, "falloff")
1181
1182
1183 class CYCLES_WORLD_PT_ray_visibility(CyclesButtonsPanel, Panel):
1184     bl_label = "Ray Visibility"
1185     bl_context = "world"
1186     bl_options = {'DEFAULT_CLOSED'}
1187
1188     @classmethod
1189     def poll(cls, context):
1190         return CyclesButtonsPanel.poll(context) and context.world
1191
1192     def draw(self, context):
1193         layout = self.layout
1194
1195         world = context.world
1196         visibility = world.cycles_visibility
1197
1198         flow = layout.column_flow()
1199
1200         flow.prop(visibility, "camera")
1201         flow.prop(visibility, "diffuse")
1202         flow.prop(visibility, "glossy")
1203         flow.prop(visibility, "transmission")
1204         flow.prop(visibility, "scatter")
1205
1206
1207 class CYCLES_WORLD_PT_settings(CyclesButtonsPanel, Panel):
1208     bl_label = "Settings"
1209     bl_context = "world"
1210     bl_options = {'DEFAULT_CLOSED'}
1211
1212     @classmethod
1213     def poll(cls, context):
1214         return context.world and CyclesButtonsPanel.poll(context)
1215
1216     def draw(self, context):
1217         layout = self.layout
1218
1219         world = context.world
1220         cworld = world.cycles
1221         # cscene = context.scene.cycles
1222
1223         split = layout.split()
1224
1225         col = split.column()
1226
1227         col.label(text="Surface:")
1228         col.prop(cworld, "sampling_method", text="Sampling")
1229
1230         sub = col.column(align=True)
1231         sub.active = cworld.sampling_method != 'NONE'
1232         subsub = sub.row(align=True)
1233         subsub.active = cworld.sampling_method == 'MANUAL'
1234         subsub.prop(cworld, "sample_map_resolution")
1235         if use_branched_path(context):
1236             subsub = sub.row(align=True)
1237             subsub.active = use_sample_all_lights(context)
1238             subsub.prop(cworld, "samples")
1239         sub.prop(cworld, "max_bounces")
1240
1241         col = split.column()
1242         col.label(text="Volume:")
1243         sub = col.column()
1244         sub.active = use_cpu(context)
1245         sub.prop(cworld, "volume_sampling", text="")
1246         col.prop(cworld, "volume_interpolation", text="")
1247         col.prop(cworld, "homogeneous_volume", text="Homogeneous")
1248
1249
1250 class CYCLES_MATERIAL_PT_preview(CyclesButtonsPanel, Panel):
1251     bl_label = "Preview"
1252     bl_context = "material"
1253     bl_options = {'DEFAULT_CLOSED'}
1254
1255     @classmethod
1256     def poll(cls, context):
1257         return context.material and CyclesButtonsPanel.poll(context)
1258
1259     def draw(self, context):
1260         self.layout.template_preview(context.material)
1261
1262
1263 class CYCLES_MATERIAL_PT_surface(CyclesButtonsPanel, Panel):
1264     bl_label = "Surface"
1265     bl_context = "material"
1266
1267     @classmethod
1268     def poll(cls, context):
1269         return context.material and CyclesButtonsPanel.poll(context)
1270
1271     def draw(self, context):
1272         layout = self.layout
1273
1274         mat = context.material
1275         if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
1276             layout.prop(mat, "diffuse_color")
1277
1278
1279 class CYCLES_MATERIAL_PT_volume(CyclesButtonsPanel, Panel):
1280     bl_label = "Volume"
1281     bl_context = "material"
1282     bl_options = {'DEFAULT_CLOSED'}
1283
1284     @classmethod
1285     def poll(cls, context):
1286         mat = context.material
1287         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
1288
1289     def draw(self, context):
1290         layout = self.layout
1291
1292         mat = context.material
1293         # cmat = mat.cycles
1294
1295         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
1296
1297
1298 class CYCLES_MATERIAL_PT_displacement(CyclesButtonsPanel, Panel):
1299     bl_label = "Displacement"
1300     bl_context = "material"
1301
1302     @classmethod
1303     def poll(cls, context):
1304         mat = context.material
1305         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
1306
1307     def draw(self, context):
1308         layout = self.layout
1309
1310         mat = context.material
1311         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
1312
1313
1314 class CYCLES_MATERIAL_PT_settings(CyclesButtonsPanel, Panel):
1315     bl_label = "Settings"
1316     bl_context = "material"
1317
1318     @classmethod
1319     def poll(cls, context):
1320         return context.material and CyclesButtonsPanel.poll(context)
1321
1322     def draw(self, context):
1323         layout = self.layout
1324
1325         mat = context.material
1326         cmat = mat.cycles
1327
1328         split = layout.split()
1329         col = split.column()
1330         col.label(text="Surface:")
1331         col.prop(cmat, "sample_as_light", text="Multiple Importance")
1332         col.prop(cmat, "use_transparent_shadow")
1333
1334         col.separator()
1335         col.label(text="Geometry:")
1336         col.prop(cmat, "displacement_method", text="")
1337
1338         col = split.column()
1339         col.label(text="Volume:")
1340         sub = col.column()
1341         sub.active = use_cpu(context)
1342         sub.prop(cmat, "volume_sampling", text="")
1343         col.prop(cmat, "volume_interpolation", text="")
1344         col.prop(cmat, "homogeneous_volume", text="Homogeneous")
1345
1346         col.separator()
1347         col.prop(mat, "pass_index")
1348
1349
1350 class CYCLES_MATERIAL_PT_viewport(CyclesButtonsPanel, Panel):
1351     bl_label = "Viewport"
1352     bl_context = "material"
1353     bl_options = {'DEFAULT_CLOSED'}
1354
1355     @classmethod
1356     def poll(cls, context):
1357         return context.material and CyclesButtonsPanel.poll(context)
1358
1359     def draw(self, context):
1360         mat = context.material
1361
1362         layout = self.layout
1363         split = layout.split()
1364
1365         col = split.column(align=True)
1366         col.label("Color:")
1367         col.prop(mat, "diffuse_color", text="")
1368         col.prop(mat, "alpha")
1369
1370         col.separator()
1371         col.label("Alpha:")
1372         col.prop(mat.game_settings, "alpha_blend", text="")
1373
1374         col = split.column(align=True)
1375         col.label("Specular:")
1376         col.prop(mat, "specular_color", text="")
1377         col.prop(mat, "specular_hardness", text="Hardness")
1378
1379
1380 class CYCLES_TEXTURE_PT_context(CyclesButtonsPanel, Panel):
1381     bl_label = ""
1382     bl_context = "texture"
1383     bl_options = {'HIDE_HEADER'}
1384     COMPAT_ENGINES = {'CYCLES'}
1385
1386     def draw(self, context):
1387         layout = self.layout
1388
1389         tex = context.texture
1390         space = context.space_data
1391         pin_id = space.pin_id
1392         use_pin_id = space.use_pin_id
1393         user = context.texture_user
1394
1395         space.use_limited_texture_context = False
1396
1397         if not (use_pin_id and isinstance(pin_id, bpy.types.Texture)):
1398             pin_id = None
1399
1400         if not pin_id:
1401             layout.template_texture_user()
1402
1403         if user or pin_id:
1404             layout.separator()
1405
1406             split = layout.split(percentage=0.65)
1407             col = split.column()
1408
1409             if pin_id:
1410                 col.template_ID(space, "pin_id")
1411             else:
1412                 propname = context.texture_user_property.identifier
1413                 col.template_ID(user, propname, new="texture.new")
1414
1415             if tex:
1416                 split = layout.split(percentage=0.2)
1417                 split.label(text="Type:")
1418                 split.prop(tex, "type", text="")
1419
1420
1421 class CYCLES_TEXTURE_PT_node(CyclesButtonsPanel, Panel):
1422     bl_label = "Node"
1423     bl_context = "texture"
1424
1425     @classmethod
1426     def poll(cls, context):
1427         node = context.texture_node
1428         return node and CyclesButtonsPanel.poll(context)
1429
1430     def draw(self, context):
1431         layout = self.layout
1432
1433         node = context.texture_node
1434         ntree = node.id_data
1435         layout.template_node_view(ntree, node, None)
1436
1437
1438 class CYCLES_TEXTURE_PT_mapping(CyclesButtonsPanel, Panel):
1439     bl_label = "Mapping"
1440     bl_context = "texture"
1441
1442     @classmethod
1443     def poll(cls, context):
1444         node = context.texture_node
1445         # TODO(sergey): perform a faster/nicer check?
1446         return node and hasattr(node, 'texture_mapping') and CyclesButtonsPanel.poll(context)
1447
1448     def draw(self, context):
1449         layout = self.layout
1450
1451         node = context.texture_node
1452
1453         mapping = node.texture_mapping
1454
1455         layout.prop(mapping, "vector_type", expand=True)
1456
1457         row = layout.row()
1458
1459         row.column().prop(mapping, "translation")
1460         row.column().prop(mapping, "rotation")
1461         row.column().prop(mapping, "scale")
1462
1463         layout.label(text="Projection:")
1464
1465         row = layout.row()
1466         row.prop(mapping, "mapping_x", text="")
1467         row.prop(mapping, "mapping_y", text="")
1468         row.prop(mapping, "mapping_z", text="")
1469
1470
1471 class CYCLES_TEXTURE_PT_colors(CyclesButtonsPanel, Panel):
1472     bl_label = "Color"
1473     bl_context = "texture"
1474     bl_options = {'DEFAULT_CLOSED'}
1475
1476     @classmethod
1477     def poll(cls, context):
1478         # node = context.texture_node
1479         return False
1480         # return node and CyclesButtonsPanel.poll(context)
1481
1482     def draw(self, context):
1483         layout = self.layout
1484
1485         node = context.texture_node
1486
1487         mapping = node.color_mapping
1488
1489         split = layout.split()
1490
1491         col = split.column()
1492         col.label(text="Blend:")
1493         col.prop(mapping, "blend_type", text="")
1494         col.prop(mapping, "blend_factor", text="Factor")
1495         col.prop(mapping, "blend_color", text="")
1496
1497         col = split.column()
1498         col.label(text="Adjust:")
1499         col.prop(mapping, "brightness")
1500         col.prop(mapping, "contrast")
1501         col.prop(mapping, "saturation")
1502
1503         layout.separator()
1504
1505         layout.prop(mapping, "use_color_ramp", text="Ramp")
1506         if mapping.use_color_ramp:
1507             layout.template_color_ramp(mapping, "color_ramp", expand=True)
1508
1509
1510 class CYCLES_PARTICLE_PT_textures(CyclesButtonsPanel, Panel):
1511     bl_label = "Textures"
1512     bl_context = "particle"
1513     bl_options = {'DEFAULT_CLOSED'}
1514
1515     @classmethod
1516     def poll(cls, context):
1517         psys = context.particle_system
1518         return psys and CyclesButtonsPanel.poll(context)
1519
1520     def draw(self, context):
1521         layout = self.layout
1522
1523         psys = context.particle_system
1524         part = psys.settings
1525
1526         row = layout.row()
1527         row.template_list("TEXTURE_UL_texslots", "", part, "texture_slots", part, "active_texture_index", rows=2)
1528
1529         col = row.column(align=True)
1530         col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
1531         col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
1532         col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
1533
1534         if not part.active_texture:
1535             layout.template_ID(part, "active_texture", new="texture.new")
1536         else:
1537             slot = part.texture_slots[part.active_texture_index]
1538             layout.template_ID(slot, "texture", new="texture.new")
1539
1540
1541 class CYCLES_RENDER_PT_bake(CyclesButtonsPanel, Panel):
1542     bl_label = "Bake"
1543     bl_context = "render"
1544     bl_options = {'DEFAULT_CLOSED'}
1545     COMPAT_ENGINES = {'CYCLES'}
1546
1547     def draw(self, context):
1548         layout = self.layout
1549
1550         scene = context.scene
1551         cscene = scene.cycles
1552         cbk = scene.render.bake
1553
1554         layout.operator("object.bake", icon='RENDER_STILL').type = cscene.bake_type
1555
1556         col = layout.column()
1557         col.prop(cscene, "bake_type")
1558
1559         col = layout.column()
1560
1561         if cscene.bake_type == 'NORMAL':
1562             col.prop(cbk, "normal_space", text="Space")
1563
1564             row = col.row(align=True)
1565             row.label(text="Swizzle:")
1566             row.prop(cbk, "normal_r", text="")
1567             row.prop(cbk, "normal_g", text="")
1568             row.prop(cbk, "normal_b", text="")
1569
1570         elif cscene.bake_type == 'COMBINED':
1571             row = col.row(align=True)
1572             row.prop(cbk, "use_pass_direct", toggle=True)
1573             row.prop(cbk, "use_pass_indirect", toggle=True)
1574
1575             split = col.split()
1576             split.active = cbk.use_pass_direct or cbk.use_pass_indirect
1577
1578             col = split.column()
1579             col.prop(cbk, "use_pass_diffuse")
1580             col.prop(cbk, "use_pass_glossy")
1581             col.prop(cbk, "use_pass_transmission")
1582
1583             col = split.column()
1584             col.prop(cbk, "use_pass_subsurface")
1585             col.prop(cbk, "use_pass_ambient_occlusion")
1586             col.prop(cbk, "use_pass_emit")
1587
1588         elif cscene.bake_type in {'DIFFUSE', 'GLOSSY', 'TRANSMISSION', 'SUBSURFACE'}:
1589             row = col.row(align=True)
1590             row.prop(cbk, "use_pass_direct", toggle=True)
1591             row.prop(cbk, "use_pass_indirect", toggle=True)
1592             row.prop(cbk, "use_pass_color", toggle=True)
1593
1594         layout.separator()
1595
1596         split = layout.split()
1597
1598         col = split.column()
1599         col.prop(cbk, "margin")
1600         col.prop(cbk, "use_clear")
1601
1602         col = split.column()
1603         col.prop(cbk, "use_selected_to_active")
1604         sub = col.column()
1605         sub.active = cbk.use_selected_to_active
1606         sub.prop(cbk, "use_cage", text="Cage")
1607         if cbk.use_cage:
1608             sub.prop(cbk, "cage_extrusion", text="Extrusion")
1609             sub.prop_search(cbk, "cage_object", scene, "objects", text="")
1610         else:
1611             sub.prop(cbk, "cage_extrusion", text="Ray Distance")
1612
1613
1614 class CYCLES_RENDER_PT_debug(CyclesButtonsPanel, Panel):
1615     bl_label = "Debug"
1616     bl_context = "render"
1617     bl_options = {'DEFAULT_CLOSED'}
1618     COMPAT_ENGINES = {'CYCLES'}
1619
1620     @classmethod
1621     def poll(cls, context):
1622         return CyclesButtonsPanel.poll(context) and bpy.app.debug_value == 256
1623
1624     def draw(self, context):
1625         layout = self.layout
1626
1627         scene = context.scene
1628         cscene = scene.cycles
1629
1630         col = layout.column()
1631
1632         col.label('CPU Flags:')
1633         row = col.row(align=True)
1634         row.prop(cscene, "debug_use_cpu_sse2", toggle=True)
1635         row.prop(cscene, "debug_use_cpu_sse3", toggle=True)
1636         row.prop(cscene, "debug_use_cpu_sse41", toggle=True)
1637         row.prop(cscene, "debug_use_cpu_avx", toggle=True)
1638         row.prop(cscene, "debug_use_cpu_avx2", toggle=True)
1639         col.prop(cscene, "debug_bvh_layout")
1640         col.prop(cscene, "debug_use_cpu_split_kernel")
1641
1642         col.separator()
1643
1644         col = layout.column()
1645         col.label('CUDA Flags:')
1646         col.prop(cscene, "debug_use_cuda_adaptive_compile")
1647         col.prop(cscene, "debug_use_cuda_split_kernel")
1648
1649         col.separator()
1650
1651         col = layout.column()
1652         col.label('OpenCL Flags:')
1653         col.prop(cscene, "debug_opencl_kernel_type", text="Kernel")
1654         col.prop(cscene, "debug_opencl_device_type", text="Device")
1655         col.prop(cscene, "debug_opencl_kernel_single_program", text="Single Program")
1656         col.prop(cscene, "debug_use_opencl_debug", text="Debug")
1657         col.prop(cscene, "debug_opencl_mem_limit")
1658
1659         col.separator()
1660
1661         col = layout.column()
1662         col.prop(cscene, "debug_bvh_type")
1663
1664
1665 class CYCLES_PARTICLE_PT_curve_settings(CyclesButtonsPanel, Panel):
1666     bl_label = "Cycles Hair Settings"
1667     bl_context = "particle"
1668
1669     @classmethod
1670     def poll(cls, context):
1671         scene = context.scene
1672         ccscene = scene.cycles_curves
1673         psys = context.particle_system
1674         use_curves = ccscene.use_curves and psys
1675         return CyclesButtonsPanel.poll(context) and use_curves and psys.settings.type == 'HAIR'
1676
1677     def draw(self, context):
1678         layout = self.layout
1679
1680         psys = context.particle_settings
1681         cpsys = psys.cycles
1682
1683         row = layout.row()
1684         row.prop(cpsys, "shape", text="Shape")
1685
1686         layout.label(text="Thickness:")
1687         row = layout.row()
1688         row.prop(cpsys, "root_width", text="Root")
1689         row.prop(cpsys, "tip_width", text="Tip")
1690
1691         row = layout.row()
1692         row.prop(cpsys, "radius_scale", text="Scaling")
1693         row.prop(cpsys, "use_closetip", text="Close tip")
1694
1695
1696 class CYCLES_SCENE_PT_simplify(CyclesButtonsPanel, Panel):
1697     bl_label = "Simplify"
1698     bl_context = "scene"
1699     COMPAT_ENGINES = {'CYCLES'}
1700
1701     def draw_header(self, context):
1702         rd = context.scene.render
1703         self.layout.prop(rd, "use_simplify", text="")
1704
1705     def draw(self, context):
1706         layout = self.layout
1707
1708         scene = context.scene
1709         rd = scene.render
1710         cscene = scene.cycles
1711
1712         layout.active = rd.use_simplify
1713
1714         col = layout.column(align=True)
1715         col.label(text="Subdivision")
1716         row = col.row(align=True)
1717         row.prop(rd, "simplify_subdivision", text="Viewport")
1718         row.prop(rd, "simplify_subdivision_render", text="Render")
1719
1720         col = layout.column(align=True)
1721         col.label(text="Child Particles")
1722         row = col.row(align=True)
1723         row.prop(rd, "simplify_child_particles", text="Viewport")
1724         row.prop(rd, "simplify_child_particles_render", text="Render")
1725
1726         col = layout.column(align=True)
1727         split = col.split()
1728         sub = split.column()
1729         sub.label(text="Texture Limit Viewport")
1730         sub.prop(cscene, "texture_limit", text="")
1731         sub = split.column()
1732         sub.label(text="Texture Limit Render")
1733         sub.prop(cscene, "texture_limit_render", text="")
1734
1735         split = layout.split()
1736         col = split.column()
1737         col.prop(cscene, "use_camera_cull")
1738         row = col.row()
1739         row.active = cscene.use_camera_cull
1740         row.prop(cscene, "camera_cull_margin")
1741
1742         col = split.column()
1743         col.prop(cscene, "use_distance_cull")
1744         row = col.row()
1745         row.active = cscene.use_distance_cull
1746         row.prop(cscene, "distance_cull_margin", text="Distance")
1747
1748         split = layout.split()
1749         col = split.column()
1750         col.prop(cscene, "ao_bounces")
1751
1752         col = split.column()
1753         col.prop(cscene, "ao_bounces_render")
1754
1755
1756 def draw_device(self, context):
1757     scene = context.scene
1758     layout = self.layout
1759
1760     if scene.render.engine == 'CYCLES':
1761         from . import engine
1762         cscene = scene.cycles
1763
1764         layout.prop(cscene, "feature_set")
1765
1766         split = layout.split(percentage=1 / 3)
1767         split.label("Device:")
1768         row = split.row()
1769         row.active = show_device_active(context)
1770         row.prop(cscene, "device", text="")
1771
1772         if engine.with_osl() and use_cpu(context):
1773             layout.prop(cscene, "shading_system")
1774
1775
1776 def draw_pause(self, context):
1777     layout = self.layout
1778     scene = context.scene
1779
1780     if scene.render.engine == "CYCLES":
1781         view = context.space_data
1782
1783         if view.viewport_shade == 'RENDERED':
1784             cscene = scene.cycles
1785             layername = scene.render.layers.active.name
1786             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1787             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1788
1789
1790 def get_panels():
1791     exclude_panels = {
1792         'DATA_PT_area',
1793         'DATA_PT_camera_dof',
1794         'DATA_PT_falloff_curve',
1795         'DATA_PT_lamp',
1796         'DATA_PT_preview',
1797         'DATA_PT_shadow',
1798         'DATA_PT_spot',
1799         'DATA_PT_sunsky',
1800         'MATERIAL_PT_context_material',
1801         'MATERIAL_PT_diffuse',
1802         'MATERIAL_PT_flare',
1803         'MATERIAL_PT_halo',
1804         'MATERIAL_PT_mirror',
1805         'MATERIAL_PT_options',
1806         'MATERIAL_PT_pipeline',
1807         'MATERIAL_PT_preview',
1808         'MATERIAL_PT_shading',
1809         'MATERIAL_PT_shadow',
1810         'MATERIAL_PT_specular',
1811         'MATERIAL_PT_sss',
1812         'MATERIAL_PT_strand',
1813         'MATERIAL_PT_transp',
1814         'MATERIAL_PT_volume_density',
1815         'MATERIAL_PT_volume_integration',
1816         'MATERIAL_PT_volume_lighting',
1817         'MATERIAL_PT_volume_options',
1818         'MATERIAL_PT_volume_shading',
1819         'MATERIAL_PT_volume_transp',
1820         'RENDERLAYER_PT_layer_options',
1821         'RENDERLAYER_PT_layer_passes',
1822         'RENDERLAYER_PT_views',
1823         'RENDER_PT_antialiasing',
1824         'RENDER_PT_bake',
1825         'RENDER_PT_motion_blur',
1826         'RENDER_PT_performance',
1827         'RENDER_PT_post_processing',
1828         'RENDER_PT_shading',
1829         'SCENE_PT_simplify',
1830         'TEXTURE_PT_context_texture',
1831         'WORLD_PT_ambient_occlusion',
1832         'WORLD_PT_environment_lighting',
1833         'WORLD_PT_gather',
1834         'WORLD_PT_indirect_lighting',
1835         'WORLD_PT_mist',
1836         'WORLD_PT_preview',
1837         'WORLD_PT_world'
1838     }
1839
1840     panels = []
1841     for panel in bpy.types.Panel.__subclasses__():
1842         if hasattr(panel, 'COMPAT_ENGINES') and 'BLENDER_RENDER' in panel.COMPAT_ENGINES:
1843             if panel.__name__ not in exclude_panels:
1844                 panels.append(panel)
1845
1846     return panels
1847
1848
1849 classes = (
1850     CYCLES_MT_sampling_presets,
1851     CYCLES_MT_integrator_presets,
1852     CYCLES_RENDER_PT_sampling,
1853     CYCLES_RENDER_PT_geometry,
1854     CYCLES_RENDER_PT_light_paths,
1855     CYCLES_RENDER_PT_motion_blur,
1856     CYCLES_RENDER_PT_film,
1857     CYCLES_RENDER_PT_performance,
1858     CYCLES_RENDER_PT_layer_options,
1859     CYCLES_RENDER_PT_layer_passes,
1860     CYCLES_RENDER_PT_views,
1861     CYCLES_RENDER_PT_denoising,
1862     CYCLES_PT_post_processing,
1863     CYCLES_CAMERA_PT_dof,
1864     CYCLES_PT_context_material,
1865     CYCLES_OBJECT_PT_motion_blur,
1866     CYCLES_OBJECT_PT_cycles_settings,
1867     CYCLES_OT_use_shading_nodes,
1868     CYCLES_LAMP_PT_preview,
1869     CYCLES_LAMP_PT_lamp,
1870     CYCLES_LAMP_PT_nodes,
1871     CYCLES_LAMP_PT_spot,
1872     CYCLES_WORLD_PT_preview,
1873     CYCLES_WORLD_PT_surface,
1874     CYCLES_WORLD_PT_volume,
1875     CYCLES_WORLD_PT_ambient_occlusion,
1876     CYCLES_WORLD_PT_mist,
1877     CYCLES_WORLD_PT_ray_visibility,
1878     CYCLES_WORLD_PT_settings,
1879     CYCLES_MATERIAL_PT_preview,
1880     CYCLES_MATERIAL_PT_surface,
1881     CYCLES_MATERIAL_PT_volume,
1882     CYCLES_MATERIAL_PT_displacement,
1883     CYCLES_MATERIAL_PT_settings,
1884     CYCLES_MATERIAL_PT_viewport,
1885     CYCLES_TEXTURE_PT_context,
1886     CYCLES_TEXTURE_PT_node,
1887     CYCLES_TEXTURE_PT_mapping,
1888     CYCLES_TEXTURE_PT_colors,
1889     CYCLES_PARTICLE_PT_textures,
1890     CYCLES_RENDER_PT_bake,
1891     CYCLES_RENDER_PT_debug,
1892     CYCLES_PARTICLE_PT_curve_settings,
1893     CYCLES_SCENE_PT_simplify,
1894 )
1895
1896
1897 def register():
1898     from bpy.utils import register_class
1899
1900     bpy.types.RENDER_PT_render.append(draw_device)
1901     bpy.types.VIEW3D_HT_header.append(draw_pause)
1902
1903     for panel in get_panels():
1904         panel.COMPAT_ENGINES.add('CYCLES')
1905
1906     for cls in classes:
1907         register_class(cls)
1908
1909
1910 def unregister():
1911     from bpy.utils import unregister_class
1912
1913     bpy.types.RENDER_PT_render.remove(draw_device)
1914     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1915
1916     for panel in get_panels():
1917         if 'CYCLES' in panel.COMPAT_ENGINES:
1918             panel.COMPAT_ENGINES.remove('CYCLES')
1919
1920     for cls in classes:
1921         unregister_class(cls)