42cb6086c35da5bd1c26b13cf8c23ce05b653a3f
[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 = "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.enabled = not rd.use_border
197         sub.prop(rd, "use_full_sample")
198
199         col = split.column()
200         col.prop(rd, "pixel_filter_type", text="")
201         col.prop(rd, "filter_size", text="Size")
202
203
204 class RENDER_PT_motion_blur(RenderButtonsPanel, Panel):
205     bl_label = "Sampled Motion Blur"
206     bl_options = {'DEFAULT_CLOSED'}
207     COMPAT_ENGINES = {'BLENDER_RENDER'}
208
209     @classmethod
210     def poll(cls, context):
211         rd = context.scene.render
212         return not rd.use_full_sample and (rd.engine in cls.COMPAT_ENGINES)
213
214     def draw_header(self, context):
215         rd = context.scene.render
216
217         self.layout.prop(rd, "use_motion_blur", text="")
218
219     def draw(self, context):
220         layout = self.layout
221
222         rd = context.scene.render
223         layout.active = rd.use_motion_blur
224
225         row = layout.row()
226         row.prop(rd, "motion_blur_samples")
227         row.prop(rd, "motion_blur_shutter")
228
229
230 class RENDER_PT_shading(RenderButtonsPanel, Panel):
231     bl_label = "Shading"
232     bl_options = {'DEFAULT_CLOSED'}
233     COMPAT_ENGINES = {'BLENDER_RENDER'}
234
235     def draw(self, context):
236         layout = self.layout
237
238         rd = context.scene.render
239
240         split = layout.split()
241
242         col = split.column()
243         col.prop(rd, "use_textures", text="Textures")
244         col.prop(rd, "use_shadows", text="Shadows")
245         col.prop(rd, "use_sss", text="Subsurface Scattering")
246         col.prop(rd, "use_envmaps", text="Environment Map")
247
248         col = split.column()
249         col.prop(rd, "use_raytrace", text="Ray Tracing")
250         col.prop(rd, "alpha_mode", text="Alpha")
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 = split.column()
277         col.label(text="Memory:")
278         sub = col.column()
279         sub.enabled = not (rd.use_border or rd.use_full_sample)
280         sub.prop(rd, "use_save_buffers")
281         sub = col.column()
282         sub.active = rd.use_compositing
283         sub.prop(rd, "use_free_image_textures")
284         sub.prop(rd, "use_free_unused_nodes")
285         sub = col.column()
286         sub.active = rd.use_raytrace
287         sub.label(text="Acceleration structure:")
288         sub.prop(rd, "raytrace_method", text="")
289         if rd.raytrace_method == 'OCTREE':
290             sub.prop(rd, "octree_resolution", text="Resolution")
291         else:
292             sub.prop(rd, "use_instances", text="Instances")
293         sub.prop(rd, "use_local_coords", text="Local Coordinates")
294
295
296 class RENDER_PT_post_processing(RenderButtonsPanel, Panel):
297     bl_label = "Post Processing"
298     bl_options = {'DEFAULT_CLOSED'}
299     COMPAT_ENGINES = {'BLENDER_RENDER'}
300
301     def draw(self, context):
302         layout = self.layout
303
304         rd = context.scene.render
305
306         split = layout.split()
307
308         col = split.column()
309         col.prop(rd, "use_compositing")
310         col.prop(rd, "use_sequencer")
311
312         split.prop(rd, "dither_intensity", text="Dither", slider=True)
313
314         layout.separator()
315
316         split = layout.split()
317
318         col = split.column()
319         col.prop(rd, "use_fields", text="Fields")
320         sub = col.column()
321         sub.active = rd.use_fields
322         sub.row().prop(rd, "field_order", expand=True)
323         sub.prop(rd, "use_fields_still", text="Still")
324
325         col = split.column()
326         col.prop(rd, "use_edge_enhance")
327         sub = col.column()
328         sub.active = rd.use_edge_enhance
329         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
330         sub.prop(rd, "edge_color", text="")
331
332
333 class RENDER_PT_stamp(RenderButtonsPanel, Panel):
334     bl_label = "Stamp"
335     bl_options = {'DEFAULT_CLOSED'}
336     COMPAT_ENGINES = {'BLENDER_RENDER'}
337
338     def draw_header(self, context):
339         rd = context.scene.render
340
341         self.layout.prop(rd, "use_stamp", text="")
342
343     def draw(self, context):
344         layout = self.layout
345
346         rd = context.scene.render
347
348         layout.active = rd.use_stamp
349
350         layout.prop(rd, "stamp_font_size", text="Font Size")
351
352         row = layout.row()
353         row.column().prop(rd, "stamp_foreground", slider=True)
354         row.column().prop(rd, "stamp_background", slider=True)
355
356         split = layout.split()
357
358         col = split.column()
359         col.prop(rd, "use_stamp_time", text="Time")
360         col.prop(rd, "use_stamp_date", text="Date")
361         col.prop(rd, "use_stamp_render_time", text="RenderTime")
362         col.prop(rd, "use_stamp_frame", text="Frame")
363         col.prop(rd, "use_stamp_scene", text="Scene")
364
365         col = split.column()
366         col.prop(rd, "use_stamp_camera", text="Camera")
367         col.prop(rd, "use_stamp_lens", text="Lens")
368         col.prop(rd, "use_stamp_filename", text="Filename")
369         col.prop(rd, "use_stamp_marker", text="Marker")
370         col.prop(rd, "use_stamp_sequencer_strip", text="Seq. Strip")
371
372         row = layout.split(percentage=0.2)
373         row.prop(rd, "use_stamp_note", text="Note")
374         sub = row.row()
375         sub.active = rd.use_stamp_note
376         sub.prop(rd, "stamp_note_text", text="")
377
378
379 class RENDER_PT_output(RenderButtonsPanel, Panel):
380     bl_label = "Output"
381     COMPAT_ENGINES = {'BLENDER_RENDER'}
382
383     def draw(self, context):
384         layout = self.layout
385
386         rd = context.scene.render
387         image_settings = rd.image_settings
388         file_format = image_settings.file_format
389
390         layout.prop(rd, "filepath", text="")
391
392         split = layout.split()
393
394         col = split.column()
395         col.active = not rd.is_movie_format
396         col.prop(rd, "use_overwrite")
397         col.prop(rd, "use_placeholder")
398
399         col = split.column()
400         col.prop(rd, "use_file_extension")
401         col.prop(rd, "use_render_cache")
402
403         layout.template_image_settings(image_settings, color_management=False)
404
405         if file_format == 'QUICKTIME':
406             quicktime = rd.quicktime
407
408             split = layout.split()
409             col = split.column()
410             col.prop(quicktime, "codec_type", text="Video Codec")
411             col.prop(quicktime, "codec_spatial_quality", text="Quality")
412
413             # Audio
414             col.prop(quicktime, "audiocodec_type", text="Audio Codec")
415             if quicktime.audiocodec_type != 'No audio':
416                 split = layout.split()
417                 if quicktime.audiocodec_type == 'LPCM':
418                     split.prop(quicktime, "audio_bitdepth", text="")
419
420                 split.prop(quicktime, "audio_samplerate", text="")
421
422                 split = layout.split()
423                 col = split.column()
424                 if quicktime.audiocodec_type == 'AAC':
425                     col.prop(quicktime, "audio_bitrate")
426
427                 subsplit = split.split()
428                 col = subsplit.column()
429
430                 if quicktime.audiocodec_type == 'AAC':
431                     col.prop(quicktime, "audio_codec_isvbr")
432
433                 col = subsplit.column()
434                 col.prop(quicktime, "audio_resampling_hq")
435
436
437 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
438     bl_label = "Encoding"
439     bl_options = {'DEFAULT_CLOSED'}
440     COMPAT_ENGINES = {'BLENDER_RENDER'}
441
442     @classmethod
443     def poll(cls, context):
444         rd = context.scene.render
445         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
446
447     def draw(self, context):
448         layout = self.layout
449
450         rd = context.scene.render
451         ffmpeg = rd.ffmpeg
452
453         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
454
455         split = layout.split()
456         split.prop(rd.ffmpeg, "format")
457         if ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG'}:
458             split.prop(ffmpeg, "codec")
459         elif rd.ffmpeg.format == 'H264':
460             split.prop(ffmpeg, "use_lossless_output")
461         else:
462             split.label()
463
464         row = layout.row()
465         row.prop(ffmpeg, "video_bitrate")
466         row.prop(ffmpeg, "gopsize")
467
468         split = layout.split()
469
470         col = split.column()
471         col.label(text="Rate:")
472         col.prop(ffmpeg, "minrate", text="Minimum")
473         col.prop(ffmpeg, "maxrate", text="Maximum")
474         col.prop(ffmpeg, "buffersize", text="Buffer")
475
476         col = split.column()
477         col.prop(ffmpeg, "use_autosplit")
478         col.label(text="Mux:")
479         col.prop(ffmpeg, "muxrate", text="Rate")
480         col.prop(ffmpeg, "packetsize", text="Packet Size")
481
482         layout.separator()
483
484         # Audio:
485         if ffmpeg.format != 'MP3':
486             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
487
488         row = layout.row()
489         row.prop(ffmpeg, "audio_bitrate")
490         row.prop(ffmpeg, "audio_volume", slider=True)
491
492
493 class RENDER_PT_bake(RenderButtonsPanel, Panel):
494     bl_label = "Bake"
495     bl_options = {'DEFAULT_CLOSED'}
496     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
497
498     def draw(self, context):
499         layout = self.layout
500
501         rd = context.scene.render
502
503         layout.operator("object.bake_image", icon='RENDER_STILL')
504
505         layout.prop(rd, "bake_type")
506
507         multires_bake = False
508         if rd.bake_type in ['NORMALS', 'DISPLACEMENT', 'DERIVATIVE', 'AO']:
509             layout.prop(rd, "use_bake_multires")
510             multires_bake = rd.use_bake_multires
511
512         if not multires_bake:
513             if rd.bake_type == 'NORMALS':
514                 layout.prop(rd, "bake_normal_space")
515             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
516                 layout.prop(rd, "use_bake_normalize")
517
518             # col.prop(rd, "bake_aa_mode")
519             # col.prop(rd, "use_bake_antialiasing")
520
521             layout.separator()
522
523             split = layout.split()
524
525             col = split.column()
526             col.prop(rd, "use_bake_to_vertex_color")
527             sub = col.column()
528             sub.active = not rd.use_bake_to_vertex_color
529             sub.prop(rd, "use_bake_clear")
530             sub.prop(rd, "bake_margin")
531             sub.prop(rd, "bake_quad_split", text="Split")
532
533             col = split.column()
534             col.prop(rd, "use_bake_selected_to_active")
535             sub = col.column()
536             sub.active = rd.use_bake_selected_to_active
537             sub.prop(rd, "bake_distance")
538             sub.prop(rd, "bake_bias")
539         else:
540             split = layout.split()
541
542             col = split.column()
543             col.prop(rd, "use_bake_clear")
544             col.prop(rd, "bake_margin")
545
546             if rd.bake_type == 'DISPLACEMENT':
547                 col = split.column()
548                 col.prop(rd, "use_bake_lores_mesh")
549
550             if rd.bake_type == 'AO':
551                 col = split.column()
552                 col.prop(rd, "bake_bias")
553                 col.prop(rd, "bake_samples")
554
555         if rd.bake_type == 'DERIVATIVE':
556             row = layout.row()
557             row.prop(rd, "use_bake_user_scale", text="")
558
559             sub = row.column()
560             sub.active = rd.use_bake_user_scale
561             sub.prop(rd, "bake_user_scale", text="User Scale")
562
563
564 if __name__ == "__main__":  # only for live edit.
565     bpy.utils.register_module(__name__)