Cycles / Sampling Presets:
[blender-staging.git] / intern / cycles / blender / addon / ui.py
1 #
2 # Copyright 2011, Blender Foundation.
3 #
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 #
18
19 # <pep8 compliant>
20
21 import bpy
22
23 from bpy.types import Panel, Menu, Operator
24
25
26 class CYCLES_MT_sampling_presets(Menu):
27     bl_label = "Sampling Presets"
28     preset_subdir = "cycles/sampling"
29     preset_operator = "script.execute_preset"
30     COMPAT_ENGINES = {'CYCLES'}
31     draw = Menu.draw_preset
32
33
34 class CYCLES_MT_integrator_presets(Menu):
35     bl_label = "Integrator Presets"
36     preset_subdir = "cycles/integrator"
37     preset_operator = "script.execute_preset"
38     COMPAT_ENGINES = {'CYCLES'}
39     draw = Menu.draw_preset
40
41
42 class CyclesButtonsPanel():
43     bl_space_type = "PROPERTIES"
44     bl_region_type = "WINDOW"
45     bl_context = "render"
46
47     @classmethod
48     def poll(cls, context):
49         rd = context.scene.render
50         return rd.engine == 'CYCLES'
51
52
53 class CyclesRender_PT_sampling(CyclesButtonsPanel, Panel):
54     bl_label = "Sampling"
55     bl_options = {'DEFAULT_CLOSED'}
56
57     def draw(self, context):
58         layout = self.layout
59
60         scene = context.scene
61         cscene = scene.cycles
62         device_type = context.user_preferences.system.compute_device_type
63         
64         row = layout.row(align=True)
65         row.menu("CYCLES_MT_sampling_presets", text=bpy.types.CYCLES_MT_sampling_presets.bl_label)
66         row.operator("render.cycles_sampling_preset_add", text="", icon="ZOOMIN")
67         row.operator("render.cycles_sampling_preset_add", text="", icon="ZOOMOUT").remove_active = True
68
69         row = layout.row()
70         sub = row.row()
71         sub.active = (device_type == 'NONE' or cscene.device == 'CPU')
72         sub.prop(cscene, "progressive")
73         row.prop(cscene, "squared_samples")
74         
75         split = layout.split()
76         
77         col = split.column()
78         sub = col.column(align=True)
79         sub.label("Settings:")
80         sub.prop(cscene, "seed")
81         sub.prop(cscene, "sample_clamp")
82
83         if cscene.progressive or (device_type != 'NONE' and cscene.device == 'GPU'):
84             col = split.column()
85             sub = col.column(align=True)
86             sub.label(text="Samples:")
87             sub.prop(cscene, "samples", text="Render")
88             sub.prop(cscene, "preview_samples", text="Preview")
89         else:
90             sub.label(text="AA Samples:")
91             sub.prop(cscene, "aa_samples", text="Render")
92             sub.prop(cscene, "preview_aa_samples", text="Preview")
93
94             col = split.column()
95             sub = col.column(align=True)
96             sub.label(text="Samples:")
97             sub.prop(cscene, "diffuse_samples", text="Diffuse")
98             sub.prop(cscene, "glossy_samples", text="Glossy")
99             sub.prop(cscene, "transmission_samples", text="Transmission")
100             sub.prop(cscene, "ao_samples", text="AO")
101             sub.prop(cscene, "mesh_light_samples", text="Mesh Light")
102             sub.prop(cscene, "subsurface_samples", text="Subsurface")
103
104         if cscene.feature_set == 'EXPERIMENTAL' and (device_type == 'NONE' or cscene.device == 'CPU'):
105             layout.row().prop(cscene, "sampling_pattern", text="Pattern")
106
107         for rl in scene.render.layers:
108             if rl.samples > 0:
109                 layout.separator()
110                 layout.row().prop(cscene, "use_layer_samples")
111                 break
112
113
114 class CyclesRender_PT_light_paths(CyclesButtonsPanel, Panel):
115     bl_label = "Light Paths"
116     bl_options = {'DEFAULT_CLOSED'}
117
118     def draw(self, context):
119         layout = self.layout
120
121         scene = context.scene
122         cscene = scene.cycles
123
124         row = layout.row(align=True)
125         row.menu("CYCLES_MT_integrator_presets", text=bpy.types.CYCLES_MT_integrator_presets.bl_label)
126         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMIN")
127         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMOUT").remove_active = True
128
129         split = layout.split()
130
131         col = split.column()
132
133         sub = col.column(align=True)
134         sub.label("Transparency:")
135         sub.prop(cscene, "transparent_max_bounces", text="Max")
136         sub.prop(cscene, "transparent_min_bounces", text="Min")
137         sub.prop(cscene, "use_transparent_shadows", text="Shadows")
138
139         col.separator()
140
141         col.prop(cscene, "no_caustics")
142         col.prop(cscene, "blur_glossy")
143
144         col = split.column()
145
146         sub = col.column(align=True)
147         sub.label(text="Bounces:")
148         sub.prop(cscene, "max_bounces", text="Max")
149         sub.prop(cscene, "min_bounces", text="Min")
150
151         sub = col.column(align=True)
152         sub.prop(cscene, "diffuse_bounces", text="Diffuse")
153         sub.prop(cscene, "glossy_bounces", text="Glossy")
154         sub.prop(cscene, "transmission_bounces", text="Transmission")
155
156
157 class CyclesRender_PT_motion_blur(CyclesButtonsPanel, Panel):
158     bl_label = "Motion Blur"
159     bl_options = {'DEFAULT_CLOSED'}
160
161     def draw_header(self, context):
162         rd = context.scene.render
163
164         self.layout.prop(rd, "use_motion_blur", text="")
165
166     def draw(self, context):
167         layout = self.layout
168
169         rd = context.scene.render
170         layout.active = rd.use_motion_blur
171
172         row = layout.row()
173         row.prop(rd, "motion_blur_shutter")
174
175
176 class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
177     bl_label = "Film"
178
179     def draw(self, context):
180         layout = self.layout
181
182         scene = context.scene
183         cscene = scene.cycles
184
185         split = layout.split()
186
187         col = split.column()
188         col.prop(cscene, "film_exposure")
189         col.prop(cscene, "film_transparent")
190
191         col = split.column()
192         sub = col.column(align=True)
193         sub.prop(cscene, "filter_type", text="")
194         if cscene.filter_type != 'BOX':
195             sub.prop(cscene, "filter_width", text="Width")
196
197
198 class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
199     bl_label = "Performance"
200     bl_options = {'DEFAULT_CLOSED'}
201
202     def draw(self, context):
203         layout = self.layout
204
205         scene = context.scene
206         rd = scene.render
207         cscene = scene.cycles
208
209         split = layout.split()
210
211         col = split.column(align=True)
212
213         col.label(text="Threads:")
214         col.row().prop(rd, "threads_mode", expand=True)
215         sub = col.column()
216         sub.enabled = rd.threads_mode == 'FIXED'
217         sub.prop(rd, "threads")
218
219         sub = col.column(align=True)
220         sub.label(text="Tiles:")
221         sub.prop(cscene, "tile_order", text="")
222
223         sub.prop(rd, "tile_x", text="X")
224         sub.prop(rd, "tile_y", text="Y")
225
226         sub.prop(cscene, "use_progressive_refine")
227
228         subsub = sub.column()
229         subsub.enabled = not rd.use_border
230         subsub.prop(rd, "use_save_buffers")
231
232         col = split.column(align=True)
233
234         col.label(text="Viewport:")
235         col.prop(cscene, "debug_bvh_type", text="")
236         col.separator()
237         col.prop(cscene, "preview_start_resolution")
238
239         col.separator()
240
241         col.label(text="Final Render:")
242         col.prop(cscene, "use_cache")
243         col.prop(rd, "use_persistent_data", text="Persistent Images")
244
245         col.separator()
246
247         col.label(text="Acceleration structure:")   
248         col.prop(cscene, "debug_use_spatial_splits")
249
250
251 class CyclesRender_PT_opengl(CyclesButtonsPanel, Panel):
252     bl_label = "OpenGL Render"
253     bl_options = {'DEFAULT_CLOSED'}
254
255     def draw(self, context):
256         layout = self.layout
257
258         rd = context.scene.render
259
260         split = layout.split()
261
262         col = split.column()
263         col.prop(rd, "use_antialiasing")
264         sub = col.row()
265         sub.active = rd.use_antialiasing
266         sub.prop(rd, "antialiasing_samples", expand=True)
267
268         col = split.column()
269         col.label(text="Alpha:")
270         col.prop(rd, "alpha_mode", text="")
271
272
273 class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
274     bl_label = "Layer List"
275     bl_context = "render_layer"
276     bl_options = {'HIDE_HEADER'}
277
278     def draw(self, context):
279         layout = self.layout
280
281         scene = context.scene
282         rd = scene.render
283         rl = rd.layers.active
284
285         row = layout.row()
286         row.template_list("RENDERLAYER_UL_renderlayers", "", rd, "layers", rd.layers, "active_index", rows=2)
287
288         col = row.column(align=True)
289         col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
290         col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
291
292         row = layout.row()
293         if rl:
294             row.prop(rl, "name")
295         row.prop(rd, "use_single_layer", text="", icon_only=True)
296
297
298 class CyclesRender_PT_layer_options(CyclesButtonsPanel, Panel):
299     bl_label = "Layer"
300     bl_context = "render_layer"
301
302     def draw(self, context):
303         layout = self.layout
304
305         scene = context.scene
306         rd = scene.render
307         rl = rd.layers.active
308
309         split = layout.split()
310
311         col = split.column()
312         col.prop(scene, "layers", text="Scene")
313         col.prop(rl, "layers_exclude", text="Exclude")
314
315         col = split.column()
316         col.prop(rl, "layers", text="Layer")
317         col.prop(rl, "layers_zmask", text="Mask Layer")
318
319         split = layout.split()
320
321         col = split.column()
322         col.label(text="Material:")
323         col.prop(rl, "material_override", text="")
324         col.separator()
325         col.prop(rl, "samples")
326
327         col = split.column()
328         col.prop(rl, "use_sky", "Use Environment")
329         col.prop(rl, "use_solid", "Use Surfaces")
330         col.prop(rl, "use_strand", "Use Hair")
331
332
333 class CyclesRender_PT_layer_passes(CyclesButtonsPanel, Panel):
334     bl_label = "Passes"
335     bl_context = "render_layer"
336     bl_options = {'DEFAULT_CLOSED'}
337
338     def draw(self, context):
339         layout = self.layout
340
341         scene = context.scene
342         rd = scene.render
343         rl = rd.layers.active
344
345         split = layout.split()
346
347         col = split.column()
348         col.prop(rl, "use_pass_combined")
349         col.prop(rl, "use_pass_z")
350         col.prop(rl, "use_pass_mist")
351         col.prop(rl, "use_pass_normal")
352         col.prop(rl, "use_pass_vector")
353         col.prop(rl, "use_pass_uv")
354         col.prop(rl, "use_pass_object_index")
355         col.prop(rl, "use_pass_material_index")
356         col.prop(rl, "use_pass_shadow")
357
358         col = split.column()
359         col.label(text="Diffuse:")
360         row = col.row(align=True)
361         row.prop(rl, "use_pass_diffuse_direct", text="Direct", toggle=True)
362         row.prop(rl, "use_pass_diffuse_indirect", text="Indirect", toggle=True)
363         row.prop(rl, "use_pass_diffuse_color", text="Color", toggle=True)
364         col.label(text="Glossy:")
365         row = col.row(align=True)
366         row.prop(rl, "use_pass_glossy_direct", text="Direct", toggle=True)
367         row.prop(rl, "use_pass_glossy_indirect", text="Indirect", toggle=True)
368         row.prop(rl, "use_pass_glossy_color", text="Color", toggle=True)
369         col.label(text="Transmission:")
370         row = col.row(align=True)
371         row.prop(rl, "use_pass_transmission_direct", text="Direct", toggle=True)
372         row.prop(rl, "use_pass_transmission_indirect", text="Indirect", toggle=True)
373         row.prop(rl, "use_pass_transmission_color", text="Color", toggle=True)
374
375         col.prop(rl, "use_pass_emit", text="Emission")
376         col.prop(rl, "use_pass_environment")
377         col.prop(rl, "use_pass_ambient_occlusion")
378
379
380 class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
381     bl_label = "Post Processing"
382     bl_options = {'DEFAULT_CLOSED'}
383
384     def draw(self, context):
385         layout = self.layout
386
387         rd = context.scene.render
388
389         split = layout.split()
390
391         col = split.column()
392         col.prop(rd, "use_compositing")
393         col.prop(rd, "use_sequencer")
394
395         col = split.column()
396         col.prop(rd, "dither_intensity", text="Dither", slider=True)
397
398
399 class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
400     bl_label = "Depth of Field"
401     bl_context = "data"
402
403     @classmethod
404     def poll(cls, context):
405         return context.camera and CyclesButtonsPanel.poll(context)
406
407     def draw(self, context):
408         layout = self.layout
409
410         cam = context.camera
411         ccam = cam.cycles
412
413         split = layout.split()
414
415         col = split.column()
416         col.label("Focus:")
417         col.prop(cam, "dof_object", text="")
418
419         sub = col.row()
420         sub.active = cam.dof_object is None
421         sub.prop(cam, "dof_distance", text="Distance")
422
423         col = split.column()
424
425         col.label("Aperture:")
426         sub = col.column(align=True)
427         sub.prop(ccam, "aperture_type", text="")
428         if ccam.aperture_type == 'RADIUS':
429             sub.prop(ccam, "aperture_size", text="Size")
430         elif ccam.aperture_type == 'FSTOP':
431             sub.prop(ccam, "aperture_fstop", text="Number")
432
433         sub = col.column(align=True)
434         sub.prop(ccam, "aperture_blades", text="Blades")
435         sub.prop(ccam, "aperture_rotation", text="Rotation")
436
437
438 class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
439     bl_label = ""
440     bl_context = "material"
441     bl_options = {'HIDE_HEADER'}
442
443     @classmethod
444     def poll(cls, context):
445         return (context.material or context.object) and CyclesButtonsPanel.poll(context)
446
447     def draw(self, context):
448         layout = self.layout
449
450         mat = context.material
451         ob = context.object
452         slot = context.material_slot
453         space = context.space_data
454
455         if ob:
456             row = layout.row()
457
458             row.template_list("MATERIAL_UL_matslots", "", ob, "material_slots", ob, "active_material_index", rows=2)
459
460             col = row.column(align=True)
461             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
462             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
463
464             col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
465
466             if ob.mode == 'EDIT':
467                 row = layout.row(align=True)
468                 row.operator("object.material_slot_assign", text="Assign")
469                 row.operator("object.material_slot_select", text="Select")
470                 row.operator("object.material_slot_deselect", text="Deselect")
471
472         split = layout.split(percentage=0.65)
473
474         if ob:
475             split.template_ID(ob, "active_material", new="material.new")
476             row = split.row()
477
478             if slot:
479                 row.prop(slot, "link", text="")
480             else:
481                 row.label()
482         elif mat:
483             split.template_ID(space, "pin_id")
484             split.separator()
485
486
487 class Cycles_PT_mesh_displacement(CyclesButtonsPanel, Panel):
488     bl_label = "Displacement"
489     bl_context = "data"
490
491     @classmethod
492     def poll(cls, context):
493         if CyclesButtonsPanel.poll(context):
494             if context.mesh or context.curve or context.meta_ball:
495                 if context.scene.cycles.feature_set == 'EXPERIMENTAL':
496                     return True
497
498         return False
499
500     def draw(self, context):
501         layout = self.layout
502
503         mesh = context.mesh
504         curve = context.curve
505         mball = context.meta_ball
506
507         if mesh:
508             cdata = mesh.cycles
509         elif curve:
510             cdata = curve.cycles
511         elif mball:
512             cdata = mball.cycles
513
514         layout.prop(cdata, "displacement_method", text="Method")
515         layout.prop(cdata, "use_subdivision")
516         layout.prop(cdata, "dicing_rate")
517
518
519 class Cycles_PT_mesh_normals(CyclesButtonsPanel, Panel):
520     bl_label = "Normals"
521     bl_context = "data"
522
523     @classmethod
524     def poll(cls, context):
525         return CyclesButtonsPanel.poll(context) and context.mesh
526
527     def draw(self, context):
528         layout = self.layout
529
530         mesh = context.mesh
531
532         split = layout.split()
533
534         col = split.column()
535         col.prop(mesh, "show_double_sided")
536
537         col = split.column()
538         col.label()
539
540
541 class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
542     bl_label = "Ray Visibility"
543     bl_context = "object"
544     bl_options = {'DEFAULT_CLOSED'}
545
546     @classmethod
547     def poll(cls, context):
548         ob = context.object
549         return CyclesButtonsPanel.poll(context) and ob and ob.type in {'MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META', 'LAMP'}
550
551     def draw(self, context):
552         layout = self.layout
553
554         ob = context.object
555         visibility = ob.cycles_visibility
556
557         flow = layout.column_flow()
558
559         flow.prop(visibility, "camera")
560         flow.prop(visibility, "diffuse")
561         flow.prop(visibility, "glossy")
562         flow.prop(visibility, "transmission")
563
564         if ob.type != 'LAMP':
565             flow.prop(visibility, "shadow")
566
567
568 class CYCLES_OT_use_shading_nodes(Operator):
569     """Enable nodes on a material, world or lamp"""
570     bl_idname = "cycles.use_shading_nodes"
571     bl_label = "Use Nodes"
572
573     @classmethod
574     def poll(cls, context):
575         return context.material or context.world or context.lamp
576
577     def execute(self, context):
578         if context.material:
579             context.material.use_nodes = True
580         elif context.world:
581             context.world.use_nodes = True
582         elif context.lamp:
583             context.lamp.use_nodes = True
584
585         return {'FINISHED'}
586
587
588 def find_node(material, nodetype):
589     if material and material.node_tree:
590         ntree = material.node_tree
591
592         for node in ntree.nodes:
593             if getattr(node, "type", None) == nodetype:
594                 return node
595
596     return None
597
598
599 def find_node_input(node, name):
600     for input in node.inputs:
601         if input.name == name:
602             return input
603
604     return None
605
606
607 def panel_node_draw(layout, id_data, output_type, input_name):
608     if not id_data.use_nodes:
609         layout.operator("cycles.use_shading_nodes", icon='NODETREE')
610         return False
611
612     ntree = id_data.node_tree
613
614     node = find_node(id_data, output_type)
615     if not node:
616         layout.label(text="No output node")
617     else:
618         input = find_node_input(node, input_name)
619         layout.template_node_view(ntree, node, input)
620
621     return True
622
623
624 class CyclesLamp_PT_preview(CyclesButtonsPanel, Panel):
625     bl_label = "Preview"
626     bl_context = "data"
627     bl_options = {'DEFAULT_CLOSED'}
628
629     @classmethod
630     def poll(cls, context):
631         return context.lamp and CyclesButtonsPanel.poll(context)
632
633     def draw(self, context):
634         self.layout.template_preview(context.lamp)
635
636
637 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
638     bl_label = "Lamp"
639     bl_context = "data"
640
641     @classmethod
642     def poll(cls, context):
643         return context.lamp and CyclesButtonsPanel.poll(context)
644
645     def draw(self, context):
646         layout = self.layout
647
648         lamp = context.lamp
649         clamp = lamp.cycles
650         cscene = context.scene.cycles
651         device_type = context.user_preferences.system.compute_device_type
652
653         layout.prop(lamp, "type", expand=True)
654
655         split = layout.split()
656         col = split.column(align=True)
657
658         if lamp.type in {'POINT', 'SUN', 'SPOT'}:
659             col.prop(lamp, "shadow_soft_size", text="Size")
660         elif lamp.type == 'AREA':
661             col.prop(lamp, "shape", text="")
662             sub = col.column(align=True)
663
664             if lamp.shape == 'SQUARE':
665                 sub.prop(lamp, "size")
666             elif lamp.shape == 'RECTANGLE':
667                 sub.prop(lamp, "size", text="Size X")
668                 sub.prop(lamp, "size_y", text="Size Y")
669
670         if not cscene.progressive and (device_type == 'NONE' or cscene.device == 'CPU'):
671             col.prop(clamp, "samples")
672
673         col = split.column()
674         col.prop(clamp, "cast_shadow")
675
676         layout.prop(clamp, "use_multiple_importance_sampling")
677
678         if lamp.type == 'HEMI':
679             layout.label(text="Not supported, interpreted as sun lamp")
680
681
682 class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
683     bl_label = "Nodes"
684     bl_context = "data"
685
686     @classmethod
687     def poll(cls, context):
688         return context.lamp and CyclesButtonsPanel.poll(context)
689
690     def draw(self, context):
691         layout = self.layout
692
693         lamp = context.lamp
694         if not panel_node_draw(layout, lamp, 'OUTPUT_LAMP', 'Surface'):
695             layout.prop(lamp, "color")
696
697
698 class CyclesLamp_PT_spot(CyclesButtonsPanel, Panel):
699     bl_label = "Spot Shape"
700     bl_context = "data"
701
702     @classmethod
703     def poll(cls, context):
704         lamp = context.lamp
705         return (lamp and lamp.type == 'SPOT') and CyclesButtonsPanel.poll(context)
706
707     def draw(self, context):
708         layout = self.layout
709
710         lamp = context.lamp
711
712         split = layout.split()
713
714         col = split.column()
715         sub = col.column()
716         sub.prop(lamp, "spot_size", text="Size")
717         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
718
719         col = split.column()
720         col.prop(lamp, "show_cone")
721
722
723 class CyclesWorld_PT_preview(CyclesButtonsPanel, Panel):
724     bl_label = "Preview"
725     bl_context = "world"
726     bl_options = {'DEFAULT_CLOSED'}
727
728     @classmethod
729     def poll(cls, context):
730         return context.world and CyclesButtonsPanel.poll(context)
731
732     def draw(self, context):
733         self.layout.template_preview(context.world)
734
735
736 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
737     bl_label = "Surface"
738     bl_context = "world"
739
740     @classmethod
741     def poll(cls, context):
742         return context.world and CyclesButtonsPanel.poll(context)
743
744     def draw(self, context):
745         layout = self.layout
746
747         world = context.world
748
749         if not panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Surface'):
750             layout.prop(world, "horizon_color", text="Color")
751
752
753 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
754     bl_label = "Volume"
755     bl_context = "world"
756     bl_options = {'DEFAULT_CLOSED'}
757
758     @classmethod
759     def poll(cls, context):
760         # world = context.world
761         # world and world.node_tree and CyclesButtonsPanel.poll(context)
762         return False
763
764     def draw(self, context):
765         layout = self.layout
766         layout.active = False
767
768         world = context.world
769         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
770
771
772 class CyclesWorld_PT_ambient_occlusion(CyclesButtonsPanel, Panel):
773     bl_label = "Ambient Occlusion"
774     bl_context = "world"
775
776     @classmethod
777     def poll(cls, context):
778         return context.world and CyclesButtonsPanel.poll(context)
779
780     def draw_header(self, context):
781         light = context.world.light_settings
782         self.layout.prop(light, "use_ambient_occlusion", text="")
783
784     def draw(self, context):
785         layout = self.layout
786         light = context.world.light_settings
787
788         layout.active = light.use_ambient_occlusion
789
790         row = layout.row()
791         row.prop(light, "ao_factor", text="Factor")
792         row.prop(light, "distance", text="Distance")
793
794
795 class CyclesWorld_PT_mist(CyclesButtonsPanel, Panel):
796     bl_label = "Mist Pass"
797     bl_context = "world"
798     bl_options = {'DEFAULT_CLOSED'}
799
800     @classmethod
801     def poll(cls, context):
802         if CyclesButtonsPanel.poll(context):
803             for rl in context.scene.render.layers:
804                 if rl.use_pass_mist:
805                     return True
806
807         return False
808
809     def draw(self, context):
810         layout = self.layout
811
812         world = context.world
813
814         split = layout.split(align=True)
815         split.prop(world.mist_settings, "start")
816         split.prop(world.mist_settings, "depth")
817
818         layout.prop(world.mist_settings, "falloff")
819
820
821 class CyclesWorld_PT_ray_visibility(CyclesButtonsPanel, Panel):
822     bl_label = "Ray Visibility"
823     bl_context = "world"
824     bl_options = {'DEFAULT_CLOSED'}
825
826     @classmethod
827     def poll(cls, context):
828         return CyclesButtonsPanel.poll(context) and context.world
829
830     def draw(self, context):
831         layout = self.layout
832
833         world = context.world
834         visibility = world.cycles_visibility
835
836         flow = layout.column_flow()
837
838         flow.prop(visibility, "camera")
839         flow.prop(visibility, "diffuse")
840         flow.prop(visibility, "glossy")
841         flow.prop(visibility, "transmission")
842
843
844 class CyclesWorld_PT_settings(CyclesButtonsPanel, Panel):
845     bl_label = "Settings"
846     bl_context = "world"
847     bl_options = {'DEFAULT_CLOSED'}
848
849     @classmethod
850     def poll(cls, context):
851         return context.world and CyclesButtonsPanel.poll(context)
852
853     def draw(self, context):
854         layout = self.layout
855
856         world = context.world
857         cworld = world.cycles
858         cscene = context.scene.cycles
859         device_type = context.user_preferences.system.compute_device_type
860
861         col = layout.column()
862
863         col.prop(cworld, "sample_as_light")
864         sub = col.row(align=True)
865         sub.active = cworld.sample_as_light
866         sub.prop(cworld, "sample_map_resolution")
867         if not cscene.progressive and (device_type == 'NONE' or cscene.device == 'CPU'):
868             sub.prop(cworld, "samples")
869
870
871 class CyclesMaterial_PT_preview(CyclesButtonsPanel, Panel):
872     bl_label = "Preview"
873     bl_context = "material"
874     bl_options = {'DEFAULT_CLOSED'}
875
876     @classmethod
877     def poll(cls, context):
878         return context.material and CyclesButtonsPanel.poll(context)
879
880     def draw(self, context):
881         self.layout.template_preview(context.material)
882
883
884 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
885     bl_label = "Surface"
886     bl_context = "material"
887
888     @classmethod
889     def poll(cls, context):
890         return context.material and CyclesButtonsPanel.poll(context)
891
892     def draw(self, context):
893         layout = self.layout
894
895         mat = context.material
896         if not panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface'):
897             layout.prop(mat, "diffuse_color")
898
899
900 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
901     bl_label = "Volume"
902     bl_context = "material"
903     bl_options = {'DEFAULT_CLOSED'}
904
905     @classmethod
906     def poll(cls, context):
907         # mat = context.material
908         # mat and mat.node_tree and CyclesButtonsPanel.poll(context)
909         return False
910
911     def draw(self, context):
912         layout = self.layout
913         layout.active = False
914
915         mat = context.material
916         cmat = mat.cycles
917
918         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
919
920         layout.prop(cmat, "homogeneous_volume")
921
922
923 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
924     bl_label = "Displacement"
925     bl_context = "material"
926
927     @classmethod
928     def poll(cls, context):
929         mat = context.material
930         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
931
932     def draw(self, context):
933         layout = self.layout
934
935         mat = context.material
936         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
937
938
939 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
940     bl_label = "Settings"
941     bl_context = "material"
942     bl_options = {'DEFAULT_CLOSED'}
943
944     @classmethod
945     def poll(cls, context):
946         return context.material and CyclesButtonsPanel.poll(context)
947
948     def draw(self, context):
949         layout = self.layout
950
951         mat = context.material
952         cmat = mat.cycles
953
954         split = layout.split()
955
956         col = split.column()
957         col.prop(mat, "diffuse_color", text="Viewport Color")
958
959         col = split.column(align=True)
960         col.label()
961         col.prop(mat, "pass_index")
962
963         col = layout.column()
964         col.prop(cmat, "sample_as_light")
965         col.prop(cmat, "use_transparent_shadow")
966
967
968 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
969     bl_label = ""
970     bl_context = "texture"
971     bl_options = {'HIDE_HEADER'}
972     COMPAT_ENGINES = {'CYCLES'}
973
974     def draw(self, context):
975         layout = self.layout
976
977         tex = context.texture
978         space = context.space_data
979         pin_id = space.pin_id
980         use_pin_id = space.use_pin_id
981         user = context.texture_user
982
983         space.use_limited_texture_context = False
984
985         if not (use_pin_id and isinstance(pin_id, bpy.types.Texture)):
986             pin_id = None
987
988         if not pin_id:
989             layout.template_texture_user()
990
991         if user or pin_id:
992             layout.separator()
993
994             split = layout.split(percentage=0.65)
995             col = split.column()
996
997             if pin_id:
998                 col.template_ID(space, "pin_id")
999             else:
1000                 propname = context.texture_user_property.identifier
1001                 col.template_ID(user, propname, new="texture.new")
1002
1003             if tex:
1004                 split = layout.split(percentage=0.2)
1005                 split.label(text="Type:")
1006                 split.prop(tex, "type", text="")
1007
1008
1009 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
1010     bl_label = "Node"
1011     bl_context = "texture"
1012
1013     @classmethod
1014     def poll(cls, context):
1015         node = context.texture_node
1016         return node and CyclesButtonsPanel.poll(context)
1017
1018     def draw(self, context):
1019         layout = self.layout
1020
1021         node = context.texture_node
1022         ntree = node.id_data
1023         layout.template_node_view(ntree, node, None)
1024
1025
1026 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
1027     bl_label = "Mapping"
1028     bl_context = "texture"
1029
1030     @classmethod
1031     def poll(cls, context):
1032         node = context.texture_node
1033         return node and CyclesButtonsPanel.poll(context)
1034
1035     def draw(self, context):
1036         layout = self.layout
1037
1038         node = context.texture_node
1039
1040         mapping = node.texture_mapping
1041
1042         row = layout.row()
1043
1044         row.column().prop(mapping, "translation")
1045         row.column().prop(mapping, "rotation")
1046         row.column().prop(mapping, "scale")
1047
1048         layout.label(text="Projection:")
1049
1050         row = layout.row()
1051         row.prop(mapping, "mapping_x", text="")
1052         row.prop(mapping, "mapping_y", text="")
1053         row.prop(mapping, "mapping_z", text="")
1054
1055
1056 class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
1057     bl_label = "Color"
1058     bl_context = "texture"
1059     bl_options = {'DEFAULT_CLOSED'}
1060
1061     @classmethod
1062     def poll(cls, context):
1063         # node = context.texture_node
1064         return False
1065         #return node and CyclesButtonsPanel.poll(context)
1066
1067     def draw(self, context):
1068         layout = self.layout
1069
1070         node = context.texture_node
1071
1072         mapping = node.color_mapping
1073
1074         split = layout.split()
1075
1076         col = split.column()
1077         col.label(text="Blend:")
1078         col.prop(mapping, "blend_type", text="")
1079         col.prop(mapping, "blend_factor", text="Factor")
1080         col.prop(mapping, "blend_color", text="")
1081
1082         col = split.column()
1083         col.label(text="Adjust:")
1084         col.prop(mapping, "brightness")
1085         col.prop(mapping, "contrast")
1086         col.prop(mapping, "saturation")
1087
1088         layout.separator()
1089
1090         layout.prop(mapping, "use_color_ramp", text="Ramp")
1091         if mapping.use_color_ramp:
1092             layout.template_color_ramp(mapping, "color_ramp", expand=True)
1093
1094
1095 class CyclesParticle_PT_textures(CyclesButtonsPanel, Panel):
1096     bl_label = "Textures"
1097     bl_context = "particle"
1098     bl_options = {'DEFAULT_CLOSED'}
1099
1100     @classmethod
1101     def poll(cls, context):
1102         psys = context.particle_system
1103         return psys and CyclesButtonsPanel.poll(context)
1104
1105     def draw(self, context):
1106         layout = self.layout
1107
1108         psys = context.particle_system
1109         part = psys.settings
1110
1111         row = layout.row()
1112         row.template_list("TEXTURE_UL_texslots", "", part, "texture_slots", part, "active_texture_index", rows=2)
1113
1114         col = row.column(align=True)
1115         col.operator("texture.slot_move", text="", icon='TRIA_UP').type = 'UP'
1116         col.operator("texture.slot_move", text="", icon='TRIA_DOWN').type = 'DOWN'
1117         col.menu("TEXTURE_MT_specials", icon='DOWNARROW_HLT', text="")
1118
1119         if not part.active_texture:
1120             layout.template_ID(part, "active_texture", new="texture.new")
1121         else:
1122             slot = part.texture_slots[part.active_texture_index]
1123             layout.template_ID(slot, "texture", new="texture.new")
1124
1125
1126 class CyclesRender_PT_CurveRendering(CyclesButtonsPanel, Panel):
1127     bl_label = "Cycles Hair Rendering"
1128     bl_context = "particle"
1129
1130     @classmethod
1131     def poll(cls, context):
1132         scene = context.scene
1133         cscene = scene.cycles
1134         psys = context.particle_system
1135         experimental = (cscene.feature_set == 'EXPERIMENTAL')
1136         return CyclesButtonsPanel.poll(context) and experimental and psys
1137
1138     def draw_header(self, context):
1139         ccscene = context.scene.cycles_curves
1140         self.layout.prop(ccscene, "use_curves", text="")
1141
1142     def draw(self, context):
1143         layout = self.layout
1144
1145         scene = context.scene
1146         ccscene = scene.cycles_curves
1147
1148         layout.active = ccscene.use_curves
1149
1150         layout.prop(ccscene, "preset", text="Mode")
1151
1152         if ccscene.preset == 'CUSTOM':
1153             layout.prop(ccscene, "primitive", text="Primitive")
1154
1155             if ccscene.primitive == 'TRIANGLES':
1156                 layout.prop(ccscene, "triangle_method", text="Method")
1157                 if ccscene.triangle_method == 'TESSELLATED_TRIANGLES':
1158                     layout.prop(ccscene, "resolution", text="Resolution")
1159                 layout.prop(ccscene, "use_smooth", text="Smooth")
1160             elif ccscene.primitive == 'LINE_SEGMENTS':
1161                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
1162
1163                 row = layout.row()
1164                 row.prop(ccscene, "use_encasing", text="Exclude encasing")
1165                 sub = row.row()
1166                 sub.active = ccscene.use_encasing
1167                 sub.prop(ccscene, "encasing_ratio", text="Ratio for encasing")
1168
1169                 layout.prop(ccscene, "line_method", text="Method")
1170                 layout.prop(ccscene, "use_tangent_normal", text="Use tangent normal as default")
1171                 layout.prop(ccscene, "use_tangent_normal_geometry", text="Use tangent normal geometry")
1172                 layout.prop(ccscene, "use_tangent_normal_correction", text="Correct tangent normal for slope")
1173                 layout.prop(ccscene, "interpolation", text="Interpolation")
1174
1175                 row = layout.row()
1176                 row.prop(ccscene, "segments", text="Segments")
1177                 row.prop(ccscene, "normalmix", text="Ray Mix")
1178             elif ccscene.primitive in {'CURVE_SEGMENTS', 'CURVE_RIBBONS'}:
1179                 layout.prop(ccscene, "subdivisions", text="Curve subdivisions")
1180                 layout.prop(ccscene, "use_backfacing", text="Check back-faces")
1181
1182                 layout.prop(ccscene, "interpolation", text="Interpolation")
1183                 row = layout.row()
1184                 row.prop(ccscene, "segments", text="Segments")
1185
1186             row = layout.row()
1187             row.prop(ccscene, "use_parents", text="Include parents")
1188
1189         row = layout.row()
1190         row.prop(ccscene, "minimum_width", text="Min Pixels")
1191         row.prop(ccscene, "maximum_width", text="Max Ext.")
1192
1193
1194 class CyclesParticle_PT_CurveSettings(CyclesButtonsPanel, Panel):
1195     bl_label = "Cycles Hair Settings"
1196     bl_context = "particle"
1197
1198     @classmethod
1199     def poll(cls, context):
1200         scene = context.scene
1201         cscene = scene.cycles
1202         ccscene = scene.cycles_curves
1203         use_curves = ccscene.use_curves and context.particle_system
1204         experimental = cscene.feature_set == 'EXPERIMENTAL'
1205         return CyclesButtonsPanel.poll(context) and experimental and use_curves
1206
1207     def draw(self, context):
1208         layout = self.layout
1209
1210         psys = context.particle_settings
1211         cpsys = psys.cycles
1212
1213         row = layout.row()
1214         row.prop(cpsys, "shape", text="Shape")
1215
1216         layout.label(text="Thickness:")
1217         row = layout.row()
1218         row.prop(cpsys, "root_width", text="Root")
1219         row.prop(cpsys, "tip_width", text="Tip")
1220
1221         row = layout.row()
1222         row.prop(cpsys, "radius_scale", text="Scaling")
1223         row.prop(cpsys, "use_closetip", text="Close tip")
1224
1225
1226 class CyclesScene_PT_simplify(CyclesButtonsPanel, Panel):
1227     bl_label = "Simplify"
1228     bl_context = "scene"
1229     COMPAT_ENGINES = {'CYCLES'}
1230
1231     def draw_header(self, context):
1232         rd = context.scene.render
1233         self.layout.prop(rd, "use_simplify", text="")
1234
1235     def draw(self, context):
1236         layout = self.layout
1237
1238         rd = context.scene.render
1239
1240         layout.active = rd.use_simplify
1241
1242         row = layout.row()
1243         row.prop(rd, "simplify_subdivision", text="Subdivision")
1244         row.prop(rd, "simplify_child_particles", text="Child Particles")
1245
1246
1247 def draw_device(self, context):
1248     scene = context.scene
1249     layout = self.layout
1250
1251     if scene.render.engine == 'CYCLES':
1252         from . import engine
1253         cscene = scene.cycles
1254
1255         layout.prop(cscene, "feature_set")
1256
1257         device_type = context.user_preferences.system.compute_device_type
1258         if device_type == 'CUDA':
1259             layout.prop(cscene, "device")
1260         elif device_type == 'OPENCL':
1261             layout.prop(cscene, "device")
1262
1263         if engine.with_osl() and (cscene.device == 'CPU' or device_type == 'NONE'):
1264             layout.prop(cscene, "shading_system")
1265
1266
1267 def draw_pause(self, context):
1268     layout = self.layout
1269     scene = context.scene
1270
1271     if scene.render.engine == "CYCLES":
1272         view = context.space_data
1273
1274         if view.viewport_shade == 'RENDERED':
1275             cscene = scene.cycles
1276             layername = scene.render.layers.active.name
1277             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
1278             layout.prop(cscene, "preview_active_layer", icon="RENDERLAYERS", text=layername)
1279
1280
1281 def get_panels():
1282     types = bpy.types
1283     return (
1284         types.RENDER_PT_render,
1285         types.RENDER_PT_output,
1286         types.RENDER_PT_encoding,
1287         types.RENDER_PT_dimensions,
1288         types.RENDER_PT_stamp,
1289         types.SCENE_PT_scene,
1290         types.SCENE_PT_color_management,
1291         types.SCENE_PT_custom_props,
1292         types.SCENE_PT_audio,
1293         types.SCENE_PT_unit,
1294         types.SCENE_PT_keying_sets,
1295         types.SCENE_PT_keying_set_paths,
1296         types.SCENE_PT_physics,
1297         types.WORLD_PT_context_world,
1298         types.WORLD_PT_custom_props,
1299         types.DATA_PT_context_mesh,
1300         types.DATA_PT_context_camera,
1301         types.DATA_PT_context_lamp,
1302         types.DATA_PT_context_speaker,
1303         types.DATA_PT_texture_space,
1304         types.DATA_PT_curve_texture_space,
1305         types.DATA_PT_mball_texture_space,
1306         types.DATA_PT_vertex_groups,
1307         types.DATA_PT_shape_keys,
1308         types.DATA_PT_uv_texture,
1309         types.DATA_PT_vertex_colors,
1310         types.DATA_PT_camera,
1311         types.DATA_PT_camera_display,
1312         types.DATA_PT_lens,
1313         types.DATA_PT_speaker,
1314         types.DATA_PT_distance,
1315         types.DATA_PT_cone,
1316         types.DATA_PT_customdata,
1317         types.DATA_PT_custom_props_mesh,
1318         types.DATA_PT_custom_props_camera,
1319         types.DATA_PT_custom_props_lamp,
1320         types.DATA_PT_custom_props_speaker,
1321         types.DATA_PT_custom_props_arm,
1322         types.DATA_PT_custom_props_curve,
1323         types.DATA_PT_custom_props_lattice,
1324         types.DATA_PT_custom_props_metaball,
1325         types.TEXTURE_PT_custom_props,
1326         types.TEXTURE_PT_clouds,
1327         types.TEXTURE_PT_wood,
1328         types.TEXTURE_PT_marble,
1329         types.TEXTURE_PT_magic,
1330         types.TEXTURE_PT_blend,
1331         types.TEXTURE_PT_stucci,
1332         types.TEXTURE_PT_image,
1333         types.TEXTURE_PT_image_sampling,
1334         types.TEXTURE_PT_image_mapping,
1335         types.TEXTURE_PT_musgrave,
1336         types.TEXTURE_PT_voronoi,
1337         types.TEXTURE_PT_distortednoise,
1338         types.TEXTURE_PT_voxeldata,
1339         types.TEXTURE_PT_pointdensity,
1340         types.TEXTURE_PT_pointdensity_turbulence,
1341         types.TEXTURE_PT_mapping,
1342         types.TEXTURE_PT_influence,
1343         types.TEXTURE_PT_colors,
1344         types.PARTICLE_PT_context_particles,
1345         types.PARTICLE_PT_custom_props,
1346         types.PARTICLE_PT_emission,
1347         types.PARTICLE_PT_hair_dynamics,
1348         types.PARTICLE_PT_cache,
1349         types.PARTICLE_PT_velocity,
1350         types.PARTICLE_PT_rotation,
1351         types.PARTICLE_PT_physics,
1352         types.SCENE_PT_rigid_body_world,
1353         types.SCENE_PT_rigid_body_cache,
1354         types.SCENE_PT_rigid_body_field_weights,
1355         types.PARTICLE_PT_boidbrain,
1356         types.PARTICLE_PT_render,
1357         types.PARTICLE_PT_draw,
1358         types.PARTICLE_PT_children,
1359         types.PARTICLE_PT_field_weights,
1360         types.PARTICLE_PT_force_fields,
1361         types.PARTICLE_PT_vertexgroups,
1362         types.MATERIAL_PT_custom_props,
1363         types.BONE_PT_custom_props,
1364         types.OBJECT_PT_custom_props,
1365         )
1366
1367
1368 def register():
1369     bpy.types.RENDER_PT_render.append(draw_device)
1370     bpy.types.VIEW3D_HT_header.append(draw_pause)
1371
1372     for panel in get_panels():
1373         panel.COMPAT_ENGINES.add('CYCLES')
1374
1375
1376 def unregister():
1377     bpy.types.RENDER_PT_render.remove(draw_device)
1378     bpy.types.VIEW3D_HT_header.remove(draw_pause)
1379
1380     for panel in get_panels():
1381         panel.COMPAT_ENGINES.remove('CYCLES')