Cycles: svn merge -r41225:41232 ^/trunk/blender
[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 import bpy
20
21 from bpy.types import Panel, Menu
22
23 from cycles import enums
24 from cycles import engine
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 class CyclesButtonsPanel():
34     bl_space_type = "PROPERTIES"
35     bl_region_type = "WINDOW"
36     bl_context = "render"
37     
38     @classmethod
39     def poll(cls, context):
40         rd = context.scene.render
41         return rd.engine == 'CYCLES'
42
43 class CyclesRender_PT_integrator(CyclesButtonsPanel, Panel):
44     bl_label = "Integrator"
45     bl_options = {'DEFAULT_CLOSED'}
46
47     def draw(self, context):
48         layout = self.layout
49
50         scene = context.scene
51         cscene = scene.cycles
52         
53         row = layout.row(align=True)
54         row.menu("CYCLES_MT_integrator_presets", text=bpy.types.CYCLES_MT_integrator_presets.bl_label)
55         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMIN")
56         row.operator("render.cycles_integrator_preset_add", text="", icon="ZOOMOUT").remove_active = True
57
58         split = layout.split()
59
60         col = split.column()
61         sub = col.column(align=True)
62         sub.label(text="Samples:")
63         sub.prop(cscene, "samples", text="Render")
64         sub.prop(cscene, "preview_samples", text="Preview")
65
66         sub = col.column(align=True)
67         sub.label("Transparency:")
68         sub.prop(cscene, "transparent_max_bounces", text="Max")
69         sub.prop(cscene, "transparent_min_bounces", text="Min")
70         sub.prop(cscene, "use_transparent_shadows", text="Shadows")
71         sub.prop(cscene, "no_caustics")
72
73         col = split.column()
74
75         sub = col.column(align=True)
76         sub.label(text="Bounces:")
77         sub.prop(cscene, "max_bounces", text="Max")
78         sub.prop(cscene, "min_bounces", text="Min")
79
80         sub = col.column(align=True)
81         sub.label(text="Light Paths:")
82         sub.prop(cscene, "diffuse_bounces", text="Diffuse")
83         sub.prop(cscene, "glossy_bounces", text="Glossy")
84         sub.prop(cscene, "transmission_bounces", text="Transmission")
85
86         #row = col.row()
87         #row.prop(cscene, "blur_caustics")
88         #row.active = not cscene.no_caustics
89         
90 class CyclesRender_PT_film(CyclesButtonsPanel, Panel):
91     bl_label = "Film"
92
93     def draw(self, context):
94         layout = self.layout
95
96         scene = context.scene
97         cscene = scene.cycles
98
99         split = layout.split()
100
101         col = split.column();
102         col.prop(cscene, "film_exposure")
103         col.prop(cscene, "film_transparent")
104
105         col = split.column()
106         sub = col.column(align=True)
107         sub.prop(cscene, "filter_type", text="")
108         if cscene.filter_type != 'BOX':
109             sub.prop(cscene, "filter_width", text="Width")
110
111 class CyclesRender_PT_performance(CyclesButtonsPanel, Panel):
112     bl_label = "Performance"
113     bl_options = {'DEFAULT_CLOSED'}
114
115     def draw(self, context):
116         layout = self.layout
117
118         scene = context.scene
119         rd = scene.render
120         cscene = scene.cycles
121
122         split = layout.split()
123
124         col = split.column(align=True)
125
126         col.label(text="Threads:")
127         col.row().prop(rd, "threads_mode", expand=True)
128         sub = col.column()
129         sub.enabled = rd.threads_mode == 'FIXED'
130         sub.prop(rd, "threads")
131
132         sub = col.column(align=True)
133         sub.label(text="Tiles:")
134         sub.prop(cscene, "debug_tile_size")
135         sub.prop(cscene, "debug_min_size")
136
137         col = split.column()
138
139         sub = col.column(align=True)
140         sub.label(text="Acceleration structure:")
141         sub.prop(cscene, "debug_bvh_type", text="")
142         sub.prop(cscene, "debug_use_spatial_splits")
143
144 class CyclesRender_PT_layers(CyclesButtonsPanel, Panel):
145     bl_label = "Layers"
146     bl_options = {'DEFAULT_CLOSED'}
147     COMPAT_ENGINES = {'BLENDER_RENDER'}
148
149     def draw(self, context):
150         layout = self.layout
151
152         scene = context.scene
153         rd = scene.render
154
155         # row = layout.row()
156         # row.template_list(rd, "layers", rd.layers, "active_index", rows=2)
157
158         # col = row.column(align=True)
159         # col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
160         # col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
161
162         row = layout.row()
163         # rl = rd.layers.active
164         rl = rd.layers[0]
165         row.prop(rl, "name")
166         #row.prop(rd, "use_single_layer", text="", icon_only=True)
167
168         split = layout.split()
169
170         col = split.column()
171         col.prop(scene, "layers", text="Scene")
172
173         col = split.column()
174         col.prop(rl, "layers", text="Layer")
175
176         layout.separator()
177
178         layout.prop(rl, "material_override", text="Material")
179
180 class Cycles_PT_post_processing(CyclesButtonsPanel, Panel):
181     bl_label = "Post Processing"
182     bl_options = {'DEFAULT_CLOSED'}
183
184     def draw(self, context):
185         layout = self.layout
186
187         rd = context.scene.render
188
189         split = layout.split()
190
191         col = split.column()
192         col.prop(rd, "use_compositing")
193         col.prop(rd, "use_sequencer")
194
195         col = split.column()
196         col.prop(rd, "dither_intensity", text="Dither", slider=True)
197
198 class CyclesCamera_PT_dof(CyclesButtonsPanel, Panel):
199     bl_label = "Depth of Field"
200     bl_context = "data"
201
202     @classmethod
203     def poll(cls, context):
204         return context.camera and CyclesButtonsPanel.poll(context)
205
206     def draw(self, context):
207         layout = self.layout
208
209         cam = context.camera
210         ccam = cam.cycles
211
212         split = layout.split()
213
214         col = split.column()
215         col.label("Focus:")
216         col.prop(cam, "dof_object", text="")
217
218         sub = col.row()
219         sub.active = cam.dof_object is None
220         sub.prop(cam, "dof_distance", text="Distance")
221
222         col = split.column()
223
224         col.label("Aperture:")
225         col.prop(ccam, "aperture_size", text="Size")
226
227         sub = col.column(align=True)
228         sub.prop(ccam, "aperture_blades", text="Blades")
229         sub.prop(ccam, "aperture_rotation", text="Rotation")
230
231 class Cycles_PT_context_material(CyclesButtonsPanel, Panel):
232     bl_label = "Surface"
233     bl_context = "material"
234     bl_options = {'HIDE_HEADER'}
235
236     @classmethod
237     def poll(cls, context):
238         return (context.material or context.object) and CyclesButtonsPanel.poll(context)
239
240     def draw(self, context):
241         layout = self.layout
242
243         mat = context.material
244         ob = context.object
245         slot = context.material_slot
246         space = context.space_data
247
248         if ob:
249             row = layout.row()
250
251             row.template_list(ob, "material_slots", ob, "active_material_index", rows=2)
252
253             col = row.column(align=True)
254             col.operator("object.material_slot_add", icon='ZOOMIN', text="")
255             col.operator("object.material_slot_remove", icon='ZOOMOUT', text="")
256
257             col.menu("MATERIAL_MT_specials", icon='DOWNARROW_HLT', text="")
258
259             if ob.mode == 'EDIT':
260                 row = layout.row(align=True)
261                 row.operator("object.material_slot_assign", text="Assign")
262                 row.operator("object.material_slot_select", text="Select")
263                 row.operator("object.material_slot_deselect", text="Deselect")
264
265         split = layout.split(percentage=0.65)
266
267         if ob:
268             split.template_ID(ob, "active_material", new="material.new")
269             row = split.row()
270
271             if slot:
272                 row.prop(slot, "link", text="")
273             else:
274                 row.label()
275         elif mat:
276             split.template_ID(space, "pin_id")
277             split.separator()
278
279 class Cycles_PT_mesh_displacement(CyclesButtonsPanel, Panel):
280     bl_label = "Displacement"
281     bl_context = "data"
282
283     @classmethod
284     def poll(cls, context):
285         return context.mesh or context.curve or context.meta_ball
286
287     def draw(self, context):
288         layout = self.layout
289
290         mesh = context.mesh
291         curve = context.curve
292         mball = context.meta_ball
293
294         if mesh:
295             cdata = mesh.cycles
296         elif curve:
297             cdata = curve.cycles
298         elif mball:
299             cdata = mball.cycles
300
301         layout.prop(cdata, "displacement_method", text="Method")
302         layout.prop(cdata, "use_subdivision");
303         layout.prop(cdata, "dicing_rate");
304
305 class CyclesObject_PT_ray_visibility(CyclesButtonsPanel, Panel):
306     bl_label = "Ray Visibility"
307     bl_context = "object"
308     bl_options = {'DEFAULT_CLOSED'}
309
310     @classmethod
311     def poll(cls, context):
312         ob = context.object
313         return ob and ob.type in ('MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META') # todo: 'LAMP'
314
315     def draw(self, context):
316         layout = self.layout
317
318         ob = context.object
319         visibility = ob.cycles_visibility
320
321         split = layout.split()
322
323         col = split.column()
324         col.prop(visibility, "camera")
325         col.prop(visibility, "diffuse")
326         col.prop(visibility, "glossy")
327
328         col = split.column()
329         col.prop(visibility, "transmission")
330         col.prop(visibility, "shadow")
331
332 def find_node(material, nodetype):
333     if material and material.node_tree:
334         ntree = material.node_tree
335
336         for node in ntree.nodes:
337             if hasattr(node, 'type') and node.type == nodetype:
338                 return node
339     
340     return None
341
342 def find_node_input(node, name):
343     for input in node.inputs:
344         if input.name == name:
345             return input
346     
347     return None
348
349 def panel_node_draw(layout, id, output_type, input_name):
350     if not id.node_tree:
351         layout.prop(id, "use_nodes", icon='NODETREE')
352         return
353
354     ntree = id.node_tree
355
356     node = find_node(id, output_type)
357     if not node:
358         layout.label(text="No output node.")
359     else:
360         input = find_node_input(node, input_name)
361         layout.template_node_view(ntree, node, input);
362
363 class CyclesLamp_PT_lamp(CyclesButtonsPanel, Panel):
364     bl_label = "Lamp"
365     bl_context = "data"
366
367     @classmethod
368     def poll(cls, context):
369         return context.lamp and CyclesButtonsPanel.poll(context)
370
371     def draw(self, context):
372         layout = self.layout
373
374         lamp = context.lamp
375         clamp = lamp.cycles
376
377         layout.prop(lamp, "type", expand=True)
378
379         split = layout.split()
380         col = split.column(align=True)
381
382         if lamp.type in ('POINT', 'SUN', 'SPOT'):
383             col.prop(lamp, "shadow_soft_size", text="Size")
384         elif lamp.type == 'AREA':
385             col.prop(lamp, "shape", text="")
386             sub = col.column(align=True)
387
388             if lamp.shape == 'SQUARE':
389                 sub.prop(lamp, "size")
390             elif lamp.shape == 'RECTANGLE':
391                 sub.prop(lamp, "size", text="Size X")
392                 sub.prop(lamp, "size_y", text="Size Y")
393
394         col = split.column()
395         col.prop(clamp, "cast_shadow")
396
397         if lamp.type == 'SPOT':
398             layout.label(text="Not supported, interpreted as point lamp.")
399         elif lamp.type == 'HEMI':
400             layout.label(text="Not supported, interpreted as sun lamp.")
401    
402 class CyclesLamp_PT_nodes(CyclesButtonsPanel, Panel):
403     bl_label = "Nodes"
404     bl_context = "data"
405
406     @classmethod
407     def poll(cls, context):
408         return context.lamp and CyclesButtonsPanel.poll(context)
409
410     def draw(self, context):
411         layout = self.layout
412
413         mat = context.lamp
414         panel_node_draw(layout, mat, 'OUTPUT_LAMP', 'Surface')
415
416 class CyclesWorld_PT_surface(CyclesButtonsPanel, Panel):
417     bl_label = "Surface"
418     bl_context = "world"
419
420     @classmethod
421     def poll(cls, context):
422         return context.world and CyclesButtonsPanel.poll(context)
423
424     def draw(self, context):
425         layout = self.layout
426
427         mat = context.world
428         panel_node_draw(layout, mat, 'OUTPUT_WORLD', 'Surface')
429
430 class CyclesWorld_PT_volume(CyclesButtonsPanel, Panel):
431     bl_label = "Volume"
432     bl_context = "world"
433     bl_options = {'DEFAULT_CLOSED'}
434
435     @classmethod
436     def poll(cls, context):
437         world = context.world
438         return world and world.node_tree and CyclesButtonsPanel.poll(context)
439
440     def draw(self, context):
441         layout = self.layout
442         layout.active = False
443
444         world = context.world
445         panel_node_draw(layout, world, 'OUTPUT_WORLD', 'Volume')
446
447 class CyclesMaterial_PT_surface(CyclesButtonsPanel, Panel):
448     bl_label = "Surface"
449     bl_context = "material"
450
451     @classmethod
452     def poll(cls, context):
453         return context.material and CyclesButtonsPanel.poll(context)
454
455     def draw(self, context):
456         layout = self.layout
457
458         mat = context.material
459         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Surface')
460
461 class CyclesMaterial_PT_volume(CyclesButtonsPanel, Panel):
462     bl_label = "Volume"
463     bl_context = "material"
464     bl_options = {'DEFAULT_CLOSED'}
465
466     @classmethod
467     def poll(cls, context):
468         mat = context.material
469         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
470
471     def draw(self, context):
472         layout = self.layout
473         layout.active = False
474
475         mat = context.material
476         cmat = mat.cycles
477
478         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Volume')
479
480         layout.prop(cmat, "homogeneous_volume")
481
482 class CyclesMaterial_PT_displacement(CyclesButtonsPanel, Panel):
483     bl_label = "Displacement"
484     bl_context = "material"
485
486     @classmethod
487     def poll(cls, context):
488         mat = context.material
489         return mat and mat.node_tree and CyclesButtonsPanel.poll(context)
490
491     def draw(self, context):
492         layout = self.layout
493
494         mat = context.material
495         panel_node_draw(layout, mat, 'OUTPUT_MATERIAL', 'Displacement')
496
497 class CyclesMaterial_PT_settings(CyclesButtonsPanel, Panel):
498     bl_label = "Settings"
499     bl_context = "material"
500     bl_options = {'DEFAULT_CLOSED'}
501
502     @classmethod
503     def poll(cls, context):
504         return context.material and CyclesButtonsPanel.poll(context)
505
506     def draw(self, context):
507         layout = self.layout
508
509         mat = context.material
510         cmat = mat.cycles
511
512         split = layout.split()
513
514         col = split.column()
515         col.prop(mat, "diffuse_color", text="Viewport Color")
516
517         col = split.column()
518         col.prop(cmat, "sample_as_light")
519
520 class CyclesTexture_PT_context(CyclesButtonsPanel, Panel):
521     bl_label = ""
522     bl_context = "texture"
523     bl_options = {'HIDE_HEADER'}
524     COMPAT_ENGINES = {'CYCLES'}
525
526     def draw(self, context):
527         layout = self.layout
528
529         tex = context.texture
530         space = context.space_data
531         pin_id = space.pin_id
532         use_pin_id = space.use_pin_id;
533         user = context.texture_user
534         node = context.texture_node
535
536         if not use_pin_id or not isinstance(pin_id, bpy.types.Texture):
537             pin_id = None
538
539         if not pin_id:
540             layout.template_texture_user()
541
542         if user:
543             layout.separator()
544
545             split = layout.split(percentage=0.65)
546             col = split.column()
547
548             if pin_id:
549                 col.template_ID(space, "pin_id")
550             elif user:
551                 col.template_ID(user, "texture", new="texture.new")
552             
553             if tex:
554                 row = split.row()
555                 row.prop(tex, "use_nodes", icon="NODETREE", text="")
556                 row.label()
557
558                 if not tex.use_nodes:
559                     split = layout.split(percentage=0.2)
560                     split.label(text="Type:")
561                     split.prop(tex, "type", text="")
562
563 class CyclesTexture_PT_nodes(CyclesButtonsPanel, Panel):
564     bl_label = "Nodes"
565     bl_context = "texture"
566
567     @classmethod
568     def poll(cls, context):
569         tex = context.texture
570         return (tex and tex.use_nodes) and CyclesButtonsPanel.poll(context)
571
572     def draw(self, context):
573         layout = self.layout
574
575         tex = context.texture
576         panel_node_draw(layout, tex, 'OUTPUT_TEXTURE', 'Color')
577
578 class CyclesTexture_PT_node(CyclesButtonsPanel, Panel):
579     bl_label = "Node"
580     bl_context = "texture"
581
582     @classmethod
583     def poll(cls, context):
584         node = context.texture_node
585         return node and CyclesButtonsPanel.poll(context)
586
587     def draw(self, context):
588         layout = self.layout
589
590         node = context.texture_node
591         ntree = node.id_data
592         layout.template_node_view(ntree, node, None)
593
594 class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
595     bl_label = "Mapping"
596     bl_context = "texture"
597
598     @classmethod
599     def poll(cls, context):
600         tex = context.texture
601         node = context.texture_node
602         return (node or (tex and tex.use_nodes)) and CyclesButtonsPanel.poll(context)
603
604     def draw(self, context):
605         layout = self.layout
606         layout.label("Texture coordinate mapping goes here.");
607         layout.label("Translate, rotate, scale, projection, XYZ.")
608
609 class CyclesTexture_PT_color(CyclesButtonsPanel, Panel):
610     bl_label = "Color"
611     bl_context = "texture"
612
613     @classmethod
614     def poll(cls, context):
615         tex = context.texture
616         node = context.texture_node
617         return (node or (tex and tex.use_nodes)) and CyclesButtonsPanel.poll(context)
618
619     def draw(self, context):
620         layout = self.layout
621         layout.label("Color modification options go here.");
622         layout.label("Ramp, brightness, contrast, saturation.")
623
624 def draw_device(self, context):
625     scene = context.scene
626     layout = self.layout
627
628     if scene.render.engine == "CYCLES":
629         cscene = scene.cycles
630
631         available_devices = engine.available_devices()
632         available_cuda = 'cuda' in available_devices
633         available_opencl = 'opencl' in available_devices
634
635         if available_cuda or available_opencl:
636             layout.prop(cscene, "device")
637             if cscene.device == 'GPU' and available_cuda and available_opencl:
638                 layout.prop(cscene, "gpu_type")
639         if cscene.device == 'CPU' and engine.with_osl():
640             layout.prop(cscene, "shading_system")
641
642 def draw_pause(self, context):
643     layout = self.layout
644     scene = context.scene
645
646     if scene.render.engine == "CYCLES":
647         view = context.space_data
648
649         if view.viewport_shade == "RENDERED":
650             cscene = scene.cycles
651             layout.prop(cscene, "preview_pause", icon="PAUSE", text="")
652
653 def get_panels():
654     return [
655         bpy.types.RENDER_PT_render,
656         bpy.types.RENDER_PT_output,
657         bpy.types.RENDER_PT_encoding,
658         bpy.types.RENDER_PT_dimensions,
659         bpy.types.RENDER_PT_stamp,
660         bpy.types.WORLD_PT_context_world,
661         bpy.types.DATA_PT_context_mesh,
662         bpy.types.DATA_PT_context_camera,
663         bpy.types.DATA_PT_context_lamp,
664         bpy.types.DATA_PT_texture_space,
665         bpy.types.DATA_PT_curve_texture_space,
666         bpy.types.DATA_PT_mball_texture_space,
667         bpy.types.DATA_PT_vertex_groups,
668         bpy.types.DATA_PT_shape_keys,
669         bpy.types.DATA_PT_uv_texture,
670         bpy.types.DATA_PT_vertex_colors,
671         bpy.types.DATA_PT_camera,
672         bpy.types.DATA_PT_camera_display,
673         bpy.types.DATA_PT_custom_props_mesh,
674         bpy.types.DATA_PT_custom_props_camera,
675         bpy.types.DATA_PT_custom_props_lamp,
676         bpy.types.TEXTURE_PT_clouds,
677         bpy.types.TEXTURE_PT_wood,
678         bpy.types.TEXTURE_PT_marble,
679         bpy.types.TEXTURE_PT_magic,
680         bpy.types.TEXTURE_PT_blend,
681         bpy.types.TEXTURE_PT_stucci,
682         bpy.types.TEXTURE_PT_image,
683         bpy.types.TEXTURE_PT_image_sampling,
684         bpy.types.TEXTURE_PT_image_mapping,
685         bpy.types.TEXTURE_PT_musgrave,
686         bpy.types.TEXTURE_PT_voronoi,
687         bpy.types.TEXTURE_PT_distortednoise,
688         bpy.types.TEXTURE_PT_voxeldata,
689         bpy.types.TEXTURE_PT_pointdensity,
690         bpy.types.TEXTURE_PT_pointdensity_turbulence]
691
692 def register():
693     bpy.types.RENDER_PT_render.append(draw_device)
694     bpy.types.VIEW3D_HT_header.append(draw_pause)
695
696     for panel in get_panels():
697         panel.COMPAT_ENGINES.add('CYCLES')
698     
699 def unregister():
700     bpy.types.RENDER_PT_render.remove(draw_device)
701     bpy.types.VIEW3D_HT_header.remove(draw_pause)
702
703     for panel in get_panels():
704         panel.COMPAT_ENGINES.remove('CYCLES')
705