Fix T53276: encoding output quality UI clarification.
[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         col.prop(rd, "preview_pixel_size", text="")
279
280         col = split.column()
281         col.label(text="Memory:")
282         sub = col.column()
283         sub.enabled = not rd.use_full_sample
284         sub.prop(rd, "use_save_buffers")
285         sub = col.column()
286         sub.active = rd.use_compositing
287         sub.prop(rd, "use_free_image_textures")
288         sub = col.column()
289         sub.active = rd.use_raytrace
290         sub.label(text="Acceleration Structure:")
291         sub.prop(rd, "raytrace_method", text="")
292         if rd.raytrace_method == 'OCTREE':
293             sub.prop(rd, "octree_resolution", text="Resolution")
294         else:
295             sub.prop(rd, "use_instances", text="Instances")
296         sub.prop(rd, "use_local_coords", text="Local Coordinates")
297
298
299 class RENDER_PT_post_processing(RenderButtonsPanel, Panel):
300     bl_label = "Post Processing"
301     bl_options = {'DEFAULT_CLOSED'}
302     COMPAT_ENGINES = {'BLENDER_RENDER'}
303
304     def draw(self, context):
305         layout = self.layout
306
307         rd = context.scene.render
308
309         split = layout.split()
310
311         col = split.column()
312         col.prop(rd, "use_compositing")
313         col.prop(rd, "use_sequencer")
314
315         split.prop(rd, "dither_intensity", text="Dither", slider=True)
316
317         layout.separator()
318
319         split = layout.split()
320
321         col = split.column()
322         col.prop(rd, "use_fields", text="Fields")
323         sub = col.column()
324         sub.active = rd.use_fields
325         sub.row().prop(rd, "field_order", expand=True)
326         sub.prop(rd, "use_fields_still", text="Still")
327
328         col = split.column()
329         col.prop(rd, "use_edge_enhance")
330         sub = col.column()
331         sub.active = rd.use_edge_enhance
332         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
333         sub.prop(rd, "edge_color", text="")
334
335
336 class RENDER_PT_stamp(RenderButtonsPanel, Panel):
337     bl_label = "Metadata"
338     bl_options = {'DEFAULT_CLOSED'}
339     COMPAT_ENGINES = {'BLENDER_RENDER'}
340
341     def draw(self, context):
342         layout = self.layout
343
344         rd = context.scene.render
345
346         layout.prop(rd, "use_stamp")
347         col = layout.column()
348         col.active = rd.use_stamp
349         row = col.row()
350         row.prop(rd, "stamp_font_size", text="Font Size")
351         row.prop(rd, "use_stamp_labels", text="Draw Labels")
352
353         row = col.row()
354         row.column().prop(rd, "stamp_foreground", slider=True)
355         row.column().prop(rd, "stamp_background", slider=True)
356
357         layout.label("Enabled Metadata")
358         split = layout.split()
359
360         col = split.column()
361         col.prop(rd, "use_stamp_time", text="Time")
362         col.prop(rd, "use_stamp_date", text="Date")
363         col.prop(rd, "use_stamp_render_time", text="RenderTime")
364         col.prop(rd, "use_stamp_frame", text="Frame")
365         col.prop(rd, "use_stamp_scene", text="Scene")
366         col.prop(rd, "use_stamp_memory", text="Memory")
367
368         col = split.column()
369         col.prop(rd, "use_stamp_camera", text="Camera")
370         col.prop(rd, "use_stamp_lens", text="Lens")
371         col.prop(rd, "use_stamp_filename", text="Filename")
372         col.prop(rd, "use_stamp_marker", text="Marker")
373         col.prop(rd, "use_stamp_sequencer_strip", text="Seq. Strip")
374
375         row = layout.split(percentage=0.2)
376         row.prop(rd, "use_stamp_note", text="Note")
377         sub = row.row()
378         sub.active = rd.use_stamp_note
379         sub.prop(rd, "stamp_note_text", text="")
380         if rd.use_sequencer:
381             layout.label("Sequencer:")
382             layout.prop(rd, "use_stamp_strip_meta")
383
384
385 class RENDER_PT_output(RenderButtonsPanel, Panel):
386     bl_label = "Output"
387     COMPAT_ENGINES = {'BLENDER_RENDER'}
388
389     def draw(self, context):
390         layout = self.layout
391
392         rd = context.scene.render
393         image_settings = rd.image_settings
394         file_format = image_settings.file_format
395
396         layout.prop(rd, "filepath", text="")
397
398         split = layout.split()
399
400         col = split.column()
401         col.active = not rd.is_movie_format
402         col.prop(rd, "use_overwrite")
403         col.prop(rd, "use_placeholder")
404
405         col = split.column()
406         col.prop(rd, "use_file_extension")
407         col.prop(rd, "use_render_cache")
408
409         layout.template_image_settings(image_settings, color_management=False)
410         if rd.use_multiview:
411             layout.template_image_views(image_settings)
412
413
414 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
415     bl_label = "Encoding"
416     bl_options = {'DEFAULT_CLOSED'}
417     COMPAT_ENGINES = {'BLENDER_RENDER'}
418
419     @classmethod
420     def poll(cls, context):
421         rd = context.scene.render
422         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
423
424     def draw(self, context):
425         layout = self.layout
426
427         rd = context.scene.render
428         ffmpeg = rd.ffmpeg
429
430         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
431
432         split = layout.split()
433         split.prop(rd.ffmpeg, "format")
434         split.prop(ffmpeg, "use_autosplit")
435
436         layout.separator()
437
438         needs_codec = ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG', 'MPEG4'}
439         if needs_codec:
440             layout.prop(ffmpeg, "codec")
441
442         if ffmpeg.codec in {'DNXHD'}:
443             layout.prop(ffmpeg, "use_lossless_output")
444
445         # Output quality
446         if needs_codec and ffmpeg.codec in {'H264', 'MPEG4'}:
447             layout.prop(ffmpeg, "constant_rate_factor")
448
449         # Encoding speed
450         layout.prop(ffmpeg, "ffmpeg_preset")
451         # I-frames
452         layout.prop(ffmpeg, "gopsize")
453         # B-Frames
454         row = layout.row()
455         row.prop(ffmpeg, "use_max_b_frames", text="Max B-frames")
456         pbox = row.split()
457         pbox.prop(ffmpeg, "max_b_frames", text="")
458         pbox.enabled = ffmpeg.use_max_b_frames
459
460         if ffmpeg.constant_rate_factor == 'NONE':
461             split = layout.split()
462             col = split.column()
463             col.label(text="Rate:")
464             col.prop(ffmpeg, "video_bitrate")
465             col.prop(ffmpeg, "minrate", text="Minimum")
466             col.prop(ffmpeg, "maxrate", text="Maximum")
467             col.prop(ffmpeg, "buffersize", text="Buffer")
468
469             col = split.column()
470             col.label(text="Mux:")
471             col.prop(ffmpeg, "muxrate", text="Rate")
472             col.prop(ffmpeg, "packetsize", text="Packet Size")
473
474         layout.separator()
475
476         # Audio:
477         if ffmpeg.format != 'MP3':
478             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
479
480         if ffmpeg.audio_codec != 'NONE':
481             row = layout.row()
482             row.prop(ffmpeg, "audio_bitrate")
483             row.prop(ffmpeg, "audio_volume", slider=True)
484
485
486 class RENDER_PT_bake(RenderButtonsPanel, Panel):
487     bl_label = "Bake"
488     bl_options = {'DEFAULT_CLOSED'}
489     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
490
491     def draw(self, context):
492         layout = self.layout
493
494         rd = context.scene.render
495
496         layout.operator("object.bake_image", icon='RENDER_STILL')
497
498         layout.prop(rd, "bake_type")
499
500         multires_bake = False
501         if rd.bake_type in ['NORMALS', 'DISPLACEMENT', 'DERIVATIVE', 'AO']:
502             layout.prop(rd, "use_bake_multires")
503             multires_bake = rd.use_bake_multires
504
505         if not multires_bake:
506             if rd.bake_type == 'NORMALS':
507                 layout.prop(rd, "bake_normal_space")
508             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
509                 layout.prop(rd, "use_bake_normalize")
510
511             # col.prop(rd, "bake_aa_mode")
512             # col.prop(rd, "use_bake_antialiasing")
513
514             layout.separator()
515
516             split = layout.split()
517
518             col = split.column()
519             col.prop(rd, "use_bake_to_vertex_color")
520             sub = col.column()
521             sub.active = not rd.use_bake_to_vertex_color
522             sub.prop(rd, "use_bake_clear")
523             sub.prop(rd, "bake_margin")
524             sub.prop(rd, "bake_quad_split", text="Split")
525
526             col = split.column()
527             col.prop(rd, "use_bake_selected_to_active")
528             sub = col.column()
529             sub.active = rd.use_bake_selected_to_active
530             sub.prop(rd, "bake_distance")
531             sub.prop(rd, "bake_bias")
532         else:
533             split = layout.split()
534
535             col = split.column()
536             col.prop(rd, "use_bake_clear")
537             col.prop(rd, "bake_margin")
538
539             if rd.bake_type == 'DISPLACEMENT':
540                 col = split.column()
541                 col.prop(rd, "use_bake_lores_mesh")
542
543             if rd.bake_type == 'AO':
544                 col = split.column()
545                 col.prop(rd, "bake_bias")
546                 col.prop(rd, "bake_samples")
547
548         if rd.bake_type == 'DERIVATIVE':
549             row = layout.row()
550             row.prop(rd, "use_bake_user_scale", text="")
551
552             sub = row.column()
553             sub.active = rd.use_bake_user_scale
554             sub.prop(rd, "bake_user_scale", text="User Scale")
555
556
557 classes = (
558     RENDER_MT_presets,
559     RENDER_MT_ffmpeg_presets,
560     RENDER_MT_framerate_presets,
561     RENDER_PT_render,
562     RENDER_PT_dimensions,
563     RENDER_PT_antialiasing,
564     RENDER_PT_motion_blur,
565     RENDER_PT_shading,
566     RENDER_PT_performance,
567     RENDER_PT_post_processing,
568     RENDER_PT_stamp,
569     RENDER_PT_output,
570     RENDER_PT_encoding,
571     RENDER_PT_bake,
572 )
573
574 if __name__ == "__main__":  # only for live edit.
575     from bpy.utils import register_class
576     for cls in classes:
577         register_class(cls)