Merged changes in the trunk up to revision 51853.
[blender-staging.git] / release / scripts / startup / bl_ui / properties_render.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Menu, Panel
22
23
24 class RENDER_MT_presets(Menu):
25     bl_label = "Render Presets"
26     preset_subdir = "render"
27     preset_operator = "script.execute_preset"
28     draw = Menu.draw_preset
29
30
31 class RENDER_MT_ffmpeg_presets(Menu):
32     bl_label = "FFMPEG Presets"
33     preset_subdir = "ffmpeg"
34     preset_operator = "script.python_file_run"
35     draw = Menu.draw_preset
36
37
38 class RENDER_MT_framerate_presets(Menu):
39     bl_label = "Frame Rate Presets"
40     preset_subdir = "framerate"
41     preset_operator = "script.execute_preset"
42     draw = Menu.draw_preset
43
44
45 class RenderButtonsPanel():
46     bl_space_type = 'PROPERTIES'
47     bl_region_type = 'WINDOW'
48     bl_context = "render"
49     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
50
51     @classmethod
52     def poll(cls, context):
53         rd = context.scene.render
54         return context.scene and (rd.engine in cls.COMPAT_ENGINES)
55
56
57 class RENDER_PT_render(RenderButtonsPanel, Panel):
58     bl_label = "Render"
59     COMPAT_ENGINES = {'BLENDER_RENDER'}
60
61     def draw(self, context):
62         layout = self.layout
63
64         rd = context.scene.render
65
66         row = layout.row(align=True)
67         row.operator("render.render", text="Render", icon='RENDER_STILL')
68         row.operator("render.render", text="Animation", icon='RENDER_ANIMATION').animation = True
69         row.operator("render.play_rendered_anim", text="Play", icon='PLAY')
70
71         layout.prop(rd, "display_mode", text="Display")
72
73
74 class RENDER_PT_dimensions(RenderButtonsPanel, Panel):
75     bl_label = "Dimensions"
76     COMPAT_ENGINES = {'BLENDER_RENDER'}
77
78     def draw(self, context):
79         layout = self.layout
80
81         scene = context.scene
82         rd = scene.render
83
84         row = layout.row(align=True)
85         row.menu("RENDER_MT_presets", text=bpy.types.RENDER_MT_presets.bl_label)
86         row.operator("render.preset_add", text="", icon='ZOOMIN')
87         row.operator("render.preset_add", text="", icon='ZOOMOUT').remove_active = True
88
89         split = layout.split()
90
91         col = split.column()
92         sub = col.column(align=True)
93         sub.label(text="Resolution:")
94         sub.prop(rd, "resolution_x", text="X")
95         sub.prop(rd, "resolution_y", text="Y")
96         sub.prop(rd, "resolution_percentage", text="")
97
98         sub.label(text="Aspect Ratio:")
99         sub.prop(rd, "pixel_aspect_x", text="X")
100         sub.prop(rd, "pixel_aspect_y", text="Y")
101
102         row = col.row()
103         row.prop(rd, "use_border", text="Border")
104         sub = row.row()
105         sub.active = rd.use_border
106         sub.prop(rd, "use_crop_to_border", text="Crop")
107
108         col = split.column()
109         sub = col.column(align=True)
110         sub.label(text="Frame Range:")
111         sub.prop(scene, "frame_start")
112         sub.prop(scene, "frame_end")
113         sub.prop(scene, "frame_step")
114
115         sub.label(text="Frame Rate:")
116         if rd.fps_base == 1:
117             fps_rate = round(rd.fps / rd.fps_base)
118         else:
119             fps_rate = round(rd.fps / rd.fps_base, 2)
120
121         # TODO: Change the following to iterate over existing presets
122         custom_framerate = (fps_rate not in {23.98, 24, 25, 29.97, 30, 50, 59.94, 60})
123
124         if custom_framerate is True:
125             fps_label_text = "Custom (" + str(fps_rate) + " fps)"
126         else:
127             fps_label_text = str(fps_rate) + " fps"
128
129         sub.menu("RENDER_MT_framerate_presets", text=fps_label_text)
130
131         if custom_framerate or (bpy.types.RENDER_MT_framerate_presets.bl_label == "Custom"):
132             sub.prop(rd, "fps")
133             sub.prop(rd, "fps_base", text="/")
134         subrow = sub.row(align=True)
135         subrow.label(text="Time Remapping:")
136         subrow = sub.row(align=True)
137         subrow.prop(rd, "frame_map_old", text="Old")
138         subrow.prop(rd, "frame_map_new", text="New")
139
140
141 class RENDER_PT_antialiasing(RenderButtonsPanel, Panel):
142     bl_label = "Anti-Aliasing"
143     COMPAT_ENGINES = {'BLENDER_RENDER'}
144
145     def draw_header(self, context):
146         rd = context.scene.render
147
148         self.layout.prop(rd, "use_antialiasing", text="")
149
150     def draw(self, context):
151         layout = self.layout
152
153         rd = context.scene.render
154         layout.active = rd.use_antialiasing
155
156         split = layout.split()
157
158         col = split.column()
159         col.row().prop(rd, "antialiasing_samples", expand=True)
160         sub = col.row()
161         sub.enabled = not rd.use_border
162         sub.prop(rd, "use_full_sample")
163
164         col = split.column()
165         col.prop(rd, "pixel_filter_type", text="")
166         col.prop(rd, "filter_size", text="Size")
167
168
169 class RENDER_PT_motion_blur(RenderButtonsPanel, Panel):
170     bl_label = "Sampled Motion Blur"
171     bl_options = {'DEFAULT_CLOSED'}
172     COMPAT_ENGINES = {'BLENDER_RENDER'}
173
174     @classmethod
175     def poll(cls, context):
176         rd = context.scene.render
177         return not rd.use_full_sample and (rd.engine in cls.COMPAT_ENGINES)
178
179     def draw_header(self, context):
180         rd = context.scene.render
181
182         self.layout.prop(rd, "use_motion_blur", text="")
183
184     def draw(self, context):
185         layout = self.layout
186
187         rd = context.scene.render
188         layout.active = rd.use_motion_blur
189
190         row = layout.row()
191         row.prop(rd, "motion_blur_samples")
192         row.prop(rd, "motion_blur_shutter")
193
194
195 class RENDER_PT_shading(RenderButtonsPanel, Panel):
196     bl_label = "Shading"
197     bl_options = {'DEFAULT_CLOSED'}
198     COMPAT_ENGINES = {'BLENDER_RENDER'}
199
200     def draw(self, context):
201         layout = self.layout
202
203         rd = context.scene.render
204
205         split = layout.split()
206
207         col = split.column()
208         col.prop(rd, "use_textures", text="Textures")
209         col.prop(rd, "use_shadows", text="Shadows")
210         col.prop(rd, "use_sss", text="Subsurface Scattering")
211         col.prop(rd, "use_envmaps", text="Environment Map")
212
213         col = split.column()
214         col.prop(rd, "use_raytrace", text="Ray Tracing")
215         col.prop(rd, "alpha_mode", text="Alpha")
216
217
218 class RENDER_PT_performance(RenderButtonsPanel, Panel):
219     bl_label = "Performance"
220     bl_options = {'DEFAULT_CLOSED'}
221     COMPAT_ENGINES = {'BLENDER_RENDER'}
222
223     def draw(self, context):
224         layout = self.layout
225
226         rd = context.scene.render
227
228         split = layout.split()
229
230         col = split.column()
231         sub = col.column(align=True)
232         sub.label(text="Threads:")
233         sub.row().prop(rd, "threads_mode", expand=True)
234         subsub = sub.column()
235         subsub.enabled = rd.threads_mode == 'FIXED'
236         subsub.prop(rd, "threads")
237         
238         sub = col.column(align=True)
239         sub.label(text="Tiles:")
240         sub.prop(rd, "parts_x", text="X")
241         sub.prop(rd, "parts_y", text="Y")
242
243         col = split.column()
244         col.label(text="Memory:")
245         sub = col.column()
246         sub.enabled = not (rd.use_border or rd.use_full_sample)
247         sub.prop(rd, "use_save_buffers")
248         sub = col.column()
249         sub.active = rd.use_compositing
250         sub.prop(rd, "use_free_image_textures")
251         sub.prop(rd, "use_free_unused_nodes")
252         sub = col.column()
253         sub.active = rd.use_raytrace
254         sub.label(text="Acceleration structure:")
255         sub.prop(rd, "raytrace_method", text="")
256         if rd.raytrace_method == 'OCTREE':
257             sub.prop(rd, "octree_resolution", text="Resolution")
258         else:
259             sub.prop(rd, "use_instances", text="Instances")
260         sub.prop(rd, "use_local_coords", text="Local Coordinates")
261
262
263 class RENDER_PT_post_processing(RenderButtonsPanel, Panel):
264     bl_label = "Post Processing"
265     bl_options = {'DEFAULT_CLOSED'}
266     COMPAT_ENGINES = {'BLENDER_RENDER'}
267
268     def draw(self, context):
269         layout = self.layout
270
271         rd = context.scene.render
272
273         split = layout.split()
274
275         col = split.column()
276         col.prop(rd, "use_compositing")
277         col.prop(rd, "use_sequencer")
278
279         split.prop(rd, "dither_intensity", text="Dither", slider=True)
280
281         layout.separator()
282
283         split = layout.split()
284
285         col = split.column()
286         col.prop(rd, "use_fields", text="Fields")
287         sub = col.column()
288         sub.active = rd.use_fields
289         sub.row().prop(rd, "field_order", expand=True)
290         sub.prop(rd, "use_fields_still", text="Still")
291
292         col = split.column()
293         col.prop(rd, "use_edge_enhance")
294         sub = col.column()
295         sub.active = rd.use_edge_enhance
296         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
297         sub.prop(rd, "edge_color", text="")
298
299
300 class RENDER_PT_freestyle(RenderButtonsPanel, Panel):
301     bl_label = "Freestyle"
302     bl_options = {'DEFAULT_CLOSED'}
303     COMPAT_ENGINES = {'BLENDER_RENDER'}
304
305     def draw_header(self, context):
306         rd = context.scene.render
307
308         self.layout.prop(rd, "use_freestyle", text="")
309
310     def draw(self, context):
311         rd = context.scene.render
312
313         layout = self.layout
314         layout.enabled = rd.use_freestyle
315
316         row = layout.row()
317         row.label(text="Line Thickness:")
318         row.prop(rd, "line_thickness_mode", expand=True)
319         row = layout.row()
320         row.enabled = (rd.line_thickness_mode == "ABSOLUTE")
321         row.prop(rd, "unit_line_thickness")
322
323
324 class RENDER_PT_stamp(RenderButtonsPanel, Panel):
325     bl_label = "Stamp"
326     bl_options = {'DEFAULT_CLOSED'}
327     COMPAT_ENGINES = {'BLENDER_RENDER'}
328
329     def draw_header(self, context):
330         rd = context.scene.render
331
332         self.layout.prop(rd, "use_stamp", text="")
333
334     def draw(self, context):
335         layout = self.layout
336
337         rd = context.scene.render
338
339         layout.active = rd.use_stamp
340
341         layout.prop(rd, "stamp_font_size", text="Font Size")
342
343         row = layout.row()
344         row.column().prop(rd, "stamp_foreground", slider=True)
345         row.column().prop(rd, "stamp_background", slider=True)
346
347         split = layout.split()
348
349         col = split.column()
350         col.prop(rd, "use_stamp_time", text="Time")
351         col.prop(rd, "use_stamp_date", text="Date")
352         col.prop(rd, "use_stamp_render_time", text="RenderTime")
353         col.prop(rd, "use_stamp_frame", text="Frame")
354         col.prop(rd, "use_stamp_scene", text="Scene")
355
356         col = split.column()
357         col.prop(rd, "use_stamp_camera", text="Camera")
358         col.prop(rd, "use_stamp_lens", text="Lens")
359         col.prop(rd, "use_stamp_filename", text="Filename")
360         col.prop(rd, "use_stamp_marker", text="Marker")
361         col.prop(rd, "use_stamp_sequencer_strip", text="Seq. Strip")
362
363         row = layout.split(percentage=0.2)
364         row.prop(rd, "use_stamp_note", text="Note")
365         sub = row.row()
366         sub.active = rd.use_stamp_note
367         sub.prop(rd, "stamp_note_text", text="")
368
369
370 class RENDER_PT_output(RenderButtonsPanel, Panel):
371     bl_label = "Output"
372     COMPAT_ENGINES = {'BLENDER_RENDER'}
373
374     def draw(self, context):
375         layout = self.layout
376
377         rd = context.scene.render
378         image_settings = rd.image_settings
379         file_format = image_settings.file_format
380
381         layout.prop(rd, "filepath", text="")
382
383         flow = layout.column_flow()
384         flow.prop(rd, "use_overwrite")
385         flow.prop(rd, "use_placeholder")
386         flow.prop(rd, "use_file_extension")
387
388         layout.template_image_settings(image_settings, color_management=False)
389
390         if file_format == 'QUICKTIME_CARBON':
391             layout.operator("scene.render_data_set_quicktime_codec")
392
393         elif file_format == 'QUICKTIME_QTKIT':
394             quicktime = rd.quicktime
395
396             split = layout.split()
397             col = split.column()
398             col.prop(quicktime, "codec_type", text="Video Codec")
399             col.prop(quicktime, "codec_spatial_quality", text="Quality")
400
401             # Audio
402             col.prop(quicktime, "audiocodec_type", text="Audio Codec")
403             if quicktime.audiocodec_type != 'No audio':
404                 split = layout.split()
405                 if quicktime.audiocodec_type == 'LPCM':
406                     split.prop(quicktime, "audio_bitdepth", text="")
407
408                 split.prop(quicktime, "audio_samplerate", text="")
409
410                 split = layout.split()
411                 col = split.column()
412                 if quicktime.audiocodec_type == 'AAC':
413                     col.prop(quicktime, "audio_bitrate")
414
415                 subsplit = split.split()
416                 col = subsplit.column()
417
418                 if quicktime.audiocodec_type == 'AAC':
419                     col.prop(quicktime, "audio_codec_isvbr")
420
421                 col = subsplit.column()
422                 col.prop(quicktime, "audio_resampling_hq")
423
424
425 class RENDER_PT_encoding(RenderButtonsPanel, Panel):
426     bl_label = "Encoding"
427     bl_options = {'DEFAULT_CLOSED'}
428     COMPAT_ENGINES = {'BLENDER_RENDER'}
429
430     @classmethod
431     def poll(cls, context):
432         rd = context.scene.render
433         return rd.image_settings.file_format in {'FFMPEG', 'XVID', 'H264', 'THEORA'}
434
435     def draw(self, context):
436         layout = self.layout
437
438         rd = context.scene.render
439         ffmpeg = rd.ffmpeg
440
441         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
442
443         split = layout.split()
444         split.prop(rd.ffmpeg, "format")
445         if ffmpeg.format in {'AVI', 'QUICKTIME', 'MKV', 'OGG'}:
446             split.prop(ffmpeg, "codec")
447         elif rd.ffmpeg.format == 'H264':
448             split.prop(ffmpeg, "use_lossless_output")
449         else:
450             split.label()
451
452         row = layout.row()
453         row.prop(ffmpeg, "video_bitrate")
454         row.prop(ffmpeg, "gopsize")
455
456         split = layout.split()
457
458         col = split.column()
459         col.label(text="Rate:")
460         col.prop(ffmpeg, "minrate", text="Minimum")
461         col.prop(ffmpeg, "maxrate", text="Maximum")
462         col.prop(ffmpeg, "buffersize", text="Buffer")
463
464         col = split.column()
465         col.prop(ffmpeg, "use_autosplit")
466         col.label(text="Mux:")
467         col.prop(ffmpeg, "muxrate", text="Rate")
468         col.prop(ffmpeg, "packetsize", text="Packet Size")
469
470         layout.separator()
471
472         # Audio:
473         if ffmpeg.format != 'MP3':
474             layout.prop(ffmpeg, "audio_codec", text="Audio Codec")
475
476         row = layout.row()
477         row.prop(ffmpeg, "audio_bitrate")
478         row.prop(ffmpeg, "audio_volume", slider=True)
479
480
481 class RENDER_PT_bake(RenderButtonsPanel, Panel):
482     bl_label = "Bake"
483     bl_options = {'DEFAULT_CLOSED'}
484     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
485
486     def draw(self, context):
487         layout = self.layout
488
489         rd = context.scene.render
490
491         layout.operator("object.bake_image", icon='RENDER_STILL')
492
493         layout.prop(rd, "bake_type")
494
495         multires_bake = False
496         if rd.bake_type in ['NORMALS', 'DISPLACEMENT']:
497             layout.prop(rd, "use_bake_multires")
498             multires_bake = rd.use_bake_multires
499
500         if not multires_bake:
501             if rd.bake_type == 'NORMALS':
502                 layout.prop(rd, "bake_normal_space")
503             elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
504                 layout.prop(rd, "use_bake_normalize")
505
506             # col.prop(rd, "bake_aa_mode")
507             # col.prop(rd, "use_bake_antialiasing")
508
509             layout.separator()
510
511             split = layout.split()
512
513             col = split.column()
514             col.prop(rd, "use_bake_clear")
515             col.prop(rd, "bake_margin")
516             col.prop(rd, "bake_quad_split", text="Split")
517
518             col = split.column()
519             col.prop(rd, "use_bake_selected_to_active")
520             sub = col.column()
521             sub.active = rd.use_bake_selected_to_active
522             sub.prop(rd, "bake_distance")
523             sub.prop(rd, "bake_bias")
524         else:
525             if rd.bake_type == 'DISPLACEMENT':
526                 layout.prop(rd, "use_bake_lores_mesh")
527
528             layout.prop(rd, "use_bake_clear")
529             layout.prop(rd, "bake_margin")
530
531
532 if __name__ == "__main__":  # only for live edit.
533     bpy.utils.register_module(__name__)