Implement Start Resolution for preview render in BI
[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.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_border or 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.prop(rd, "use_free_unused_nodes")
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 = "Stamp"
338     bl_options = {'DEFAULT_CLOSED'}
339     COMPAT_ENGINES = {'BLENDER_RENDER'}
340
341     def draw_header(self, context):
342         rd = context.scene.render
343
344         self.layout.prop(rd, "use_stamp", text="")
345
346     def draw(self, context):
347         layout = self.layout
348
349         rd = context.scene.render
350
351         layout.active = rd.use_stamp
352
353         layout.prop(rd, "stamp_font_size", text="Font Size")
354
355         row = layout.row()
356         row.column().prop(rd, "stamp_foreground", slider=True)
357         row.column().prop(rd, "stamp_background", slider=True)
358
359         split = layout.split()
360
361         col = split.column()
362         col.prop(rd, "use_stamp_time", text="Time")
363         col.prop(rd, "use_stamp_date", text="Date")
364         col.prop(rd, "use_stamp_render_time", text="RenderTime")
365         col.prop(rd, "use_stamp_frame", text="Frame")
366         col.prop(rd, "use_stamp_scene", text="Scene")
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
381
382 class RENDER_PT_output(RenderButtonsPanel, Panel):
383     bl_label = "Output"
384     COMPAT_ENGINES = {'BLENDER_RENDER'}
385
386     def draw(self, context):
387         layout = self.layout
388
389         rd = context.scene.render
390         image_settings = rd.image_settings
391         file_format = image_settings.file_format
392
393         layout.prop(rd, "filepath", text="")
394
395         split = layout.split()
396
397         col = split.column()
398         col.active = not rd.is_movie_format
399         col.prop(rd, "use_overwrite")
400         col.prop(rd, "use_placeholder")
401
402         col = split.column()
403         col.prop(rd, "use_file_extension")
404         col.prop(rd, "use_render_cache")
405
406         layout.template_image_settings(image_settings, color_management=False)
407
408         if file_format == 'QUICKTIME':
409             quicktime = rd.quicktime
410
411             split = layout.split()
412             col = split.column()
413             col.prop(quicktime, "codec_type", text="Video Codec")
414             col.prop(quicktime, "codec_spatial_quality", text="Quality")
415
416             # Audio
417             col.prop(quicktime, "audiocodec_type", text="Audio Codec")
418             if quicktime.audiocodec_type != 'No audio':
419                 split = layout.split()
420                 if quicktime.audiocodec_type == 'LPCM':
421                     split.prop(quicktime, "audio_bitdepth", text="")
422
423                 split.prop(quicktime, "audio_samplerate", text="")
424
425                 split = layout.split()
426                 col = split.column()
427                 if quicktime.audiocodec_type == 'AAC':
428                     col.prop(quicktime, "audio_bitrate")
429
430                 subsplit = split.split()
431                 col = subsplit.column()
432
433                 if quicktime.audiocodec_type == 'AAC':
434                     col.prop(quicktime, "audio_codec_isvbr")
435
436                 col = subsplit.column()
437                 col.prop(quicktime, "audio_resampling_hq")
438
439
440 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
441     bl_label = "Encoding"
442     bl_options = {'DEFAULT_CLOSED'}
443     COMPAT_ENGINES = {'BLENDER_RENDER'}
444
445     @classmethod
446     def poll(cls, context):
447         rd = context.scene.render
448         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
449
450     def draw(self, context):
451         layout = self.layout
452
453         rd = context.scene.render
454         ffmpeg = rd.ffmpeg
455
456         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
457
458         split = layout.split()
459         split.prop(rd.ffmpeg, "format")
460         if ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG'}:
461             split.prop(ffmpeg, "codec")
462         elif rd.ffmpeg.format == 'H264':
463             split.prop(ffmpeg, "use_lossless_output")
464         else:
465             split.label()
466
467         row = layout.row()
468         row.prop(ffmpeg, "video_bitrate")
469         row.prop(ffmpeg, "gopsize")
470
471         split = layout.split()
472
473         col = split.column()
474         col.label(text="Rate:")
475         col.prop(ffmpeg, "minrate", text="Minimum")
476         col.prop(ffmpeg, "maxrate", text="Maximum")
477         col.prop(ffmpeg, "buffersize", text="Buffer")
478
479         col = split.column()
480         col.prop(ffmpeg, "use_autosplit")
481         col.label(text="Mux:")
482         col.prop(ffmpeg, "muxrate", text="Rate")
483         col.prop(ffmpeg, "packetsize", text="Packet Size")
484
485         layout.separator()
486
487         # Audio:
488         if ffmpeg.format != 'MP3':
489             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
490
491         row = layout.row()
492         row.prop(ffmpeg, "audio_bitrate")
493         row.prop(ffmpeg, "audio_volume", slider=True)
494
495
496 class RENDER_PT_bake(RenderButtonsPanel, Panel):
497     bl_label = "Bake"
498     bl_options = {'DEFAULT_CLOSED'}
499     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
500
501     def draw(self, context):
502         layout = self.layout
503
504         rd = context.scene.render
505
506         layout.operator("object.bake_image", icon='RENDER_STILL')
507
508         layout.prop(rd, "bake_type")
509
510         multires_bake = False
511         if rd.bake_type in ['NORMALS', 'DISPLACEMENT', 'DERIVATIVE', 'AO']:
512             layout.prop(rd, "use_bake_multires")
513             multires_bake = rd.use_bake_multires
514
515         if not multires_bake:
516             if rd.bake_type == 'NORMALS':
517                 layout.prop(rd, "bake_normal_space")
518             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
519                 layout.prop(rd, "use_bake_normalize")
520
521             # col.prop(rd, "bake_aa_mode")
522             # col.prop(rd, "use_bake_antialiasing")
523
524             layout.separator()
525
526             split = layout.split()
527
528             col = split.column()
529             col.prop(rd, "use_bake_to_vertex_color")
530             sub = col.column()
531             sub.active = not rd.use_bake_to_vertex_color
532             sub.prop(rd, "use_bake_clear")
533             sub.prop(rd, "bake_margin")
534             sub.prop(rd, "bake_quad_split", text="Split")
535
536             col = split.column()
537             col.prop(rd, "use_bake_selected_to_active")
538             sub = col.column()
539             sub.active = rd.use_bake_selected_to_active
540             sub.prop(rd, "bake_distance")
541             sub.prop(rd, "bake_bias")
542         else:
543             split = layout.split()
544
545             col = split.column()
546             col.prop(rd, "use_bake_clear")
547             col.prop(rd, "bake_margin")
548
549             if rd.bake_type == 'DISPLACEMENT':
550                 col = split.column()
551                 col.prop(rd, "use_bake_lores_mesh")
552
553             if rd.bake_type == 'AO':
554                 col = split.column()
555                 col.prop(rd, "bake_bias")
556                 col.prop(rd, "bake_samples")
557
558         if rd.bake_type == 'DERIVATIVE':
559             row = layout.row()
560             row.prop(rd, "use_bake_user_scale", text="")
561
562             sub = row.column()
563             sub.active = rd.use_bake_user_scale
564             sub.prop(rd, "bake_user_scale", text="User Scale")
565
566
567 if __name__ == "__main__":  # only for live edit.
568     bpy.utils.register_module(__name__)