Merged changes in the trunk up to revision 27647.
[blender-staging.git] / release / scripts / 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
22 narrowui = 180
23
24
25 class RENDER_MT_presets(bpy.types.Menu):
26     bl_label = "Render Presets"
27     preset_subdir = "render"
28     preset_operator = "script.python_file_run"
29     draw = bpy.types.Menu.draw_preset
30
31
32 class RENDER_MT_ffmpeg_presets(bpy.types.Menu):
33     bl_label = "FFMPEG Presets"
34     preset_subdir = "ffmpeg"
35     preset_operator = "script.python_file_run"
36     draw = bpy.types.Menu.draw_preset
37
38
39 class RenderButtonsPanel(bpy.types.Panel):
40     bl_space_type = 'PROPERTIES'
41     bl_region_type = 'WINDOW'
42     bl_context = "render"
43     # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
44
45     def poll(self, context):
46         rd = context.scene.render
47         return (context.scene and rd.use_game_engine is False) and (rd.engine in self.COMPAT_ENGINES)
48
49
50 class RENDER_PT_render(RenderButtonsPanel):
51     bl_label = "Render"
52     COMPAT_ENGINES = {'BLENDER_RENDER'}
53
54     def draw(self, context):
55         layout = self.layout
56
57         rd = context.scene.render
58         wide_ui = context.region.width > narrowui
59
60         split = layout.split()
61
62         col = split.column()
63         col.operator("render.render", text="Image", icon='RENDER_STILL')
64
65         if wide_ui:
66             col = split.column()
67         col.operator("render.render", text="Animation", icon='RENDER_ANIMATION').animation = True
68
69         layout.prop(rd, "display_mode", text="Display")
70
71
72 class RENDER_PT_layers(RenderButtonsPanel):
73     bl_label = "Layers"
74     bl_default_closed = True
75     COMPAT_ENGINES = {'BLENDER_RENDER'}
76
77     def draw(self, context):
78         layout = self.layout
79
80         scene = context.scene
81         rd = scene.render
82         wide_ui = context.region.width > narrowui
83
84         row = layout.row()
85         row.template_list(rd, "layers", rd, "active_layer_index", rows=2)
86
87         col = row.column(align=True)
88         col.operator("scene.render_layer_add", icon='ZOOMIN', text="")
89         col.operator("scene.render_layer_remove", icon='ZOOMOUT', text="")
90
91         rl = rd.layers[rd.active_layer_index]
92
93         if rl:
94             layout.prop(rl, "name")
95
96         split = layout.split()
97
98         col = split.column()
99         col.prop(scene, "visible_layers", text="Scene")
100         if wide_ui:
101             col = split.column()
102         col.prop(rl, "visible_layers", text="Layer")
103
104         layout.prop(rl, "light_override", text="Light")
105         layout.prop(rl, "material_override", text="Material")
106
107         layout.separator()
108         layout.label(text="Include:")
109
110         split = layout.split()
111
112         col = split.column()
113         col.prop(rl, "zmask")
114         row = col.row()
115         row.prop(rl, "zmask_negate", text="Negate")
116         row.active = rl.zmask
117         col.prop(rl, "all_z")
118
119         col = split.column()
120         col.prop(rl, "solid")
121         col.prop(rl, "halo")
122         col.prop(rl, "ztransp")
123         col.prop(rl, "sky")
124                 
125         col = split.column()
126         col.prop(rl, "edge")
127         col.prop(rl, "strand")
128         col.prop(rl, "freestyle")
129
130         if rl.zmask:
131             split = layout.split()
132             split.label(text="Zmask Layers:")
133             split.column().prop(rl, "zmask_layers", text="")
134
135         layout.separator()
136
137         split = layout.split()
138
139         col = split.column()
140         col.label(text="Passes:")
141         col.prop(rl, "pass_combined")
142         col.prop(rl, "pass_z")
143         col.prop(rl, "pass_vector")
144         col.prop(rl, "pass_normal")
145         col.prop(rl, "pass_uv")
146         col.prop(rl, "pass_mist")
147         col.prop(rl, "pass_object_index")
148         col.prop(rl, "pass_color")
149
150         if wide_ui:
151             col = split.column()
152         col.label()
153         col.prop(rl, "pass_diffuse")
154         row = col.row()
155         row.prop(rl, "pass_specular")
156         row.prop(rl, "pass_specular_exclude", text="", icon='X')
157         row = col.row()
158         row.prop(rl, "pass_shadow")
159         row.prop(rl, "pass_shadow_exclude", text="", icon='X')
160         row = col.row()
161         row.prop(rl, "pass_emit")
162         row.prop(rl, "pass_emit_exclude", text="", icon='X')
163         row = col.row()
164         row.prop(rl, "pass_ao")
165         row.prop(rl, "pass_ao_exclude", text="", icon='X')
166         row = col.row()
167         row.prop(rl, "pass_environment")
168         row.prop(rl, "pass_environment_exclude", text="", icon='X')
169         row = col.row()
170         row.prop(rl, "pass_indirect")
171         row.prop(rl, "pass_indirect_exclude", text="", icon='X')
172         row = col.row()
173         row.prop(rl, "pass_reflection")
174         row.prop(rl, "pass_reflection_exclude", text="", icon='X')
175         row = col.row()
176         row.prop(rl, "pass_refraction")
177         row.prop(rl, "pass_refraction_exclude", text="", icon='X')
178
179         if rl.freestyle:
180             layout.separator()
181
182             split = layout.split()
183
184             col = split.column()
185             col.label(text="Freestyle:")
186             freestyle = rl.freestyle_settings
187             col.prop(freestyle, "sphere_radius", text="Sphere Radius")
188             col.prop(freestyle, "ridges_and_valleys", text="Ridges and Valleys")
189             col.prop(freestyle, "suggestive_contours", text="Suggestive Contours")
190             col.prop(freestyle, "dkr_epsilon", text="Dkr Epsilon")
191
192             col.operator("scene.freestyle_module_add", text="Add Style Module")
193
194             for i, module in enumerate(freestyle.modules):
195                     box = layout.box()
196                     box.set_context_pointer("freestyle_module", module)
197                     row = box.row(align=True)
198                     row.prop(module, "is_displayed", text="")
199                     row.prop(module, "module_path", text="")
200                     row.operator("scene.freestyle_module_remove", icon='X', text="")
201                     props = row.operator("scene.freestyle_module_move_up", icon='MOVE_UP_VEC', text="")
202                     props.active = (i > 0)
203                     props = row.operator("scene.freestyle_module_move_down", icon='MOVE_DOWN_VEC', text="")
204                     props.active = (i < len(freestyle.modules) - 1)
205
206
207 class RENDER_PT_shading(RenderButtonsPanel):
208     bl_label = "Shading"
209     COMPAT_ENGINES = {'BLENDER_RENDER'}
210
211     def draw(self, context):
212         layout = self.layout
213
214         rd = context.scene.render
215         wide_ui = context.region.width > narrowui
216
217         split = layout.split()
218
219         col = split.column()
220         col.prop(rd, "render_textures", text="Textures")
221         col.prop(rd, "render_shadows", text="Shadows")
222         col.prop(rd, "render_sss", text="Subsurface Scattering")
223         col.prop(rd, "render_envmaps", text="Environment Map")
224
225         if wide_ui:
226             col = split.column()
227         col.prop(rd, "render_raytracing", text="Ray Tracing")
228         col.prop(rd, "color_management")
229         col.prop(rd, "alpha_mode", text="Alpha")
230
231
232 class RENDER_PT_performance(RenderButtonsPanel):
233     bl_label = "Performance"
234     bl_default_closed = True
235     COMPAT_ENGINES = {'BLENDER_RENDER'}
236
237     def draw(self, context):
238         layout = self.layout
239
240         rd = context.scene.render
241         wide_ui = context.region.width > narrowui
242
243         split = layout.split()
244
245         col = split.column()
246         col.label(text="Threads:")
247         col.row().prop(rd, "threads_mode", expand=True)
248         sub = col.column()
249         sub.enabled = rd.threads_mode == 'FIXED'
250         sub.prop(rd, "threads")
251         sub = col.column(align=True)
252         sub.label(text="Tiles:")
253         sub.prop(rd, "parts_x", text="X")
254         sub.prop(rd, "parts_y", text="Y")
255
256         if wide_ui:
257             col = split.column()
258         col.label(text="Memory:")
259         sub = col.column()
260         sub.enabled = not (rd.use_border or rd.full_sample)
261         sub.prop(rd, "save_buffers")
262         sub = col.column()
263         sub.active = rd.use_compositing
264         sub.prop(rd, "free_image_textures")
265         sub = col.column()
266         sub.active = rd.render_raytracing
267         sub.label(text="Acceleration structure:")
268         sub.prop(rd, "raytrace_structure", text="")
269         if rd.raytrace_structure == 'OCTREE':
270             sub.prop(rd, "octree_resolution", text="Resolution")
271         else:
272             sub.prop(rd, "use_instances", text="Instances")
273         sub.prop(rd, "use_local_coords", text="Local Coordinates")
274
275
276 class RENDER_PT_post_processing(RenderButtonsPanel):
277     bl_label = "Post Processing"
278     bl_default_closed = True
279     COMPAT_ENGINES = {'BLENDER_RENDER'}
280
281     def draw(self, context):
282         layout = self.layout
283
284         rd = context.scene.render
285         wide_ui = context.region.width > narrowui
286
287         split = layout.split()
288
289         col = split.column()
290         col.prop(rd, "use_compositing")
291         col.prop(rd, "use_sequencer")
292
293         if wide_ui:
294             col = split.column()
295         col.prop(rd, "dither_intensity", text="Dither", slider=True)
296
297         layout.separator()
298
299         split = layout.split()
300
301         col = split.column()
302         col.prop(rd, "fields", text="Fields")
303         sub = col.column()
304         sub.active = rd.fields
305         sub.row().prop(rd, "field_order", expand=True)
306         sub.prop(rd, "fields_still", text="Still")
307
308
309         if wide_ui:
310             col = split.column()
311         else:
312             col.separator()
313         col.prop(rd, "edge")
314         sub = col.column()
315         sub.active = rd.edge
316         sub.prop(rd, "edge_threshold", text="Threshold", slider=True)
317         sub.prop(rd, "edge_color", text="")
318
319         layout.separator()
320
321         split = layout.split()
322         col = split.column()
323         col.prop(rd, "freestyle", text="Freestyle")
324
325
326 class RENDER_PT_output(RenderButtonsPanel):
327     bl_label = "Output"
328     COMPAT_ENGINES = {'BLENDER_RENDER'}
329
330     def draw(self, context):
331         layout = self.layout
332
333         rd = context.scene.render
334         wide_ui = context.region.width > narrowui
335
336         layout.prop(rd, "output_path", text="")
337
338         split = layout.split()
339         col = split.column()
340         col.prop(rd, "file_format", text="")
341         col.row().prop(rd, "color_mode", text="Color", expand=True)
342
343         if wide_ui:
344             col = split.column()
345         col.prop(rd, "use_file_extension")
346         col.prop(rd, "use_overwrite")
347         col.prop(rd, "use_placeholder")
348
349         if rd.file_format in ('AVI_JPEG', 'JPEG'):
350             split = layout.split()
351             split.prop(rd, "file_quality", slider=True)
352
353         elif rd.file_format == 'OPEN_EXR':
354             split = layout.split()
355
356             col = split.column()
357             col.label(text="Codec:")
358             col.prop(rd, "exr_codec", text="")
359
360             if wide_ui:
361                 subsplit = split.split()
362                 col = subsplit.column()
363             col.prop(rd, "exr_half")
364             col.prop(rd, "exr_zbuf")
365
366             if wide_ui:
367                 col = subsplit.column()
368             col.prop(rd, "exr_preview")
369
370         elif rd.file_format == 'JPEG2000':
371             split = layout.split()
372             col = split.column()
373             col.label(text="Depth:")
374             col.row().prop(rd, "jpeg2k_depth", expand=True)
375
376             if wide_ui:
377                 col = split.column()
378             col.prop(rd, "jpeg2k_preset", text="")
379             col.prop(rd, "jpeg2k_ycc")
380
381         elif rd.file_format in ('CINEON', 'DPX'):
382             split = layout.split()
383             col = split.column()
384             col.prop(rd, "cineon_log", text="Convert to Log")
385
386             if wide_ui:
387                 col = split.column(align=True)
388             col.active = rd.cineon_log
389             col.prop(rd, "cineon_black", text="Black")
390             col.prop(rd, "cineon_white", text="White")
391             col.prop(rd, "cineon_gamma", text="Gamma")
392
393         elif rd.file_format == 'TIFF':
394             split = layout.split()
395             split.prop(rd, "tiff_bit")
396
397         elif rd.file_format == 'QUICKTIME_CARBON':
398             split = layout.split()
399             split.operator("scene.render_set_quicktime_codec")
400
401         elif rd.file_format == 'QUICKTIME_QTKIT':
402             split = layout.split()
403             col = split.column()
404             col.prop(rd, "quicktime_codec_type")
405             col.prop(rd, "quicktime_codec_spatial_quality", text="Quality")
406
407
408 class RENDER_PT_encoding(RenderButtonsPanel):
409     bl_label = "Encoding"
410     bl_default_closed = True
411     COMPAT_ENGINES = {'BLENDER_RENDER'}
412
413     def poll(self, context):
414         rd = context.scene.render
415         return rd.file_format in ('FFMPEG', 'XVID', 'H264', 'THEORA')
416
417     def draw(self, context):
418         layout = self.layout
419
420         rd = context.scene.render
421         wide_ui = context.region.width > narrowui
422
423         layout.menu("RENDER_MT_ffmpeg_presets", text="Presets")
424
425         split = layout.split()
426
427         col = split.column()
428         col.prop(rd, "ffmpeg_format")
429         if rd.ffmpeg_format in ('AVI', 'QUICKTIME', 'MKV', 'OGG'):
430             if wide_ui:
431                 col = split.column()
432             col.prop(rd, "ffmpeg_codec")
433         else:
434             if wide_ui:
435                 split.label()
436
437         split = layout.split()
438
439         col = split.column()
440         col.prop(rd, "ffmpeg_video_bitrate")
441         if wide_ui:
442             col = split.column()
443         col.prop(rd, "ffmpeg_gopsize")
444
445         split = layout.split()
446
447         col = split.column()
448         col.label(text="Rate:")
449         col.prop(rd, "ffmpeg_minrate", text="Minimum")
450         col.prop(rd, "ffmpeg_maxrate", text="Maximum")
451         col.prop(rd, "ffmpeg_buffersize", text="Buffer")
452
453         if wide_ui:
454             col = split.column()
455
456         col.prop(rd, "ffmpeg_autosplit")
457         col.label(text="Mux:")
458         col.prop(rd, "ffmpeg_muxrate", text="Rate")
459         col.prop(rd, "ffmpeg_packetsize", text="Packet Size")
460
461         # Audio:
462         sub = layout.column()
463
464         if rd.ffmpeg_format not in ('MP3'):
465             sub.prop(rd, "ffmpeg_audio_codec", text="Audio Codec")
466
467         sub.separator()
468
469         split = sub.split()
470
471         col = split.column()
472         col.prop(rd, "ffmpeg_audio_bitrate")
473         col.prop(rd, "ffmpeg_audio_mixrate")
474
475         if wide_ui:
476             col = split.column()
477         col.prop(rd, "ffmpeg_audio_volume", slider=True)
478
479
480 class RENDER_PT_antialiasing(RenderButtonsPanel):
481     bl_label = "Anti-Aliasing"
482     COMPAT_ENGINES = {'BLENDER_RENDER'}
483
484     def draw_header(self, context):
485         rd = context.scene.render
486
487         self.layout.prop(rd, "antialiasing", text="")
488
489     def draw(self, context):
490         layout = self.layout
491
492         rd = context.scene.render
493         wide_ui = context.region.width > narrowui
494         layout.active = rd.antialiasing
495
496         split = layout.split()
497
498         col = split.column()
499         col.row().prop(rd, "antialiasing_samples", expand=True)
500         sub = col.row()
501         sub.enabled = not rd.use_border
502         sub.prop(rd, "full_sample")
503
504         if wide_ui:
505             col = split.column()
506         col.prop(rd, "pixel_filter", text="")
507         col.prop(rd, "filter_size", text="Size")
508
509
510 class RENDER_PT_motion_blur(RenderButtonsPanel):
511     bl_label = "Full Sample Motion Blur"
512     bl_default_closed = True
513     COMPAT_ENGINES = {'BLENDER_RENDER'}
514
515     def draw_header(self, context):
516         rd = context.scene.render
517
518         self.layout.prop(rd, "motion_blur", text="")
519
520     def draw(self, context):
521         layout = self.layout
522
523         rd = context.scene.render
524         layout.active = rd.motion_blur
525
526         row = layout.row()
527         row.prop(rd, "motion_blur_samples")
528
529
530 class RENDER_PT_dimensions(RenderButtonsPanel):
531     bl_label = "Dimensions"
532     COMPAT_ENGINES = {'BLENDER_RENDER'}
533
534     def draw(self, context):
535         layout = self.layout
536
537         scene = context.scene
538         rd = scene.render
539         wide_ui = context.region.width > narrowui
540
541         row = layout.row().split()
542         sub = row.row(align=True).split(percentage=0.75)
543         sub.menu("RENDER_MT_presets", text="Presets")
544         sub.operator("render.preset_add", text="Add")
545
546         split = layout.split()
547
548         col = split.column()
549         sub = col.column(align=True)
550         sub.label(text="Resolution:")
551         sub.prop(rd, "resolution_x", text="X")
552         sub.prop(rd, "resolution_y", text="Y")
553         sub.prop(rd, "resolution_percentage", text="")
554
555         sub.label(text="Aspect Ratio:")
556         sub.prop(rd, "pixel_aspect_x", text="X")
557         sub.prop(rd, "pixel_aspect_y", text="Y")
558
559         row = col.row()
560         row.prop(rd, "use_border", text="Border")
561         sub = row.row()
562         sub.active = rd.use_border
563         sub.prop(rd, "crop_to_border", text="Crop")
564
565         if wide_ui:
566             col = split.column()
567         sub = col.column(align=True)
568         sub.label(text="Frame Range:")
569         sub.prop(scene, "start_frame", text="Start")
570         sub.prop(scene, "end_frame", text="End")
571         sub.prop(scene, "frame_step", text="Step")
572
573         sub.label(text="Frame Rate:")
574         sub.prop(rd, "fps")
575         sub.prop(rd, "fps_base", text="/")
576
577
578 class RENDER_PT_stamp(RenderButtonsPanel):
579     bl_label = "Stamp"
580     bl_default_closed = True
581     COMPAT_ENGINES = {'BLENDER_RENDER'}
582
583     def draw_header(self, context):
584         rd = context.scene.render
585
586         self.layout.prop(rd, "render_stamp", text="")
587
588     def draw(self, context):
589         layout = self.layout
590
591         rd = context.scene.render
592         wide_ui = context.region.width > narrowui
593
594         layout.active = rd.render_stamp
595
596         split = layout.split()
597
598         col = split.column()
599         col.prop(rd, "stamp_time", text="Time")
600         col.prop(rd, "stamp_date", text="Date")
601         col.prop(rd, "stamp_render_time", text="RenderTime")
602         col.prop(rd, "stamp_frame", text="Frame")
603         col.prop(rd, "stamp_scene", text="Scene")
604         col.prop(rd, "stamp_camera", text="Camera")
605         col.prop(rd, "stamp_filename", text="Filename")
606         col.prop(rd, "stamp_marker", text="Marker")
607         col.prop(rd, "stamp_sequencer_strip", text="Seq. Strip")
608
609         if wide_ui:
610             col = split.column()
611         col.active = rd.render_stamp
612         col.prop(rd, "stamp_foreground", slider=True)
613         col.prop(rd, "stamp_background", slider=True)
614         col.separator()
615         col.prop(rd, "stamp_font_size", text="Font Size")
616
617         row = layout.split(percentage=0.2)
618         row.prop(rd, "stamp_note", text="Note")
619         sub = row.row()
620         sub.active = rd.stamp_note
621         sub.prop(rd, "stamp_note_text", text="")
622
623
624 class RENDER_PT_bake(RenderButtonsPanel):
625     bl_label = "Bake"
626     bl_default_closed = True
627     COMPAT_ENGINES = {'BLENDER_RENDER'}
628
629     def draw(self, context):
630         layout = self.layout
631
632         rd = context.scene.render
633         wide_ui = context.region.width > narrowui
634
635         layout.operator("object.bake_image", icon='RENDER_STILL')
636         
637         if wide_ui:
638             layout.prop(rd, "bake_type")
639         else:
640             layout.prop(rd, "bake_type", text="")
641         
642         if rd.bake_type == 'NORMALS':
643             if wide_ui:
644                 layout.prop(rd, "bake_normal_space")
645             else:
646                 layout.prop(rd, "bake_normal_space", text="")
647         elif rd.bake_type in ('DISPLACEMENT', 'AO'):
648             layout.prop(rd, "bake_normalized")
649         
650         # col.prop(rd, "bake_aa_mode")
651         # col.prop(rd, "bake_enable_aa")
652         
653         layout.separator()
654         
655         split = layout.split()
656
657         col = split.column()
658         col.prop(rd, "bake_clear")
659         col.prop(rd, "bake_margin")
660         col.prop(rd, "bake_quad_split", text="Split")
661         
662         if wide_ui:
663             col = split.column()
664         col.prop(rd, "bake_active")
665         sub = col.column()
666         sub.active = rd.bake_active
667         sub.prop(rd, "bake_distance")
668         sub.prop(rd, "bake_bias")
669
670         
671 classes = [
672     RENDER_MT_presets,
673     RENDER_MT_ffmpeg_presets,
674     RENDER_PT_render,
675     RENDER_PT_layers,
676     RENDER_PT_dimensions,
677     RENDER_PT_antialiasing,
678     RENDER_PT_motion_blur,
679     RENDER_PT_shading,
680     RENDER_PT_output,
681     RENDER_PT_encoding,
682     RENDER_PT_performance,
683     RENDER_PT_post_processing,
684     RENDER_PT_stamp,
685     RENDER_PT_bake]
686
687
688 def register():
689     register = bpy.types.register
690     for cls in classes:
691         register(cls)
692
693
694 def unregister():
695     unregister = bpy.types.unregister
696     for cls in classes:
697         unregister(cls)
698
699 if __name__ == "__main__":
700     register()