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