Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / blender / addon / properties.py
1 #
2 # Copyright 2011-2013 Blender Foundation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16
17 # <pep8 compliant>
18
19 import bpy
20 from bpy.props import (BoolProperty,
21                        EnumProperty,
22                        FloatProperty,
23                        IntProperty,
24                        PointerProperty,
25                        StringProperty)
26
27 # enums
28
29 import _cycles
30
31 enum_devices = (
32     ('CPU', "CPU", "Use CPU for rendering"),
33     ('GPU', "GPU Compute", "Use GPU compute device for rendering, configured in user preferences"),
34     )
35
36 if _cycles.with_network:
37     enum_devices += (('NETWORK', "Networked Device", "Use networked device for rendering"),)
38
39 enum_feature_set = (
40     ('SUPPORTED', "Supported", "Only use finished and supported features"),
41     ('EXPERIMENTAL', "Experimental", "Use experimental and incomplete features that might be broken or change in the future", 'ERROR', 1),
42     )
43
44 enum_displacement_methods = (
45     ('BUMP', "Bump", "Bump mapping to simulate the appearance of displacement"),
46     ('TRUE', "True", "Use true displacement only, requires fine subdivision"),
47     ('BOTH', "Both", "Combination of displacement and bump mapping"),
48     )
49
50 enum_bvh_types = (
51     ('DYNAMIC_BVH', "Dynamic BVH", "Objects can be individually updated, at the cost of slower render time"),
52     ('STATIC_BVH', "Static BVH", "Any object modification requires a complete BVH rebuild, but renders faster"),
53     )
54
55 enum_filter_types = (
56     ('BOX', "Box", "Box filter"),
57     ('GAUSSIAN', "Gaussian", "Gaussian filter"),
58     ('BLACKMAN_HARRIS', "Blackman-Harris", "Blackman-Harris filter"),
59     )
60
61 enum_aperture_types = (
62     ('RADIUS', "Radius", "Directly change the size of the aperture"),
63     ('FSTOP', "F-stop", "Change the size of the aperture by f-stop"),
64     )
65
66 enum_panorama_types = (
67     ('EQUIRECTANGULAR', "Equirectangular", "Render the scene with a spherical camera, also known as Lat Long panorama"),
68     ('FISHEYE_EQUIDISTANT', "Fisheye Equidistant", "Ideal for fulldomes, ignore the sensor dimensions"),
69     ('FISHEYE_EQUISOLID', "Fisheye Equisolid",
70                           "Similar to most fisheye modern lens, takes sensor dimensions into consideration"),
71     ('MIRRORBALL', "Mirror Ball", "Uses the mirror ball mapping"),
72     )
73
74 enum_curve_primitives = (
75     ('TRIANGLES', "Triangles", "Create triangle geometry around strands"),
76     ('LINE_SEGMENTS', "Line Segments", "Use line segment primitives"),
77     ('CURVE_SEGMENTS', "Curve Segments", "Use segmented cardinal curve primitives"),
78     )
79
80 enum_triangle_curves = (
81     ('CAMERA_TRIANGLES', "Planes", "Create individual triangles forming planes that face camera"),
82     ('TESSELLATED_TRIANGLES', "Tessellated", "Create mesh surrounding each strand"),
83     )
84
85 enum_curve_shape = (
86     ('RIBBONS', "Ribbons", "Ignore thickness of each strand"),
87     ('THICK', "Thick", "Use thickness of strand when rendering"),
88     )
89
90 enum_tile_order = (
91     ('CENTER', "Center", "Render from center to the edges"),
92     ('RIGHT_TO_LEFT', "Right to Left", "Render from right to left"),
93     ('LEFT_TO_RIGHT', "Left to Right", "Render from left to right"),
94     ('TOP_TO_BOTTOM', "Top to Bottom", "Render from top to bottom"),
95     ('BOTTOM_TO_TOP', "Bottom to Top", "Render from bottom to top"),
96     ('HILBERT_SPIRAL', "Hilbert Spiral", "Render in a Hilbert Spiral"),
97     )
98
99 enum_use_layer_samples = (
100     ('USE', "Use", "Per render layer number of samples override scene samples"),
101     ('BOUNDED', "Bounded", "Bound per render layer number of samples by global samples"),
102     ('IGNORE', "Ignore", "Ignore per render layer number of samples"),
103     )
104
105 enum_sampling_pattern = (
106     ('SOBOL', "Sobol", "Use Sobol random sampling pattern"),
107     ('CORRELATED_MUTI_JITTER', "Correlated Multi-Jitter", "Use Correlated Multi-Jitter random sampling pattern"),
108     )
109
110 enum_integrator = (
111     ('BRANCHED_PATH', "Branched Path Tracing", "Path tracing integrator that branches on the first bounce, giving more control over the number of light and material samples"),
112     ('PATH', "Path Tracing", "Pure path tracing integrator"),
113     )
114
115 enum_volume_sampling = (
116     ('DISTANCE', "Distance", "Use distance sampling, best for dense volumes with lights far away"),
117     ('EQUIANGULAR', "Equiangular", "Use equiangular sampling, best for volumes with low density with light inside or near the volume"),
118     ('MULTIPLE_IMPORTANCE', "Multiple Importance", "Combine distance and equi-angular sampling for volumes where neither method is ideal"),
119     )
120
121 enum_volume_interpolation = (
122     ('LINEAR', "Linear", "Good smoothness and speed"),
123     ('CUBIC', "Cubic", "Smoothed high quality interpolation, but slower")
124     )
125
126 enum_device_type = (
127     ('CPU', "CPU", "CPU", 0),
128     ('CUDA', "CUDA", "CUDA", 1),
129     ('OPENCL', "OpenCL", "OpenCL", 2)
130     )
131
132
133 class CyclesRenderSettings(bpy.types.PropertyGroup):
134     @classmethod
135     def register(cls):
136         bpy.types.Scene.cycles = PointerProperty(
137                 name="Cycles Render Settings",
138                 description="Cycles render settings",
139                 type=cls,
140                 )
141         cls.device = EnumProperty(
142                 name="Device",
143                 description="Device to use for rendering",
144                 items=enum_devices,
145                 default='CPU',
146                 )
147         cls.feature_set = EnumProperty(
148                 name="Feature Set",
149                 description="Feature set to use for rendering",
150                 items=enum_feature_set,
151                 default='SUPPORTED',
152                 )
153         cls.shading_system = BoolProperty(
154                 name="Open Shading Language",
155                 description="Use Open Shading Language (CPU rendering only)",
156                 )
157
158         cls.progressive = EnumProperty(
159                 name="Integrator",
160                 description="Method to sample lights and materials",
161                 items=enum_integrator,
162                 default='PATH',
163                 )
164
165         cls.use_square_samples = BoolProperty(
166                 name="Square Samples",
167                 description="Square sampling values for easier artist control",
168                 default=False,
169                 )
170
171         cls.samples = IntProperty(
172                 name="Samples",
173                 description="Number of samples to render for each pixel",
174                 min=1, max=2147483647,
175                 default=128,
176                 )
177         cls.preview_samples = IntProperty(
178                 name="Preview Samples",
179                 description="Number of samples to render in the viewport, unlimited if 0",
180                 min=0, max=2147483647,
181                 default=32,
182                 )
183         cls.preview_pause = BoolProperty(
184                 name="Pause Preview",
185                 description="Pause all viewport preview renders",
186                 default=False,
187                 )
188         cls.preview_active_layer = BoolProperty(
189                 name="Preview Active Layer",
190                 description="Preview active render layer in viewport",
191                 default=False,
192                 )
193
194         cls.aa_samples = IntProperty(
195                 name="AA Samples",
196                 description="Number of antialiasing samples to render for each pixel",
197                 min=1, max=2097151,
198                 default=4,
199                 )
200         cls.preview_aa_samples = IntProperty(
201                 name="AA Samples",
202                 description="Number of antialiasing samples to render in the viewport, unlimited if 0",
203                 min=0, max=2097151,
204                 default=4,
205                 )
206         cls.diffuse_samples = IntProperty(
207                 name="Diffuse Samples",
208                 description="Number of diffuse bounce samples to render for each AA sample",
209                 min=1, max=1024,
210                 default=1,
211                 )
212         cls.glossy_samples = IntProperty(
213                 name="Glossy Samples",
214                 description="Number of glossy bounce samples to render for each AA sample",
215                 min=1, max=1024,
216                 default=1,
217                 )
218         cls.transmission_samples = IntProperty(
219                 name="Transmission Samples",
220                 description="Number of transmission bounce samples to render for each AA sample",
221                 min=1, max=1024,
222                 default=1,
223                 )
224         cls.ao_samples = IntProperty(
225                 name="Ambient Occlusion Samples",
226                 description="Number of ambient occlusion samples to render for each AA sample",
227                 min=1, max=1024,
228                 default=1,
229                 )
230         cls.mesh_light_samples = IntProperty(
231                 name="Mesh Light Samples",
232                 description="Number of mesh emission light samples to render for each AA sample",
233                 min=1, max=1024,
234                 default=1,
235                 )
236
237         cls.subsurface_samples = IntProperty(
238                 name="Subsurface Samples",
239                 description="Number of subsurface scattering samples to render for each AA sample",
240                 min=1, max=1024,
241                 default=1,
242                 )
243
244         cls.volume_samples = IntProperty(
245                 name="Volume Samples",
246                 description="Number of volume scattering samples to render for each AA sample",
247                 min=1, max=1024,
248                 default=1,
249                 )
250
251         cls.sampling_pattern = EnumProperty(
252                 name="Sampling Pattern",
253                 description="Random sampling pattern used by the integrator",
254                 items=enum_sampling_pattern,
255                 default='SOBOL',
256                 )
257
258         cls.use_layer_samples = EnumProperty(
259                 name="Layer Samples",
260                 description="How to use per render layer sample settings",
261                 items=enum_use_layer_samples,
262                 default='USE',
263                 )
264
265         cls.sample_all_lights_direct = BoolProperty(
266                 name="Sample All Direct Lights",
267                 description="Sample all lights (for direct samples), rather than randomly picking one",
268                 default=True,
269                 )
270
271         cls.sample_all_lights_indirect = BoolProperty(
272                 name="Sample All Indirect Lights",
273                 description="Sample all lights (for indirect samples), rather than randomly picking one",
274                 default=True,
275                 )
276         cls.light_sampling_threshold = FloatProperty(
277                 name="Light Sampling Threshold",
278                 description="Probabilistically terminate light samples when the light contribution is below this threshold (more noise but faster rendering). "
279                             "Zero disables the test and never ignores lights",
280                 min=0.0, max=1.0,
281                 default=0.05,
282                 )
283
284         cls.caustics_reflective = BoolProperty(
285                 name="Reflective Caustics",
286                 description="Use reflective caustics, resulting in a brighter image (more noise but added realism)",
287                 default=True,
288                 )
289
290         cls.caustics_refractive = BoolProperty(
291                 name="Refractive Caustics",
292                 description="Use refractive caustics, resulting in a brighter image (more noise but added realism)",
293                 default=True,
294                 )
295
296         cls.blur_glossy = FloatProperty(
297                 name="Filter Glossy",
298                 description="Adaptively blur glossy shaders after blurry bounces, "
299                             "to reduce noise at the cost of accuracy",
300                 min=0.0, max=10.0,
301                 default=0.0,
302                 )
303
304         cls.min_bounces = IntProperty(
305                 name="Min Bounces",
306                 description="Minimum number of bounces, setting this lower "
307                             "than the maximum enables probabilistic path "
308                             "termination (faster but noisier)",
309                 min=0, max=1024,
310                 default=3,
311                 )
312         cls.max_bounces = IntProperty(
313                 name="Max Bounces",
314                 description="Total maximum number of bounces",
315                 min=0, max=1024,
316                 default=12,
317                 )
318
319         cls.diffuse_bounces = IntProperty(
320                 name="Diffuse Bounces",
321                 description="Maximum number of diffuse reflection bounces, bounded by total maximum",
322                 min=0, max=1024,
323                 default=4,
324                 )
325         cls.glossy_bounces = IntProperty(
326                 name="Glossy Bounces",
327                 description="Maximum number of glossy reflection bounces, bounded by total maximum",
328                 min=0, max=1024,
329                 default=4,
330                 )
331         cls.transmission_bounces = IntProperty(
332                 name="Transmission Bounces",
333                 description="Maximum number of transmission bounces, bounded by total maximum",
334                 min=0, max=1024,
335                 default=12,
336                 )
337         cls.volume_bounces = IntProperty(
338                 name="Volume Bounces",
339                 description="Maximum number of volumetric scattering events",
340                 min=0, max=1024,
341                 default=0,
342                 )
343
344         cls.transparent_min_bounces = IntProperty(
345                 name="Transparent Min Bounces",
346                 description="Minimum number of transparent bounces, setting "
347                             "this lower than the maximum enables "
348                             "probabilistic path termination (faster but "
349                             "noisier)",
350                 min=0, max=1024,
351                 default=8,
352                 )
353         cls.transparent_max_bounces = IntProperty(
354                 name="Transparent Max Bounces",
355                 description="Maximum number of transparent bounces",
356                 min=0, max=1024,
357                 default=8,
358                 )
359         cls.use_transparent_shadows = BoolProperty(
360                 name="Transparent Shadows",
361                 description="Use transparency of surfaces for rendering shadows",
362                 default=True,
363                 )
364
365         cls.volume_step_size = FloatProperty(
366                 name="Step Size",
367                 description="Distance between volume shader samples when rendering the volume "
368                             "(lower values give more accurate and detailed results, but also increased render time)",
369                 default=0.1,
370                 min=0.0000001, max=100000.0, soft_min=0.01, soft_max=1.0, precision=4
371                 )
372
373         cls.volume_max_steps = IntProperty(
374                 name="Max Steps",
375                 description="Maximum number of steps through the volume before giving up, "
376                             "to avoid extremely long render times with big objects or small step sizes",
377                 default=1024,
378                 min=2, max=65536
379                 )
380
381         cls.dicing_rate = FloatProperty(
382                 name="Dicing Rate",
383                 description="Size of a micropolygon in pixels",
384                 min=0.1, max=1000.0, soft_min=0.5,
385                 default=1.0,
386                 subtype="PIXEL"
387                 )
388         cls.preview_dicing_rate = FloatProperty(
389                 name="Preview Dicing Rate",
390                 description="Size of a micropolygon in pixels during preview render",
391                 min=0.1, max=1000.0, soft_min=0.5,
392                 default=8.0,
393                 subtype="PIXEL"
394                 )
395
396         cls.max_subdivisions = IntProperty(
397                 name="Max Subdivisions",
398                 description="Stop subdividing when this level is reached even if the dice rate would produce finer tessellation",
399                 min=0, max=16,
400                 default=12,
401                 )
402
403         cls.film_exposure = FloatProperty(
404                 name="Exposure",
405                 description="Image brightness scale",
406                 min=0.0, max=10.0,
407                 default=1.0,
408                 )
409         cls.film_transparent = BoolProperty(
410                 name="Transparent",
411                 description="World background is transparent with premultiplied alpha",
412                 default=False,
413                 )
414
415         # Really annoyingly, we have to keep it around for a few releases,
416         # otherwise forward compatibility breaks in really bad manner: CRASH!
417         #
418         # TODO(sergey): Remove this during 2.8x series of Blender.
419         cls.filter_type = EnumProperty(
420                 name="Filter Type",
421                 description="Pixel filter type",
422                 items=enum_filter_types,
423                 default='BLACKMAN_HARRIS',
424                 )
425
426         cls.pixel_filter_type = EnumProperty(
427                 name="Filter Type",
428                 description="Pixel filter type",
429                 items=enum_filter_types,
430                 default='BLACKMAN_HARRIS',
431                 )
432
433         cls.filter_width = FloatProperty(
434                 name="Filter Width",
435                 description="Pixel filter width",
436                 min=0.01, max=10.0,
437                 default=1.5,
438                 )
439
440         cls.seed = IntProperty(
441                 name="Seed",
442                 description="Seed value for integrator to get different noise patterns",
443                 min=0, max=2147483647,
444                 default=0,
445                 )
446
447         cls.use_animated_seed = BoolProperty(
448                 name="Use Animated Seed",
449                 description="Use different seed values (and hence noise patterns) at different frames",
450                 default=False,
451                 )
452
453         cls.sample_clamp_direct = FloatProperty(
454                 name="Clamp Direct",
455                 description="If non-zero, the maximum value for a direct sample, "
456                             "higher values will be scaled down to avoid too "
457                             "much noise and slow convergence at the cost of accuracy",
458                 min=0.0, max=1e8,
459                 default=0.0,
460                 )
461
462         cls.sample_clamp_indirect = FloatProperty(
463                 name="Clamp Indirect",
464                 description="If non-zero, the maximum value for an indirect sample, "
465                             "higher values will be scaled down to avoid too "
466                             "much noise and slow convergence at the cost of accuracy",
467                 min=0.0, max=1e8,
468                 default=0.0,
469                 )
470
471         cls.debug_tile_size = IntProperty(
472                 name="Tile Size",
473                 description="",
474                 min=1, max=4096,
475                 default=1024,
476                 )
477
478         cls.preview_start_resolution = IntProperty(
479                 name="Start Resolution",
480                 description="Resolution to start rendering preview at, "
481                             "progressively increasing it to the full viewport size",
482                 min=8, max=16384,
483                 default=64,
484                 )
485
486         cls.debug_reset_timeout = FloatProperty(
487                 name="Reset timeout",
488                 description="",
489                 min=0.01, max=10.0,
490                 default=0.1,
491                 )
492         cls.debug_cancel_timeout = FloatProperty(
493                 name="Cancel timeout",
494                 description="",
495                 min=0.01, max=10.0,
496                 default=0.1,
497                 )
498         cls.debug_text_timeout = FloatProperty(
499                 name="Text timeout",
500                 description="",
501                 min=0.01, max=10.0,
502                 default=1.0,
503                 )
504
505         cls.debug_bvh_type = EnumProperty(
506                 name="Viewport BVH Type",
507                 description="Choose between faster updates, or faster render",
508                 items=enum_bvh_types,
509                 default='DYNAMIC_BVH',
510                 )
511         cls.debug_use_spatial_splits = BoolProperty(
512                 name="Use Spatial Splits",
513                 description="Use BVH spatial splits: longer builder time, faster render",
514                 default=False,
515                 )
516         cls.debug_use_hair_bvh = BoolProperty(
517                 name="Use Hair BVH",
518                 description="Use special type BVH optimized for hair (uses more ram but renders faster)",
519                 default=True,
520                 )
521         cls.tile_order = EnumProperty(
522                 name="Tile Order",
523                 description="Tile order for rendering",
524                 items=enum_tile_order,
525                 default='HILBERT_SPIRAL',
526                 options=set(),  # Not animatable!
527                 )
528         cls.use_progressive_refine = BoolProperty(
529                 name="Progressive Refine",
530                 description="Instead of rendering each tile until it is finished, "
531                             "refine the whole image progressively "
532                             "(this renders somewhat slower, "
533                             "but time can be saved by manually stopping the render when the noise is low enough)",
534                 default=False,
535                 )
536
537         cls.bake_type = EnumProperty(
538             name="Bake Type",
539             default='COMBINED',
540             description="Type of pass to bake",
541             items=(
542                 ('COMBINED', "Combined", ""),
543                 ('AO', "Ambient Occlusion", ""),
544                 ('SHADOW', "Shadow", ""),
545                 ('NORMAL', "Normal", ""),
546                 ('UV', "UV", ""),
547                 ('EMIT', "Emit", ""),
548                 ('ENVIRONMENT', "Environment", ""),
549                 ('DIFFUSE', "Diffuse", ""),
550                 ('GLOSSY', "Glossy", ""),
551                 ('TRANSMISSION', "Transmission", ""),
552                 ('SUBSURFACE', "Subsurface", ""),
553                 ),
554             )
555
556         cls.use_camera_cull = BoolProperty(
557                 name="Use Camera Cull",
558                 description="Allow objects to be culled based on the camera frustum",
559                 default=False,
560                 )
561
562         cls.camera_cull_margin = FloatProperty(
563                 name="Camera Cull Margin",
564                 description="Margin for the camera space culling",
565                 default=0.1,
566                 min=0.0, max=5.0
567                 )
568
569         cls.motion_blur_position = EnumProperty(
570             name="Motion Blur Position",
571             default='CENTER',
572             description="Offset for the shutter's time interval, allows to change the motion blur trails",
573             items=(
574                 ('START', "Start on Frame", "The shutter opens at the current frame"),
575                 ('CENTER', "Center on Frame", "The shutter is open during the current frame"),
576                 ('END', "End on Frame", "The shutter closes at the current frame"),
577                 ),
578             )
579
580         cls.rolling_shutter_type = EnumProperty(
581             name="Shutter Type",
582             default='NONE',
583             description="Type of rolling shutter effect matching CMOS-based cameras",
584             items=(
585                 ('NONE', "None", "No rolling shutter effect used"),
586                 ('TOP', "Top-Bottom", "Sensor is being scanned from top to bottom")
587                 # TODO(seergey): Are there real cameras with different scanning direction?
588                 ),
589             )
590
591         cls.rolling_shutter_duration = FloatProperty(
592             name="Rolling Shutter Duration",
593             description="Scanline \"exposure\" time for the rolling shutter effect",
594             default=0.1,
595             min=0.0, max=1.0,
596             )
597
598         # Various fine-tuning debug flags
599
600         def devices_update_callback(self, context):
601             import _cycles
602             scene = context.scene.as_pointer()
603             return _cycles.debug_flags_update(scene)
604
605         cls.debug_use_cpu_avx2 = BoolProperty(name="AVX2", default=True)
606         cls.debug_use_cpu_avx = BoolProperty(name="AVX", default=True)
607         cls.debug_use_cpu_sse41 = BoolProperty(name="SSE41", default=True)
608         cls.debug_use_cpu_sse3 = BoolProperty(name="SSE3", default=True)
609         cls.debug_use_cpu_sse2 = BoolProperty(name="SSE2", default=True)
610         cls.debug_use_qbvh = BoolProperty(name="QBVH", default=True)
611
612         cls.debug_use_cuda_adaptive_compile = BoolProperty(name="Adaptive Compile", default=False)
613
614         cls.debug_opencl_kernel_type = EnumProperty(
615             name="OpenCL Kernel Type",
616             default='DEFAULT',
617             items=(
618                 ('DEFAULT', "Default", ""),
619                 ('MEGA', "Mega", ""),
620                 ('SPLIT', "Split", ""),
621                 ),
622             update=devices_update_callback
623             )
624
625         cls.debug_opencl_device_type = EnumProperty(
626             name="OpenCL Device Type",
627             default='ALL',
628             items=(
629                 ('NONE', "None", ""),
630                 ('ALL', "All", ""),
631                 ('DEFAULT', "Default", ""),
632                 ('CPU', "CPU", ""),
633                 ('GPU', "GPU", ""),
634                 ('ACCELERATOR', "Accelerator", ""),
635                 ),
636             update=devices_update_callback
637             )
638
639         cls.debug_use_opencl_debug = BoolProperty(name="Debug OpenCL", default=False)
640
641     @classmethod
642     def unregister(cls):
643         del bpy.types.Scene.cycles
644
645
646 class CyclesCameraSettings(bpy.types.PropertyGroup):
647     @classmethod
648     def register(cls):
649         import math
650
651         bpy.types.Camera.cycles = PointerProperty(
652                 name="Cycles Camera Settings",
653                 description="Cycles camera settings",
654                 type=cls,
655                 )
656
657         cls.aperture_type = EnumProperty(
658                 name="Aperture Type",
659                 description="Use f-stop number or aperture radius",
660                 items=enum_aperture_types,
661                 default='RADIUS',
662                 )
663         cls.aperture_fstop = FloatProperty(
664                 name="Aperture f-stop",
665                 description="F-stop ratio (lower numbers give more defocus, higher numbers give a sharper image)",
666                 min=0.0, soft_min=0.1, soft_max=64.0,
667                 default=5.6,
668                 step=10,
669                 precision=1,
670                 )
671         cls.aperture_size = FloatProperty(
672                 name="Aperture Size",
673                 description="Radius of the aperture for depth of field (higher values give more defocus)",
674                 min=0.0, soft_max=10.0,
675                 default=0.0,
676                 step=1,
677                 precision=4,
678                 subtype='DISTANCE',
679                 )
680         cls.aperture_blades = IntProperty(
681                 name="Aperture Blades",
682                 description="Number of blades in aperture for polygonal bokeh (at least 3)",
683                 min=0, max=100,
684                 default=0,
685                 )
686         cls.aperture_rotation = FloatProperty(
687                 name="Aperture Rotation",
688                 description="Rotation of blades in aperture",
689                 soft_min=-math.pi, soft_max=math.pi,
690                 subtype='ANGLE',
691                 default=0,
692                 )
693         cls.aperture_ratio = FloatProperty(
694                 name="Aperture Ratio",
695                 description="Distortion to simulate anamorphic lens bokeh",
696                 min=0.01, soft_min=1.0, soft_max=2.0,
697                 default=1.0,
698                 precision=4,
699                 )
700         cls.panorama_type = EnumProperty(
701                 name="Panorama Type",
702                 description="Distortion to use for the calculation",
703                 items=enum_panorama_types,
704                 default='FISHEYE_EQUISOLID',
705                 )
706         cls.fisheye_fov = FloatProperty(
707                 name="Field of View",
708                 description="Field of view for the fisheye lens",
709                 min=0.1745, soft_max=2.0 * math.pi, max=10.0 * math.pi,
710                 subtype='ANGLE',
711                 default=math.pi,
712                 )
713         cls.fisheye_lens = FloatProperty(
714                 name="Fisheye Lens",
715                 description="Lens focal length (mm)",
716                 min=0.01, soft_max=15.0, max=100.0,
717                 default=10.5,
718                 )
719         cls.latitude_min = FloatProperty(
720                 name="Min Latitude",
721                 description="Minimum latitude (vertical angle) for the equirectangular lens",
722                 min=-0.5 * math.pi, max=0.5 * math.pi,
723                 subtype='ANGLE',
724                 default=-0.5 * math.pi,
725                 )
726         cls.latitude_max = FloatProperty(
727                 name="Max Latitude",
728                 description="Maximum latitude (vertical angle) for the equirectangular lens",
729                 min=-0.5 * math.pi, max=0.5 * math.pi,
730                 subtype='ANGLE',
731                 default=0.5 * math.pi,
732                 )
733         cls.longitude_min = FloatProperty(
734                 name="Min Longitude",
735                 description="Minimum longitude (horizontal angle) for the equirectangular lens",
736                 min=-math.pi, max=math.pi,
737                 subtype='ANGLE',
738                 default=-math.pi,
739                 )
740         cls.longitude_max = FloatProperty(
741                 name="Max Longitude",
742                 description="Maximum longitude (horizontal angle) for the equirectangular lens",
743                 min=-math.pi, max=math.pi,
744                 subtype='ANGLE',
745                 default=math.pi,
746                 )
747
748     @classmethod
749     def unregister(cls):
750         del bpy.types.Camera.cycles
751
752
753 class CyclesMaterialSettings(bpy.types.PropertyGroup):
754     @classmethod
755     def register(cls):
756         bpy.types.Material.cycles = PointerProperty(
757                 name="Cycles Material Settings",
758                 description="Cycles material settings",
759                 type=cls,
760                 )
761         cls.sample_as_light = BoolProperty(
762                 name="Multiple Importance Sample",
763                 description="Use multiple importance sampling for this material, "
764                             "disabling may reduce overall noise for large "
765                             "objects that emit little light compared to other light sources",
766                 default=True,
767                 )
768         cls.use_transparent_shadow = BoolProperty(
769                 name="Transparent Shadows",
770                 description="Use transparent shadows for this material if it contains a Transparent BSDF, "
771                             "disabling will render faster but not give accurate shadows",
772                 default=True,
773                 )
774         cls.homogeneous_volume = BoolProperty(
775                 name="Homogeneous Volume",
776                 description="When using volume rendering, assume volume has the same density everywhere "
777                             "(not using any textures), for faster rendering",
778                 default=False,
779                 )
780         cls.volume_sampling = EnumProperty(
781                 name="Volume Sampling",
782                 description="Sampling method to use for volumes",
783                 items=enum_volume_sampling,
784                 default='MULTIPLE_IMPORTANCE',
785                 )
786
787         cls.volume_interpolation = EnumProperty(
788                 name="Volume Interpolation",
789                 description="Interpolation method to use for smoke/fire volumes",
790                 items=enum_volume_interpolation,
791                 default='LINEAR',
792                 )
793
794         cls.displacement_method = EnumProperty(
795                 name="Displacement Method",
796                 description="Method to use for the displacement",
797                 items=enum_displacement_methods,
798                 default='BUMP',
799                 )
800
801     @classmethod
802     def unregister(cls):
803         del bpy.types.Material.cycles
804
805
806 class CyclesLampSettings(bpy.types.PropertyGroup):
807     @classmethod
808     def register(cls):
809         bpy.types.Lamp.cycles = PointerProperty(
810                 name="Cycles Lamp Settings",
811                 description="Cycles lamp settings",
812                 type=cls,
813                 )
814         cls.cast_shadow = BoolProperty(
815                 name="Cast Shadow",
816                 description="Lamp casts shadows",
817                 default=True,
818                 )
819         cls.samples = IntProperty(
820                 name="Samples",
821                 description="Number of light samples to render for each AA sample",
822                 min=1, max=10000,
823                 default=1,
824                 )
825         cls.max_bounces = IntProperty(
826                 name="Max Bounces",
827                 description="Maximum number of bounces the light will contribute to the render",
828                 min=0, max=1024,
829                 default=1024,
830                 )
831         cls.use_multiple_importance_sampling = BoolProperty(
832                 name="Multiple Importance Sample",
833                 description="Use multiple importance sampling for the lamp, "
834                             "reduces noise for area lamps and sharp glossy materials",
835                 default=True,
836                 )
837         cls.is_portal = BoolProperty(
838                 name="Is Portal",
839                 description="Use this area lamp to guide sampling of the background, "
840                             "note that this will make the lamp invisible",
841                 default=False,
842                 )
843
844     @classmethod
845     def unregister(cls):
846         del bpy.types.Lamp.cycles
847
848
849 class CyclesWorldSettings(bpy.types.PropertyGroup):
850     @classmethod
851     def register(cls):
852         bpy.types.World.cycles = PointerProperty(
853                 name="Cycles World Settings",
854                 description="Cycles world settings",
855                 type=cls,
856                 )
857         cls.sample_as_light = BoolProperty(
858                 name="Multiple Importance Sample",
859                 description="Use multiple importance sampling for the environment, "
860                             "enabling for non-solid colors is recommended",
861                 default=True,
862                 )
863         cls.sample_map_resolution = IntProperty(
864                 name="Map Resolution",
865                 description="Importance map size is resolution x resolution; "
866                             "higher values potentially produce less noise, at the cost of memory and speed",
867                 min=4, max=8192,
868                 default=1024,
869                 )
870         cls.samples = IntProperty(
871                 name="Samples",
872                 description="Number of light samples to render for each AA sample",
873                 min=1, max=10000,
874                 default=1,
875                 )
876         cls.max_bounces = IntProperty(
877                 name="Max Bounces",
878                 description="Maximum number of bounces the background light will contribute to the render",
879                 min=0, max=1024,
880                 default=1024,
881                 )
882         cls.homogeneous_volume = BoolProperty(
883                 name="Homogeneous Volume",
884                 description="When using volume rendering, assume volume has the same density everywhere"
885                             "(not using any textures), for faster rendering",
886                 default=False,
887                 )
888         cls.volume_sampling = EnumProperty(
889                 name="Volume Sampling",
890                 description="Sampling method to use for volumes",
891                 items=enum_volume_sampling,
892                 default='EQUIANGULAR',
893                 )
894
895         cls.volume_interpolation = EnumProperty(
896                 name="Volume Interpolation",
897                 description="Interpolation method to use for volumes",
898                 items=enum_volume_interpolation,
899                 default='LINEAR',
900                 )
901
902     @classmethod
903     def unregister(cls):
904         del bpy.types.World.cycles
905
906
907 class CyclesVisibilitySettings(bpy.types.PropertyGroup):
908     @classmethod
909     def register(cls):
910         bpy.types.Object.cycles_visibility = PointerProperty(
911                 name="Cycles Visibility Settings",
912                 description="Cycles visibility settings",
913                 type=cls,
914                 )
915
916         bpy.types.World.cycles_visibility = PointerProperty(
917                 name="Cycles Visibility Settings",
918                 description="Cycles visibility settings",
919                 type=cls,
920                 )
921
922         cls.camera = BoolProperty(
923                 name="Camera",
924                 description="Object visibility for camera rays",
925                 default=True,
926                 )
927         cls.diffuse = BoolProperty(
928                 name="Diffuse",
929                 description="Object visibility for diffuse reflection rays",
930                 default=True,
931                 )
932         cls.glossy = BoolProperty(
933                 name="Glossy",
934                 description="Object visibility for glossy reflection rays",
935                 default=True,
936                 )
937         cls.transmission = BoolProperty(
938                 name="Transmission",
939                 description="Object visibility for transmission rays",
940                 default=True,
941                 )
942         cls.shadow = BoolProperty(
943                 name="Shadow",
944                 description="Object visibility for shadow rays",
945                 default=True,
946                 )
947         cls.scatter = BoolProperty(
948                 name="Volume Scatter",
949                 description="Object visibility for volume scatter rays",
950                 default=True,
951                 )
952
953     @classmethod
954     def unregister(cls):
955         del bpy.types.Object.cycles_visibility
956         del bpy.types.World.cycles_visibility
957
958
959 class CyclesMeshSettings(bpy.types.PropertyGroup):
960     @classmethod
961     def register(cls):
962         bpy.types.Mesh.cycles = PointerProperty(
963                 name="Cycles Mesh Settings",
964                 description="Cycles mesh settings",
965                 type=cls,
966                 )
967         bpy.types.Curve.cycles = PointerProperty(
968                 name="Cycles Mesh Settings",
969                 description="Cycles mesh settings",
970                 type=cls,
971                 )
972         bpy.types.MetaBall.cycles = PointerProperty(
973                 name="Cycles Mesh Settings",
974                 description="Cycles mesh settings",
975                 type=cls,
976                 )
977
978     @classmethod
979     def unregister(cls):
980         del bpy.types.Mesh.cycles
981         del bpy.types.Curve.cycles
982         del bpy.types.MetaBall.cycles
983
984
985 class CyclesObjectSettings(bpy.types.PropertyGroup):
986     @classmethod
987     def register(cls):
988         bpy.types.Object.cycles = PointerProperty(
989                 name="Cycles Object Settings",
990                 description="Cycles object settings",
991                 type=cls,
992                 )
993
994         cls.use_motion_blur = BoolProperty(
995                 name="Use Motion Blur",
996                 description="Use motion blur for this object",
997                 default=True,
998                 )
999
1000         cls.use_deform_motion = BoolProperty(
1001                 name="Use Deformation Motion",
1002                 description="Use deformation motion blur for this object",
1003                 default=True,
1004                 )
1005
1006         cls.motion_steps = IntProperty(
1007                 name="Motion Steps",
1008                 description="Control accuracy of deformation motion blur, more steps gives more memory usage (actual number of steps is 2^(steps - 1))",
1009                 min=1, soft_max=8,
1010                 default=1,
1011                 )
1012
1013         cls.use_camera_cull = BoolProperty(
1014                 name="Use Camera Cull",
1015                 description="Allow this object and its duplicators to be culled by camera space culling",
1016                 default=False,
1017                 )
1018
1019         cls.use_adaptive_subdivision = BoolProperty(
1020                 name="Use Adaptive Subdivision",
1021                 description="Use adaptive render time subdivision",
1022                 default=False,
1023                 )
1024
1025         cls.dicing_rate = FloatProperty(
1026                 name="Dicing Scale",
1027                 description="Multiplier for scene dicing rate (located in the Geometry Panel)",
1028                 min=0.1, max=1000.0, soft_min=0.5,
1029                 default=1.0,
1030                 )
1031
1032     @classmethod
1033     def unregister(cls):
1034         del bpy.types.Object.cycles
1035
1036
1037 class CyclesCurveRenderSettings(bpy.types.PropertyGroup):
1038     @classmethod
1039     def register(cls):
1040         bpy.types.Scene.cycles_curves = PointerProperty(
1041                 name="Cycles Hair Rendering Settings",
1042                 description="Cycles hair rendering settings",
1043                 type=cls,
1044                 )
1045         cls.primitive = EnumProperty(
1046                 name="Primitive",
1047                 description="Type of primitive used for hair rendering",
1048                 items=enum_curve_primitives,
1049                 default='LINE_SEGMENTS',
1050                 )
1051         cls.shape = EnumProperty(
1052                 name="Shape",
1053                 description="Form of hair",
1054                 items=enum_curve_shape,
1055                 default='THICK',
1056                 )
1057         cls.cull_backfacing = BoolProperty(
1058                 name="Cull back-faces",
1059                 description="Do not test the back-face of each strand",
1060                 default=True,
1061                 )
1062         cls.use_curves = BoolProperty(
1063                 name="Use Cycles Hair Rendering",
1064                 description="Activate Cycles hair rendering for particle system",
1065                 default=True,
1066                 )
1067         cls.resolution = IntProperty(
1068                 name="Resolution",
1069                 description="Resolution of generated mesh",
1070                 min=3, max=64,
1071                 default=3,
1072                 )
1073         cls.minimum_width = FloatProperty(
1074                 name="Minimal width",
1075                 description="Minimal pixel width for strands (0 - deactivated)",
1076                 min=0.0, max=100.0,
1077                 default=0.0,
1078                 )
1079         cls.maximum_width = FloatProperty(
1080                 name="Maximal width",
1081                 description="Maximum extension that strand radius can be increased by",
1082                 min=0.0, max=100.0,
1083                 default=0.1,
1084                 )
1085         cls.subdivisions = IntProperty(
1086                 name="Subdivisions",
1087                 description="Number of subdivisions used in Cardinal curve intersection (power of 2)",
1088                 min=0, max=24,
1089                 default=4,
1090                 )
1091
1092     @classmethod
1093     def unregister(cls):
1094         del bpy.types.Scene.cycles_curves
1095
1096
1097 class CyclesDeviceSettings(bpy.types.PropertyGroup):
1098     @classmethod
1099     def register(cls):
1100         cls.id = StringProperty(name="ID")
1101         cls.name = StringProperty(name="Name")
1102         cls.use = BoolProperty(name="Use", default=True)
1103         cls.type = EnumProperty(name="Type", items=enum_device_type, default='CUDA')
1104
1105
1106 class CyclesPreferences(bpy.types.AddonPreferences):
1107     bl_idname = __package__
1108
1109     def get_device_types(self, context):
1110         import _cycles
1111         has_cuda, has_opencl = _cycles.get_device_types()
1112         list = [('NONE', "None", "Don't use compute device", 0)]
1113         if has_cuda:
1114             list.append(('CUDA', "CUDA", "Use CUDA for GPU acceleration", 1))
1115         if has_opencl:
1116             list.append(('OPENCL', "OpenCL", "Use OpenCL for GPU acceleration", 2))
1117         return list
1118
1119     compute_device_type = EnumProperty(
1120             name="Compute Device Type",
1121             description="Device to use for computation (rendering with Cycles)",
1122             items=get_device_types,
1123             )
1124
1125     devices = bpy.props.CollectionProperty(type=CyclesDeviceSettings)
1126
1127     def get_devices(self):
1128         import _cycles
1129         # Layout of the device tuples: (Name, Type, Internal ID, Persistent ID)
1130         device_list = _cycles.available_devices()
1131
1132         cuda_devices = []
1133         opencl_devices = []
1134         for device in device_list:
1135             if not device[1] in {'CUDA', 'OPENCL'}:
1136                 continue
1137
1138             entry = None
1139             # Try to find existing Device entry
1140             for dev in self.devices:
1141                 if dev.id == device[2] and dev.type == device[1]:
1142                     entry = dev
1143                     break
1144             # Create new entry if no existing one was found
1145             if not entry:
1146                 entry = self.devices.add()
1147                 entry.id   = device[2]
1148                 entry.name = device[0]
1149                 entry.type = device[1]
1150
1151             # Sort entries into lists
1152             if entry.type == 'CUDA':
1153                 cuda_devices.append(entry)
1154             elif entry.type == 'OPENCL':
1155                 opencl_devices.append(entry)
1156         return cuda_devices, opencl_devices
1157
1158
1159     def get_num_gpu_devices(self):
1160         import _cycles
1161         device_list = _cycles.available_devices()
1162         num = 0
1163         for device in device_list:
1164             if device[1] != self.compute_device_type:
1165                 continue
1166             for dev in self.devices:
1167                 if dev.use and dev.id == device[2]:
1168                     num += 1
1169         return num
1170
1171
1172     def has_active_device(self):
1173         return self.get_num_gpu_devices() > 0
1174
1175
1176     def draw_impl(self, layout, context):
1177         layout.label(text="Compute Device:")
1178         layout.row().prop(self, "compute_device_type", expand=True)
1179
1180         cuda_devices, opencl_devices = self.get_devices()
1181         row = layout.row()
1182
1183         if cuda_devices:
1184             col = row.column(align=True)
1185             col.label(text="CUDA devices:")
1186             for device in cuda_devices:
1187                 col.prop(device, "use", text=device.name, toggle=True)
1188
1189         if opencl_devices:
1190             col = row.column(align=True)
1191             col.label(text="OpenCL devices:")
1192             for device in opencl_devices:
1193                 col.prop(device, "use", text=device.name, toggle=True)
1194
1195
1196     def draw(self, context):
1197         self.draw_impl(self.layout, context)
1198
1199
1200 def register():
1201     bpy.utils.register_class(CyclesRenderSettings)
1202     bpy.utils.register_class(CyclesCameraSettings)
1203     bpy.utils.register_class(CyclesMaterialSettings)
1204     bpy.utils.register_class(CyclesLampSettings)
1205     bpy.utils.register_class(CyclesWorldSettings)
1206     bpy.utils.register_class(CyclesVisibilitySettings)
1207     bpy.utils.register_class(CyclesMeshSettings)
1208     bpy.utils.register_class(CyclesObjectSettings)
1209     bpy.utils.register_class(CyclesCurveRenderSettings)
1210     bpy.utils.register_class(CyclesDeviceSettings)
1211     bpy.utils.register_class(CyclesPreferences)
1212
1213
1214 def unregister():
1215     bpy.utils.unregister_class(CyclesRenderSettings)
1216     bpy.utils.unregister_class(CyclesCameraSettings)
1217     bpy.utils.unregister_class(CyclesMaterialSettings)
1218     bpy.utils.unregister_class(CyclesLampSettings)
1219     bpy.utils.unregister_class(CyclesWorldSettings)
1220     bpy.utils.unregister_class(CyclesMeshSettings)
1221     bpy.utils.unregister_class(CyclesObjectSettings)
1222     bpy.utils.unregister_class(CyclesVisibilitySettings)
1223     bpy.utils.unregister_class(CyclesCurveRenderSettings)
1224     bpy.utils.unregister_class(CyclesDeviceSettings)
1225     bpy.utils.unregister_class(CyclesPreferences)