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