Merging r57729 through r57815 from trunk into soc-2013-depsgraph_mt
[blender.git] / release / scripts / startup / bl_ui / properties_render.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2
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 # ##### END GPL LICENSE BLOCK #####
19
20 # <pep8 compliant>
21 import bpy
22 from bpy.types import Menu, Panel
23
24
25 class RENDER_MT_presets(Menu):
26     bl_label = "Render Presets"
27     preset_subdir = "render"
28     preset_operator = "script.execute_preset"
29     draw = Menu.draw_preset
30
31
32 class RENDER_MT_ffmpeg_presets(Menu):
33     bl_label = "FFMPEG Presets"
34     preset_subdir = "ffmpeg"
35     preset_operator = "script.python_file_run"
36     draw = Menu.draw_preset
37
38
39 class RENDER_MT_framerate_presets(Menu):
40     bl_label = "Frame Rate Presets"
41     preset_subdir = "framerate"
42     preset_operator = "script.execute_preset"
43     draw = Menu.draw_preset
44
45
46 class RenderButtonsPanel():
47     bl_space_type = 'PROPERTIES'
48     bl_region_type = 'WINDOW'
49     bl_context = "render"
50     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
51
52     @classmethod
53     def poll(cls, context):
54         scene = context.scene
55         return scene and (scene.render.engine in cls.COMPAT_ENGINES)
56
57
58 class RENDER_PT_render(RenderButtonsPanel, Panel):
59     bl_label = "Render"
60     COMPAT_ENGINES = {'BLENDER_RENDER'}
61
62     def draw(self, context):
63         layout = self.layout
64
65         rd = context.scene.render
66
67         row = layout.row(align=True)
68         row.operator("render.render", text="Render", icon='RENDER_STILL')
69         row.operator("render.render", text="Animation", icon='RENDER_ANIMATION').animation = True
70         row.operator("render.play_rendered_anim", text="Play", icon='PLAY')
71
72         layout.prop(rd, "display_mode", text="Display")
73         layout.prop(rd, "use_lock_interface")
74
75
76 class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
77     bl_label = "Dimensions"
78     COMPAT_ENGINES = {'BLENDER_RENDER'}
79
80     _frame_rate_args_prev = None
81     _preset_class = None
82
83     @staticmethod
84     def _draw_framerate_label(*args):
85         # avoids re-creating text string each draw
86         if RENDER_PT_dimensions._frame_rate_args_prev == args:
87             return RENDER_PT_dimensions._frame_rate_ret
88
89         fps, fps_base, preset_label = args
90
91         if fps_base == 1.0:
92             fps_rate = round(fps)
93         else:
94             fps_rate = round(fps / fps_base, 2)
95
96         # TODO: Change the following to iterate over existing presets
97         custom_framerate = (fps_rate not in {23.98, 24, 25, 29.97, 30, 50, 59.94, 60})
98
99         if custom_framerate is True:
100             fps_label_text = "Custom (%r fps)" % fps_rate
101             show_framerate = True
102         else:
103             fps_label_text = "%r fps" % fps_rate
104             show_framerate = (preset_label == "Custom")
105
106         RENDER_PT_dimensions._frame_rate_args_prev = args
107         RENDER_PT_dimensions._frame_rate_ret = args = (fps_label_text, show_framerate)
108         return args
109
110     @staticmethod
111     def draw_framerate(sub, rd):
112         if RENDER_PT_dimensions._preset_class is None:
113             RENDER_PT_dimensions._preset_class = bpy.types.RENDER_MT_framerate_presets
114
115         args = rd.fps, rd.fps_base, RENDER_PT_dimensions._preset_class.bl_label
116         fps_label_text, show_framerate = RENDER_PT_dimensions._draw_framerate_label(*args)
117
118         sub.menu("RENDER_MT_framerate_presets", text=fps_label_text)
119
120         if show_framerate:
121             sub.prop(rd, "fps")
122             sub.prop(rd, "fps_base", text="/")
123
124     def draw(self, context):
125         layout = self.layout
126
127         scene = context.scene
128         rd = scene.render
129
130         row = layout.row(align=True)
131         row.menu("RENDER_MT_presets", text=bpy.types.RENDER_MT_presets.bl_label)
132         row.operator("render.preset_add", text="", icon='ZOOMIN')
133         row.operator("render.preset_add", text="", icon='ZOOMOUT').remove_active = True
134
135         split = layout.split()
136
137         col = split.column()
138         sub = col.column(align=True)
139         sub.label(text="Resolution:")
140         sub.prop(rd, "resolution_x", text="X")
141         sub.prop(rd, "resolution_y", text="Y")
142         sub.prop(rd, "resolution_percentage", text="")
143
144         sub.label(text="Aspect Ratio:")
145         sub.prop(rd, "pixel_aspect_x", text="X")
146         sub.prop(rd, "pixel_aspect_y", text="Y")
147
148         row = col.row()
149         row.prop(rd, "use_border", text="Border")
150         sub = row.row()
151         sub.active = rd.use_border
152         sub.prop(rd, "use_crop_to_border", text="Crop")
153
154         col = split.column()
155         sub = col.column(align=True)
156         sub.label(text="Frame Range:")
157         sub.prop(scene, "frame_start")
158         sub.prop(scene, "frame_end")
159         sub.prop(scene, "frame_step")
160
161         sub.label(text="Frame Rate:")
162
163         self.draw_framerate(sub, rd)
164
165         subrow = sub.row(align=True)
166         subrow.label(text="Time Remapping:")
167         subrow = sub.row(align=True)
168         subrow.prop(rd, "frame_map_old", text="Old")
169         subrow.prop(rd, "frame_map_new", text="New")
170
171
172 class RENDER_PT_antialiasing(RenderButtonsPanel, Panel):
173     bl_label = "Anti-Aliasing"
174     COMPAT_ENGINES = {'BLENDER_RENDER'}
175
176     def draw_header(self, context):
177         rd = context.scene.render
178
179         self.layout.prop(rd, "use_antialiasing", text="")
180
181     def draw(self, context):
182         layout = self.layout
183
184         rd = context.scene.render
185         layout.active = rd.use_antialiasing
186
187         split = layout.split()
188
189         col = split.column()
190         col.row().prop(rd, "antialiasing_samples", expand=True)
191         sub = col.row()
192         sub.enabled = not rd.use_border
193         sub.prop(rd, "use_full_sample")
194
195         col = split.column()
196         col.prop(rd, "pixel_filter_type", text="")
197         col.prop(rd, "filter_size", text="Size")
198
199
200 class RENDER_PT_motion_blur(RenderButtonsPanel, Panel):
201     bl_label = "Sampled Motion Blur"
202     bl_options = {'DEFAULT_CLOSED'}
203     COMPAT_ENGINES = {'BLENDER_RENDER'}
204
205     @classmethod
206     def poll(cls, context):
207         rd = context.scene.render
208         return not rd.use_full_sample and (rd.engine in cls.COMPAT_ENGINES)
209
210     def draw_header(self, context):
211         rd = context.scene.render
212
213         self.layout.prop(rd, "use_motion_blur", text="")
214
215     def draw(self, context):
216         layout = self.layout
217
218         rd = context.scene.render
219         layout.active = rd.use_motion_blur
220
221         row = layout.row()
222         row.prop(rd, "motion_blur_samples")
223         row.prop(rd, "motion_blur_shutter")
224
225
226 class RENDER_PT_shading(RenderButtonsPanel, Panel):
227     bl_label = "Shading"
228     bl_options = {'DEFAULT_CLOSED'}
229     COMPAT_ENGINES = {'BLENDER_RENDER'}
230
231     def draw(self, context):
232         layout = self.layout
233
234         rd = context.scene.render
235
236         split = layout.split()
237
238         col = split.column()
239         col.prop(rd, "use_textures", text="Textures")
240         col.prop(rd, "use_shadows", text="Shadows")
241         col.prop(rd, "use_sss", text="Subsurface Scattering")
242         col.prop(rd, "use_envmaps", text="Environment Map")
243
244         col = split.column()
245         col.prop(rd, "use_raytrace", text="Ray Tracing")
246         col.prop(rd, "alpha_mode", text="Alpha")
247
248
249 class RENDER_PT_performance(RenderButtonsPanel, Panel):
250     bl_label = "Performance"
251     bl_options = {'DEFAULT_CLOSED'}
252     COMPAT_ENGINES = {'BLENDER_RENDER'}
253
254     def draw(self, context):
255         layout = self.layout
256
257         rd = context.scene.render
258
259         split = layout.split()
260
261         col = split.column()
262         sub = col.column(align=True)
263         sub.label(text="Threads:")
264         sub.row().prop(rd, "threads_mode", expand=True)
265         subsub = sub.column()
266         subsub.enabled = rd.threads_mode == 'FIXED'
267         subsub.prop(rd, "threads")
268
269         sub = col.column(align=True)
270         sub.label(text="Tile Size:")
271         sub.prop(rd, "tile_x", text="X")
272         sub.prop(rd, "tile_y", text="Y")
273
274         col = split.column()
275         col.label(text="Memory:")
276         sub = col.column()
277         sub.enabled = not (rd.use_border or rd.use_full_sample)
278         sub.prop(rd, "use_save_buffers")
279         sub = col.column()
280         sub.active = rd.use_compositing
281         sub.prop(rd, "use_free_image_textures")
282         sub.prop(rd, "use_free_unused_nodes")
283         sub = col.column()
284         sub.active = rd.use_raytrace
285         sub.label(text="Acceleration structure:")
286         sub.prop(rd, "raytrace_method", text="")
287         if rd.raytrace_method == 'OCTREE':
288             sub.prop(rd, "octree_resolution", text="Resolution")
289         else:
290             sub.prop(rd, "use_instances", text="Instances")
291         sub.prop(rd, "use_local_coords", text="Local Coordinates")
292
293
294 class RENDER_PT_post_processing(RenderButtonsPanel, Panel):
295     bl_label = "Post Processing"
296     bl_options = {'DEFAULT_CLOSED'}
297     COMPAT_ENGINES = {'BLENDER_RENDER'}
298
299     def draw(self, context):
300         layout = self.layout
301
302         rd = context.scene.render
303
304         split = layout.split()
305
306         col = split.column()
307         col.prop(rd, "use_compositing")
308         col.prop(rd, "use_sequencer")
309
310         split.prop(rd, "dither_intensity", text="Dither", slider=True)
311
312         layout.separator()
313
314         split = layout.split()
315
316         col = split.column()
317         col.prop(rd, "use_fields", text="Fields")
318         sub = col.column()
319         sub.active = rd.use_fields
320         sub.row().prop(rd, "field_order", expand=True)
321         sub.prop(rd, "use_fields_still", text="Still")
322
323         col = split.column()
324         col.prop(rd, "use_edge_enhance")
325         sub = col.column()
326         sub.active = rd.use_edge_enhance
327         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
328         sub.prop(rd, "edge_color", text="")
329
330
331 class RENDER_PT_stamp(RenderButtonsPanel, Panel):
332     bl_label = "Stamp"
333     bl_options = {'DEFAULT_CLOSED'}
334     COMPAT_ENGINES = {'BLENDER_RENDER'}
335
336     def draw_header(self, context):
337         rd = context.scene.render
338
339         self.layout.prop(rd, "use_stamp", text="")
340
341     def draw(self, context):
342         layout = self.layout
343
344         rd = context.scene.render
345
346         layout.active = rd.use_stamp
347
348         layout.prop(rd, "stamp_font_size", text="Font Size")
349
350         row = layout.row()
351         row.column().prop(rd, "stamp_foreground", slider=True)
352         row.column().prop(rd, "stamp_background", slider=True)
353
354         split = layout.split()
355
356         col = split.column()
357         col.prop(rd, "use_stamp_time", text="Time")
358         col.prop(rd, "use_stamp_date", text="Date")
359         col.prop(rd, "use_stamp_render_time", text="RenderTime")
360         col.prop(rd, "use_stamp_frame", text="Frame")
361         col.prop(rd, "use_stamp_scene", text="Scene")
362
363         col = split.column()
364         col.prop(rd, "use_stamp_camera", text="Camera")
365         col.prop(rd, "use_stamp_lens", text="Lens")
366         col.prop(rd, "use_stamp_filename", text="Filename")
367         col.prop(rd, "use_stamp_marker", text="Marker")
368         col.prop(rd, "use_stamp_sequencer_strip", text="Seq. Strip")
369
370         row = layout.split(percentage=0.2)
371         row.prop(rd, "use_stamp_note", text="Note")
372         sub = row.row()
373         sub.active = rd.use_stamp_note
374         sub.prop(rd, "stamp_note_text", text="")
375
376
377 class RENDER_PT_output(RenderButtonsPanel, Panel):
378     bl_label = "Output"
379     COMPAT_ENGINES = {'BLENDER_RENDER'}
380
381     def draw(self, context):
382         layout = self.layout
383
384         rd = context.scene.render
385         image_settings = rd.image_settings
386         file_format = image_settings.file_format
387
388         layout.prop(rd, "filepath", text="")
389
390         split = layout.split()
391
392         col = split.column()
393         col.active = not rd.is_movie_format
394         col.prop(rd, "use_overwrite")
395         col.prop(rd, "use_placeholder")
396
397         split.prop(rd, "use_file_extension")
398
399         layout.template_image_settings(image_settings, color_management=False)
400
401         if file_format == 'QUICKTIME_CARBON':
402             layout.operator("scene.render_data_set_quicktime_codec")
403
404         elif file_format == 'QUICKTIME_QTKIT':
405             quicktime = rd.quicktime
406
407             split = layout.split()
408             col = split.column()
409             col.prop(quicktime, "codec_type", text="Video Codec")
410             col.prop(quicktime, "codec_spatial_quality", text="Quality")
411
412             # Audio
413             col.prop(quicktime, "audiocodec_type", text="Audio Codec")
414             if quicktime.audiocodec_type != 'No audio':
415                 split = layout.split()
416                 if quicktime.audiocodec_type == 'LPCM':
417                     split.prop(quicktime, "audio_bitdepth", text="")
418
419                 split.prop(quicktime, "audio_samplerate", text="")
420
421                 split = layout.split()
422                 col = split.column()
423                 if quicktime.audiocodec_type == 'AAC':
424                     col.prop(quicktime, "audio_bitrate")
425
426                 subsplit = split.split()
427                 col = subsplit.column()
428
429                 if quicktime.audiocodec_type == 'AAC':
430                     col.prop(quicktime, "audio_codec_isvbr")
431
432                 col = subsplit.column()
433                 col.prop(quicktime, "audio_resampling_hq")
434
435
436 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
437     bl_label = "Encoding"
438     bl_options = {'DEFAULT_CLOSED'}
439     COMPAT_ENGINES = {'BLENDER_RENDER'}
440
441     @classmethod
442     def poll(cls, context):
443         rd = context.scene.render
444         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
445
446     def draw(self, context):
447         layout = self.layout
448
449         rd = context.scene.render
450         ffmpeg = rd.ffmpeg
451
452         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
453
454         split = layout.split()
455         split.prop(rd.ffmpeg, "format")
456         if ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG'}:
457             split.prop(ffmpeg, "codec")
458         elif rd.ffmpeg.format == 'H264':
459             split.prop(ffmpeg, "use_lossless_output")
460         else:
461             split.label()
462
463         row = layout.row()
464         row.prop(ffmpeg, "video_bitrate")
465         row.prop(ffmpeg, "gopsize")
466
467         split = layout.split()
468
469         col = split.column()
470         col.label(text="Rate:")
471         col.prop(ffmpeg, "minrate", text="Minimum")
472         col.prop(ffmpeg, "maxrate", text="Maximum")
473         col.prop(ffmpeg, "buffersize", text="Buffer")
474
475         col = split.column()
476         col.prop(ffmpeg, "use_autosplit")
477         col.label(text="Mux:")
478         col.prop(ffmpeg, "muxrate", text="Rate")
479         col.prop(ffmpeg, "packetsize", text="Packet Size")
480
481         layout.separator()
482
483         # Audio:
484         if ffmpeg.format != 'MP3':
485             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
486
487         row = layout.row()
488         row.prop(ffmpeg, "audio_bitrate")
489         row.prop(ffmpeg, "audio_volume", slider=True)
490
491
492 class RENDER_PT_bake(RenderButtonsPanel, Panel):
493     bl_label = "Bake"
494     bl_options = {'DEFAULT_CLOSED'}
495     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
496
497     def draw(self, context):
498         layout = self.layout
499
500         rd = context.scene.render
501
502         layout.operator("object.bake_image", icon='RENDER_STILL')
503
504         layout.prop(rd, "bake_type")
505
506         multires_bake = False
507         if rd.bake_type in ['NORMALS', 'DISPLACEMENT', 'AO']:
508             layout.prop(rd, "use_bake_multires")
509             multires_bake = rd.use_bake_multires
510
511         if not multires_bake:
512             if rd.bake_type == 'NORMALS':
513                 layout.prop(rd, "bake_normal_space")
514             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
515                 layout.prop(rd, "use_bake_normalize")
516
517             # col.prop(rd, "bake_aa_mode")
518             # col.prop(rd, "use_bake_antialiasing")
519
520             layout.separator()
521
522             split = layout.split()
523
524             col = split.column()
525             col.prop(rd, "use_bake_to_vertex_color")
526             sub = col.column()
527             sub.active = not rd.use_bake_to_vertex_color
528             sub.prop(rd, "use_bake_clear")
529             sub.prop(rd, "bake_margin")
530             sub.prop(rd, "bake_quad_split", text="Split")
531
532             col = split.column()
533             col.prop(rd, "use_bake_selected_to_active")
534             sub = col.column()
535             sub.active = rd.use_bake_selected_to_active
536             sub.prop(rd, "bake_distance")
537             sub.prop(rd, "bake_bias")
538         else:
539             split = layout.split()
540
541             col = split.column()
542             col.prop(rd, "use_bake_clear")
543             col.prop(rd, "bake_margin")
544
545             if rd.bake_type == 'DISPLACEMENT':
546                 col = split.column()
547                 col.prop(rd, "use_bake_lores_mesh")
548             if rd.bake_type == 'AO':
549                 col = split.column()
550                 col.prop(rd, "bake_bias")
551                 col.prop(rd, "bake_samples")
552
553
554 if __name__ == "__main__":  # only for live edit.
555     bpy.utils.register_module(__name__)