Merged changes in the trunk up to revision 54110.
[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
47 class RenderButtonsPanel():
48     bl_space_type = 'PROPERTIES'
49     bl_region_type = 'WINDOW'
50     bl_context = "render"
51     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
52
53     @classmethod
54     def poll(cls, context):
55         scene = context.scene
56         return scene and (scene.render.engine in cls.COMPAT_ENGINES)
57
58
59 class RenderFreestyleButtonsPanel(RenderButtonsPanel):
60     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
61
62     @classmethod
63     def poll(cls, context):
64         if not super().poll(context):
65             return False
66         return bpy.app.build_options.freestyle
67
68
69 class RENDER_PT_render(RenderButtonsPanel, Panel):
70     bl_label = "Render"
71     COMPAT_ENGINES = {'BLENDER_RENDER'}
72
73     def draw(self, context):
74         layout = self.layout
75
76         rd = context.scene.render
77
78         row = layout.row(align=True)
79         row.operator("render.render", text="Render", icon='RENDER_STILL')
80         row.operator("render.render", text="Animation", icon='RENDER_ANIMATION').animation = True
81         row.operator("render.play_rendered_anim", text="Play", icon='PLAY')
82
83         layout.prop(rd, "display_mode", text="Display")
84
85
86 class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
87     bl_label = "Dimensions"
88     COMPAT_ENGINES = {'BLENDER_RENDER'}
89
90     def draw(self, context):
91         layout = self.layout
92
93         scene = context.scene
94         rd = scene.render
95
96         row = layout.row(align=True)
97         row.menu("RENDER_MT_presets", text=bpy.types.RENDER_MT_presets.bl_label)
98         row.operator("render.preset_add", text="", icon='ZOOMIN')
99         row.operator("render.preset_add", text="", icon='ZOOMOUT').remove_active = True
100
101         split = layout.split()
102
103         col = split.column()
104         sub = col.column(align=True)
105         sub.label(text="Resolution:")
106         sub.prop(rd, "resolution_x", text="X")
107         sub.prop(rd, "resolution_y", text="Y")
108         sub.prop(rd, "resolution_percentage", text="")
109
110         sub.label(text="Aspect Ratio:")
111         sub.prop(rd, "pixel_aspect_x", text="X")
112         sub.prop(rd, "pixel_aspect_y", text="Y")
113
114         row = col.row()
115         row.prop(rd, "use_border", text="Border")
116         sub = row.row()
117         sub.active = rd.use_border
118         sub.prop(rd, "use_crop_to_border", text="Crop")
119
120         col = split.column()
121         sub = col.column(align=True)
122         sub.label(text="Frame Range:")
123         sub.prop(scene, "frame_start")
124         sub.prop(scene, "frame_end")
125         sub.prop(scene, "frame_step")
126
127         sub.label(text="Frame Rate:")
128         if rd.fps_base == 1:
129             fps_rate = round(rd.fps / rd.fps_base)
130         else:
131             fps_rate = round(rd.fps / rd.fps_base, 2)
132
133         # TODO: Change the following to iterate over existing presets
134         custom_framerate = (fps_rate not in {23.98, 24, 25, 29.97, 30, 50, 59.94, 60})
135
136         if custom_framerate is True:
137             fps_label_text = "Custom (" + str(fps_rate) + " fps)"
138         else:
139             fps_label_text = str(fps_rate) + " fps"
140
141         sub.menu("RENDER_MT_framerate_presets", text=fps_label_text)
142
143         if custom_framerate or (bpy.types.RENDER_MT_framerate_presets.bl_label == "Custom"):
144             sub.prop(rd, "fps")
145             sub.prop(rd, "fps_base", text="/")
146         subrow = sub.row(align=True)
147         subrow.label(text="Time Remapping:")
148         subrow = sub.row(align=True)
149         subrow.prop(rd, "frame_map_old", text="Old")
150         subrow.prop(rd, "frame_map_new", text="New")
151
152
153 class RENDER_PT_antialiasing(RenderButtonsPanel, Panel):
154     bl_label = "Anti-Aliasing"
155     COMPAT_ENGINES = {'BLENDER_RENDER'}
156
157     def draw_header(self, context):
158         rd = context.scene.render
159
160         self.layout.prop(rd, "use_antialiasing", text="")
161
162     def draw(self, context):
163         layout = self.layout
164
165         rd = context.scene.render
166         layout.active = rd.use_antialiasing
167
168         split = layout.split()
169
170         col = split.column()
171         col.row().prop(rd, "antialiasing_samples", expand=True)
172         sub = col.row()
173         sub.enabled = not rd.use_border
174         sub.prop(rd, "use_full_sample")
175
176         col = split.column()
177         col.prop(rd, "pixel_filter_type", text="")
178         col.prop(rd, "filter_size", text="Size")
179
180
181 class RENDER_PT_motion_blur(RenderButtonsPanel, Panel):
182     bl_label = "Sampled Motion Blur"
183     bl_options = {'DEFAULT_CLOSED'}
184     COMPAT_ENGINES = {'BLENDER_RENDER'}
185
186     @classmethod
187     def poll(cls, context):
188         rd = context.scene.render
189         return not rd.use_full_sample and (rd.engine in cls.COMPAT_ENGINES)
190
191     def draw_header(self, context):
192         rd = context.scene.render
193
194         self.layout.prop(rd, "use_motion_blur", text="")
195
196     def draw(self, context):
197         layout = self.layout
198
199         rd = context.scene.render
200         layout.active = rd.use_motion_blur
201
202         row = layout.row()
203         row.prop(rd, "motion_blur_samples")
204         row.prop(rd, "motion_blur_shutter")
205
206
207 class RENDER_PT_shading(RenderButtonsPanel, Panel):
208     bl_label = "Shading"
209     bl_options = {'DEFAULT_CLOSED'}
210     COMPAT_ENGINES = {'BLENDER_RENDER'}
211
212     def draw(self, context):
213         layout = self.layout
214
215         rd = context.scene.render
216
217         split = layout.split()
218
219         col = split.column()
220         col.prop(rd, "use_textures", text="Textures")
221         col.prop(rd, "use_shadows", text="Shadows")
222         col.prop(rd, "use_sss", text="Subsurface Scattering")
223         col.prop(rd, "use_envmaps", text="Environment Map")
224
225         col = split.column()
226         col.prop(rd, "use_raytrace", text="Ray Tracing")
227         col.prop(rd, "alpha_mode", text="Alpha")
228
229
230 class RENDER_PT_performance(RenderButtonsPanel, Panel):
231     bl_label = "Performance"
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         sub = col.column(align=True)
244         sub.label(text="Threads:")
245         sub.row().prop(rd, "threads_mode", expand=True)
246         subsub = sub.column()
247         subsub.enabled = rd.threads_mode == 'FIXED'
248         subsub.prop(rd, "threads")
249
250         sub = col.column(align=True)
251         sub.label(text="Tile Size:")
252         sub.prop(rd, "tile_x", text="X")
253         sub.prop(rd, "tile_y", text="Y")
254
255         col = split.column()
256         col.label(text="Memory:")
257         sub = col.column()
258         sub.enabled = not (rd.use_border or rd.use_full_sample)
259         sub.prop(rd, "use_save_buffers")
260         sub = col.column()
261         sub.active = rd.use_compositing
262         sub.prop(rd, "use_free_image_textures")
263         sub.prop(rd, "use_free_unused_nodes")
264         sub = col.column()
265         sub.active = rd.use_raytrace
266         sub.label(text="Acceleration structure:")
267         sub.prop(rd, "raytrace_method", text="")
268         if rd.raytrace_method == 'OCTREE':
269             sub.prop(rd, "octree_resolution", text="Resolution")
270         else:
271             sub.prop(rd, "use_instances", text="Instances")
272         sub.prop(rd, "use_local_coords", text="Local Coordinates")
273
274
275 class RENDER_PT_post_processing(RenderButtonsPanel, Panel):
276     bl_label = "Post Processing"
277     bl_options = {'DEFAULT_CLOSED'}
278     COMPAT_ENGINES = {'BLENDER_RENDER'}
279
280     def draw(self, context):
281         layout = self.layout
282
283         rd = context.scene.render
284
285         split = layout.split()
286
287         col = split.column()
288         col.prop(rd, "use_compositing")
289         col.prop(rd, "use_sequencer")
290
291         split.prop(rd, "dither_intensity", text="Dither", slider=True)
292
293         layout.separator()
294
295         split = layout.split()
296
297         col = split.column()
298         col.prop(rd, "use_fields", text="Fields")
299         sub = col.column()
300         sub.active = rd.use_fields
301         sub.row().prop(rd, "field_order", expand=True)
302         sub.prop(rd, "use_fields_still", text="Still")
303
304         col = split.column()
305         col.prop(rd, "use_edge_enhance")
306         sub = col.column()
307         sub.active = rd.use_edge_enhance
308         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
309         sub.prop(rd, "edge_color", text="")
310
311
312 class RENDER_PT_freestyle(RenderFreestyleButtonsPanel, Panel):
313     bl_label = "Freestyle"
314     bl_options = {'DEFAULT_CLOSED'}
315     COMPAT_ENGINES = {'BLENDER_RENDER'}
316
317     def draw_header(self, context):
318         rd = context.scene.render
319         self.layout.prop(rd, "use_freestyle", text="")
320
321     def draw(self, context):
322         rd = context.scene.render
323
324         layout = self.layout
325         layout.active = rd.use_freestyle
326
327         row = layout.row()
328         row.label(text="Line Thickness:")
329         row.prop(rd, "line_thickness_mode", expand=True)
330         row = layout.row()
331         row.active = (rd.line_thickness_mode == 'ABSOLUTE')
332         row.prop(rd, "unit_line_thickness")
333
334
335 class RENDER_PT_stamp(RenderButtonsPanel, Panel):
336     bl_label = "Stamp"
337     bl_options = {'DEFAULT_CLOSED'}
338     COMPAT_ENGINES = {'BLENDER_RENDER'}
339
340     def draw_header(self, context):
341         rd = context.scene.render
342
343         self.layout.prop(rd, "use_stamp", text="")
344
345     def draw(self, context):
346         layout = self.layout
347
348         rd = context.scene.render
349
350         layout.active = rd.use_stamp
351
352         layout.prop(rd, "stamp_font_size", text="Font Size")
353
354         row = layout.row()
355         row.column().prop(rd, "stamp_foreground", slider=True)
356         row.column().prop(rd, "stamp_background", slider=True)
357
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
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
380
381 class RENDER_PT_output(RenderButtonsPanel, Panel):
382     bl_label = "Output"
383     COMPAT_ENGINES = {'BLENDER_RENDER'}
384
385     def draw(self, context):
386         layout = self.layout
387
388         rd = context.scene.render
389         image_settings = rd.image_settings
390         file_format = image_settings.file_format
391
392         layout.prop(rd, "filepath", text="")
393
394         flow = layout.column_flow()
395         flow.prop(rd, "use_overwrite")
396         flow.prop(rd, "use_placeholder")
397         flow.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__)