bd5d926d4cdd2b8a3bd0831108508a320c597d9e
[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("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 = f"Custom ({fps_rate!r} fps)"
105             show_framerate = True
106         else:
107             fps_label_text = f"{fps_rate!r} fps"
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_frame_range", text="Frame range")
373         col.prop(rd, "use_stamp_marker", text="Marker")
374         col.prop(rd, "use_stamp_sequencer_strip", text="Seq. Strip")
375
376         row = layout.split(percentage=0.2)
377         row.prop(rd, "use_stamp_note", text="Note")
378         sub = row.row()
379         sub.active = rd.use_stamp_note
380         sub.prop(rd, "stamp_note_text", text="")
381         if rd.use_sequencer:
382             layout.label("Sequencer:")
383             layout.prop(rd, "use_stamp_strip_meta")
384
385
386 class RENDER_PT_output(RenderButtonsPanel, Panel):
387     bl_label = "Output"
388     COMPAT_ENGINES = {'BLENDER_RENDER'}
389
390     def draw(self, context):
391         layout = self.layout
392
393         rd = context.scene.render
394         image_settings = rd.image_settings
395         file_format = image_settings.file_format
396
397         layout.prop(rd, "filepath", text="")
398
399         split = layout.split()
400
401         col = split.column()
402         col.active = not rd.is_movie_format
403         col.prop(rd, "use_overwrite")
404         col.prop(rd, "use_placeholder")
405
406         col = split.column()
407         col.prop(rd, "use_file_extension")
408         col.prop(rd, "use_render_cache")
409
410         layout.template_image_settings(image_settings, color_management=False)
411         if rd.use_multiview:
412             layout.template_image_views(image_settings)
413
414
415 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
416     bl_label = "Encoding"
417     bl_options = {'DEFAULT_CLOSED'}
418     COMPAT_ENGINES = {'BLENDER_RENDER'}
419
420     @classmethod
421     def poll(cls, context):
422         rd = context.scene.render
423         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
424
425     def draw(self, context):
426         layout = self.layout
427
428         rd = context.scene.render
429         ffmpeg = rd.ffmpeg
430
431         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
432
433         split = layout.split()
434         split.prop(rd.ffmpeg, "format")
435         split.prop(ffmpeg, "use_autosplit")
436
437         # Video:
438         layout.separator()
439         self.draw_vcodec(context)
440
441         # Audio:
442         layout.separator()
443         if ffmpeg.format != 'MP3':
444             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
445
446         if ffmpeg.audio_codec != 'NONE':
447             row = layout.row()
448             row.prop(ffmpeg, "audio_bitrate")
449             row.prop(ffmpeg, "audio_volume", slider=True)
450
451     def draw_vcodec(self, context):
452         """Video codec options."""
453         layout = self.layout
454         ffmpeg = context.scene.render.ffmpeg
455
456         needs_codec = ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG', 'MPEG4'}
457         if needs_codec:
458             layout.prop(ffmpeg, "codec")
459
460         if needs_codec and ffmpeg.codec == 'NONE':
461             return
462
463         if ffmpeg.codec in {'DNXHD'}:
464             layout.prop(ffmpeg, "use_lossless_output")
465
466         # Output quality
467         use_crf = needs_codec and ffmpeg.codec in {'H264', 'MPEG4', 'WEBM'}
468         if use_crf:
469             layout.prop(ffmpeg, "constant_rate_factor")
470
471         # Encoding speed
472         layout.prop(ffmpeg, "ffmpeg_preset")
473         # I-frames
474         layout.prop(ffmpeg, "gopsize")
475         # B-Frames
476         row = layout.row()
477         row.prop(ffmpeg, "use_max_b_frames", text="Max B-frames")
478         pbox = row.split()
479         pbox.prop(ffmpeg, "max_b_frames", text="")
480         pbox.enabled = ffmpeg.use_max_b_frames
481
482         if not use_crf or ffmpeg.constant_rate_factor == 'NONE':
483             split = layout.split()
484             col = split.column()
485             col.label(text="Rate:")
486             col.prop(ffmpeg, "video_bitrate")
487             col.prop(ffmpeg, "minrate", text="Minimum")
488             col.prop(ffmpeg, "maxrate", text="Maximum")
489             col.prop(ffmpeg, "buffersize", text="Buffer")
490
491             col = split.column()
492             col.label(text="Mux:")
493             col.prop(ffmpeg, "muxrate", text="Rate")
494             col.prop(ffmpeg, "packetsize", text="Packet Size")
495
496
497 class RENDER_PT_bake(RenderButtonsPanel, Panel):
498     bl_label = "Bake"
499     bl_options = {'DEFAULT_CLOSED'}
500     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
501
502     def draw(self, context):
503         layout = self.layout
504
505         rd = context.scene.render
506
507         layout.operator("object.bake_image", icon='RENDER_STILL')
508
509         layout.prop(rd, "bake_type")
510
511         multires_bake = False
512         if rd.bake_type in ['NORMALS', 'DISPLACEMENT', 'DERIVATIVE', 'AO']:
513             layout.prop(rd, "use_bake_multires")
514             multires_bake = rd.use_bake_multires
515
516         if not multires_bake:
517             if rd.bake_type == 'NORMALS':
518                 layout.prop(rd, "bake_normal_space")
519             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
520                 layout.prop(rd, "use_bake_normalize")
521
522             # col.prop(rd, "bake_aa_mode")
523             # col.prop(rd, "use_bake_antialiasing")
524
525             layout.separator()
526
527             split = layout.split()
528
529             col = split.column()
530             col.prop(rd, "use_bake_to_vertex_color")
531             sub = col.column()
532             sub.active = not rd.use_bake_to_vertex_color
533             sub.prop(rd, "use_bake_clear")
534             sub.prop(rd, "bake_margin")
535             sub.prop(rd, "bake_quad_split", text="Split")
536
537             col = split.column()
538             col.prop(rd, "use_bake_selected_to_active")
539             sub = col.column()
540             sub.active = rd.use_bake_selected_to_active
541             sub.prop(rd, "bake_distance")
542             sub.prop(rd, "bake_bias")
543         else:
544             split = layout.split()
545
546             col = split.column()
547             col.prop(rd, "use_bake_clear")
548             col.prop(rd, "bake_margin")
549
550             if rd.bake_type == 'DISPLACEMENT':
551                 col = split.column()
552                 col.prop(rd, "use_bake_lores_mesh")
553
554             if rd.bake_type == 'AO':
555                 col = split.column()
556                 col.prop(rd, "bake_bias")
557                 col.prop(rd, "bake_samples")
558
559         if rd.bake_type == 'DERIVATIVE':
560             row = layout.row()
561             row.prop(rd, "use_bake_user_scale", text="")
562
563             sub = row.column()
564             sub.active = rd.use_bake_user_scale
565             sub.prop(rd, "bake_user_scale", text="User Scale")
566
567
568 classes = (
569     RENDER_MT_presets,
570     RENDER_MT_ffmpeg_presets,
571     RENDER_MT_framerate_presets,
572     RENDER_PT_render,
573     RENDER_PT_dimensions,
574     RENDER_PT_antialiasing,
575     RENDER_PT_motion_blur,
576     RENDER_PT_shading,
577     RENDER_PT_performance,
578     RENDER_PT_post_processing,
579     RENDER_PT_stamp,
580     RENDER_PT_output,
581     RENDER_PT_encoding,
582     RENDER_PT_bake,
583 )
584
585 if __name__ == "__main__":  # only for live edit.
586     from bpy.utils import register_class
587     for cls in classes:
588         register_class(cls)