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