Fix T104270: Error in materials_utils "unregister" function
[blender-addons.git] / render_povray / particles_properties.py
blobd0cd9b3495599bebc1b42aee6a371d98c619e756
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 """Declare shading properties exported to POV textures."""
4 import bpy
5 from bpy.utils import register_class, unregister_class
6 from bpy.types import PropertyGroup
7 from bpy.props import (
8 StringProperty,
9 BoolProperty,
10 FloatProperty,
11 PointerProperty,
15 class MaterialStrandSettings(PropertyGroup):
16 """Declare strand properties controllable in UI and translated to POV."""
18 bl_description = ("Strand settings for the material",)
20 blend_distance: FloatProperty(
21 name="Distance",
22 description="Worldspace distance over which to blend in the surface normal",
23 min=0.0,
24 max=10.0,
25 soft_min=0.0,
26 soft_max=10.0,
27 default=0.0,
28 precision=3,
31 root_size: FloatProperty(
32 name="Root",
33 description="Start size of strands in pixels or Blender units",
34 min=0.25,
35 default=1.0,
36 precision=5,
39 shape: FloatProperty(
40 name="Shape",
41 description="Positive values make strands rounder, negative ones make strands spiky",
42 min=-0.9,
43 max=0.9,
44 default=0.0,
45 precision=3,
48 size_min: FloatProperty(
49 name="Minimum",
50 description="Minimum size of strands in pixels",
51 min=0.001,
52 max=10.0,
53 default=1.0,
54 precision=3,
57 tip_size: FloatProperty(
58 name="Tip",
59 description="End size of strands in pixels or Blender units",
60 min=0.0,
61 default=1.0,
62 precision=5,
65 use_blender_units: BoolProperty(
66 name="Blender Units",
67 description="Use Blender units for widths instead of pixels",
68 default=False,
71 use_surface_diffuse: BoolProperty(
72 name="Surface diffuse",
73 description="Make diffuse shading more similar to shading the surface",
74 default=False,
77 use_tangent_shading: BoolProperty(
78 name="Tangent Shading",
79 description="Use direction of strands as normal for tangent-shading",
80 default=True,
83 uv_layer: StringProperty(
84 name="UV Layer",
85 # icon="GROUP_UVS",
86 description="Name of UV map to override",
87 default="",
90 width_fade: FloatProperty(
91 name="Width Fade",
92 description="Transparency along the width of the strand",
93 min=0.0,
94 max=2.0,
95 default=0.0,
96 precision=3,
99 # halo
101 # Halo settings for the material
102 # Type: MaterialHalo, (readonly, never None)
105 # darkness
107 # Minnaert darkness
108 # Type: float in [0, 2], default 0.0
110 # diffuse_color
112 # Diffuse color of the material
113 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
115 # diffuse_fresnel
117 # Power of Fresnel
118 # Type: float in [0, 5], default 0.0
120 # diffuse_fresnel_factor
122 # Blending factor of Fresnel
123 # Type: float in [0, 5], default 0.0
125 # diffuse_intensity
127 # Amount of diffuse reflection
128 # Type: float in [0, 1], default 0.0
130 # diffuse_ramp
132 # Color ramp used to affect diffuse shading
133 # Type: ColorRamp, (readonly)
135 # diffuse_ramp_blend
137 # Blending method of the ramp and the diffuse color
138 # Type: enum in [‘MIX’, ‘ADD’, ‘MULTIPLY’, ‘SUBTRACT’, ‘SCREEN’, ‘DIVIDE’, ‘DIFFERENCE’, ‘DARKEN’, ‘LIGHTEN’, ‘OVERLAY’, ‘DODGE’, ‘BURN’, ‘HUE’, ‘SATURATION’, ‘VALUE’, ‘COLOR’, ‘SOFT_LIGHT’, ‘LINEAR_LIGHT’], default ‘MIX’
140 # diffuse_ramp_factor
142 # Blending factor (also uses alpha in Colorband)
143 # Type: float in [0, 1], default 0.0
145 # diffuse_ramp_input
147 # How the ramp maps on the surface
148 # Type: enum in [‘SHADER’, ‘ENERGY’, ‘NORMAL’, ‘RESULT’], default ‘SHADER’
150 # diffuse_shader
152 # LAMBERT Lambert, Use a Lambertian shader.
153 # OREN_NAYAR Oren-Nayar, Use an Oren-Nayar shader.
154 # TOON Toon, Use a toon shader.
155 # MINNAERT Minnaert, Use a Minnaert shader.
156 # FRESNEL Fresnel, Use a Fresnel shader.
158 # Type: enum in [‘LAMBERT’, ‘OREN_NAYAR’, ‘TOON’, ‘MINNAERT’, ‘FRESNEL’], default ‘LAMBERT’
160 # diffuse_toon_size
162 # Size of diffuse toon area
163 # Type: float in [0, 3.14], default 0.0
165 # diffuse_toon_smooth
167 # Smoothness of diffuse toon area
168 # Type: float in [0, 1], default 0.0
170 # emit
172 # Amount of light to emit
173 # Type: float in [0, inf], default 0.0
175 # halo
177 # Halo settings for the material
178 # Type: MaterialHalo, (readonly, never None)
180 # invert_z
182 # Render material’s faces with an inverted Z buffer (scanline only)
183 # Type: boolean, default False
185 # light_group
187 # Limit lighting to lamps in this Group
188 # Type: Group
190 # line_color
192 # Line color used for Freestyle line rendering
193 # Type: float array of 4 items in [0, inf], default (0.0, 0.0, 0.0, 0.0)
195 # line_priority
197 # The line color of a higher priority is used at material boundaries
198 # Type: int in [0, 32767], default 0
200 # mirror_color
202 # Mirror color of the material
203 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
205 # node_tree
207 # Node tree for node based materials
208 # Type: NodeTree, (readonly)
210 # offset_z
212 # Give faces an artificial offset in the Z buffer for Z transparency
213 # Type: float in [-inf, inf], default 0.0
215 # paint_active_slot
217 # Index of active texture paint slot
218 # Type: int in [0, 32767], default 0
220 # paint_clone_slot
222 # Index of clone texture paint slot
223 # Type: int in [0, 32767], default 0
225 # pass_index
227 # Index number for the “Material Index” render pass
228 # Type: int in [0, 32767], default 0
230 # physics
232 # Game physics settings
233 # Type: MaterialPhysics, (readonly, never None)
235 # preview_render_type
237 # Type of preview render
239 # FLAT Flat, Flat XY plane.
240 # SPHERE Sphere, Sphere.
241 # CUBE Cube, Cube.
242 # MONKEY Monkey, Monkey.
243 # HAIR Hair, Hair strands.
244 # SPHERE_A World Sphere, Large sphere with sky.
246 # Type: enum in [‘FLAT’, ‘SPHERE’, ‘CUBE’, ‘MONKEY’, ‘HAIR’, ‘SPHERE_A’], default ‘FLAT’
248 # roughness
250 # Oren-Nayar Roughness
251 # Type: float in [0, 3.14], default 0.0
253 # shadow_buffer_bias
255 # Factor to multiply shadow buffer bias with (0 is ignore)
256 # Type: float in [0, 10], default 0.0
258 # shadow_cast_alpha
260 # Shadow casting alpha, in use for Irregular and Deep shadow buffer
261 # Type: float in [0.001, 1], default 0.0
263 # shadow_only_type
265 # How to draw shadows
267 # SHADOW_ONLY_OLD Shadow and Distance, Old shadow only method.
268 # SHADOW_ONLY Shadow Only, Improved shadow only method.
269 # SHADOW_ONLY_SHADED Shadow and Shading, Improved shadow only method which also renders lightless areas as shadows.
271 # Type: enum in [‘SHADOW_ONLY_OLD’, ‘SHADOW_ONLY’, ‘SHADOW_ONLY_SHADED’], default ‘SHADOW_ONLY_OLD’
273 # shadow_ray_bias
275 # Shadow raytracing bias to prevent terminator problems on shadow boundary
276 # Type: float in [0, 0.25], default 0.0
278 # specular_color
280 # Specular color of the material
281 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
283 # specular_hardness
285 # How hard (sharp) the specular reflection is
286 # Type: int in [1, 511], default 0
288 # specular_intensity
290 # How intense (bright) the specular reflection is
291 # Type: float in [0, 1], default 0.0
293 # specular_ior
295 # Specular index of refraction
296 # Type: float in [1, 10], default 0.0
298 # specular_ramp
300 # Color ramp used to affect specular shading
301 # Type: ColorRamp, (readonly)
303 # specular_ramp_blend
305 # Blending method of the ramp and the specular color
306 # Type: enum in [‘MIX’, ‘ADD’, ‘MULTIPLY’, ‘SUBTRACT’, ‘SCREEN’, ‘DIVIDE’, ‘DIFFERENCE’, ‘DARKEN’, ‘LIGHTEN’, ‘OVERLAY’, ‘DODGE’, ‘BURN’, ‘HUE’, ‘SATURATION’, ‘VALUE’, ‘COLOR’, ‘SOFT_LIGHT’, ‘LINEAR_LIGHT’], default ‘MIX’
308 # specular_ramp_factor
310 # Blending factor (also uses alpha in Colorband)
311 # Type: float in [0, 1], default 0.0
313 # specular_ramp_input
315 # How the ramp maps on the surface
316 # Type: enum in [‘SHADER’, ‘ENERGY’, ‘NORMAL’, ‘RESULT’], default ‘SHADER’
317 # specular_shader
319 # COOKTORR CookTorr, Use a Cook-Torrance shader.
320 # PHONG Phong, Use a Phong shader.
321 # BLINN Blinn, Use a Blinn shader.
322 # TOON Toon, Use a toon shader.
323 # WARDISO WardIso, Use a Ward anisotropic shader.
325 # Type: enum in [‘COOKTORR’, ‘PHONG’, ‘BLINN’, ‘TOON’, ‘WARDISO’], default ‘COOKTORR’
327 # specular_slope
329 # The standard deviation of surface slope
330 # Type: float in [0, 0.4], default 0.0
332 # specular_toon_size
334 # Size of specular toon area
335 # Type: float in [0, 1.53], default 0.0
337 # specular_toon_smooth
339 # Smoothness of specular toon area
340 # Type: float in [0, 1], default 0.0
342 # strand
344 # Strand settings for the material
345 # Type: MaterialStrand, (readonly, never None)
347 # subsurface_scattering
349 # Subsurface scattering settings for the material
350 # Type: MaterialSubsurfaceScattering, (readonly, never None)
352 # texture_paint_images
354 # Texture images used for texture painting
355 # Type: bpy_prop_collection of Image, (readonly)
357 # texture_paint_slots
359 # Texture slots defining the mapping and influence of textures
360 # Type: bpy_prop_collection of TexPaintSlot, (readonly)
362 # texture_slots
364 # Texture slots defining the mapping and influence of textures
365 # Type: MaterialTextureSlots bpy_prop_collection of MaterialTextureSlot, (readonly)
367 # type
369 # Material type defining how the object is rendered
371 # SURFACE Surface, Render object as a surface.
372 # WIRE Wire, Render the edges of faces as wires (not supported in raytracing).
373 # VOLUME Volume, Render object as a volume.
374 # HALO Halo, Render object as halo particles.
376 # Type: enum in [‘SURFACE’, ‘WIRE’, ‘VOLUME’, ‘HALO’], default ‘SURFACE’
378 # use_cast_shadows
380 # Allow this material to cast shadows
381 # Type: boolean, default False
383 # use_cast_shadows_only
385 # Make objects with this material appear invisible (not rendered), only casting shadows
386 # Type: boolean, default False
388 # use_cubic
390 # Use cubic interpolation for diffuse values, for smoother transitions
391 # Type: boolean, default False
393 # use_diffuse_ramp
395 # Toggle diffuse ramp operations
396 # Type: boolean, default False
398 # use_face_texture
400 # Replace the object’s base color with color from UV map image textures
401 # Type: boolean, default False
403 # use_face_texture_alpha
405 # Replace the object’s base alpha value with alpha from UV map image textures
406 # Type: boolean, default False
408 # use_full_oversampling
410 # Force this material to render full shading/textures for all anti-aliasing samples
411 # Type: boolean, default False
413 # use_light_group_exclusive
415 # Material uses the light group exclusively - these lamps are excluded from other scene lighting
416 # Type: boolean, default False
418 # use_light_group_local
420 # When linked in, material uses local light group with the same name
421 # Type: boolean, default False
423 # use_mist
425 # Use mist with this material (in world settings)
426 # Type: boolean, default False
428 # use_nodes
430 # Use shader nodes to render the material
431 # Type: boolean, default False
433 # use_object_color
435 # Modulate the result with a per-object color
436 # Type: boolean, default False
438 # use_only_shadow
440 # Render shadows as the material’s alpha value, making the material transparent except for shadowed areas
441 # Type: boolean, default False
443 # use_ray_shadow_bias
445 # Prevent raytraced shadow errors on surfaces with smooth shaded normals (terminator problem)
446 # Type: boolean, default False
448 # use_raytrace
450 # Include this material and geometry that uses it in raytracing calculations
451 # Type: boolean, default False
453 # use_shadeless
455 # Make this material insensitive to light or shadow
456 # Type: boolean, default False
458 # use_shadows
460 # Allow this material to receive shadows
461 # Type: boolean, default False
463 # use_sky
465 # Render this material with zero alpha, with sky background in place (scanline only)
466 # Type: boolean, default False
468 # use_specular_ramp
470 # Toggle specular ramp operations
471 # Type: boolean, default False
473 # use_tangent_shading
475 # Use the material’s tangent vector instead of the normal for shading - for anisotropic shading effects
476 # Type: boolean, default False
478 # use_textures
480 # Enable/Disable each texture
481 # Type: boolean array of 18 items, default (False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)
483 # use_transparency
485 # Render material as transparent
486 # Type: boolean, default False
488 # use_transparent_shadows
490 # Allow this object to receive transparent shadows cast through other objects
491 # Type: boolean, default False
493 # use_uv_project
495 # Use to ensure UV interpolation is correct for camera projections (use with UV project modifier)
496 # Type: boolean, default False
498 # use_vertex_color_light
500 # Add vertex colors as additional lighting
501 # Type: boolean, default False
503 # use_vertex_color_paint
505 # Replace object base color with vertex colors (multiply with ‘texture face’ face assigned textures)
506 # Type: boolean, default False
508 # volume
510 # Volume settings for the material
511 # Type: MaterialVolume, (readonly, never None)
513 (mat.type in {'SURFACE', 'WIRE', 'VOLUME'})
514 "use_transparency")
518 mat.use_transparency and mat.pov.transparency_method == 'Z_TRANSPARENCY'
523 col.prop(mat, "use_raytrace")
524 col.prop(mat, "use_full_oversampling")
526 sub.prop(mat, "use_sky")
529 col.prop(mat, "use_cast_shadows", text="Cast")
530 col.prop(mat, "use_cast_shadows_only", text="Cast Only")
531 col.prop(mat, "use_cast_buffer_shadows")
533 sub.active = mat.use_cast_buffer_shadows
534 sub.prop(mat, "shadow_cast_alpha", text="Casting Alpha")
535 col.prop(mat, "use_cast_approximate")
539 col.prop(mat, "diffuse_color", text="")
541 sub.active = (not mat.use_shadeless)
543 sub.prop(mat, "diffuse_intensity", text="Intensity")
546 col.prop(mat, "diffuse_shader", text="")
547 col.prop(mat, "use_diffuse_ramp", text="Ramp")
550 if mat.diffuse_shader == 'OREN_NAYAR':
551 col.prop(mat, "roughness")
552 elif mat.diffuse_shader == 'MINNAERT':
553 col.prop(mat, "darkness")
554 elif mat.diffuse_shader == 'TOON':
556 row.prop(mat, "diffuse_toon_size", text="Size")
557 row.prop(mat, "diffuse_toon_smooth", text="Smooth")
558 elif mat.diffuse_shader == 'FRESNEL':
560 row.prop(mat, "diffuse_fresnel", text="Fresnel")
561 row.prop(mat, "diffuse_fresnel_factor", text="Factor")
563 if mat.use_diffuse_ramp:
565 col.template_color_ramp(mat, "diffuse_ramp", expand=True)
569 row.prop(mat, "diffuse_ramp_input", text="Input")
570 row.prop(mat, "diffuse_ramp_blend", text="Blend")
572 col.prop(mat, "diffuse_ramp_factor", text="Factor")
577 col.prop(mat, "specular_color", text="")
578 col.prop(mat, "specular_intensity", text="Intensity")
580 col.prop(mat, "specular_shader", text="")
581 col.prop(mat, "use_specular_ramp", text="Ramp")
583 if mat.pov.specular_shader in {'COOKTORR', 'PHONG'}:
584 col.prop(mat, "specular_hardness", text="Hardness")
585 elif mat.pov.specular_shader == 'BLINN':
587 row.prop(mat, "specular_hardness", text="Hardness")
588 row.prop(mat, "specular_ior", text="IOR")
589 elif mat.pov.specular_shader == 'WARDISO':
590 col.prop(mat, "specular_slope", text="Slope")
591 elif mat.pov.specular_shader == 'TOON':
593 row.prop(mat, "specular_toon_size", text="Size")
594 row.prop(mat, "specular_toon_smooth", text="Smooth")
596 if mat.use_specular_ramp:
597 layout.separator()
598 layout.template_color_ramp(mat, "specular_ramp", expand=True)
599 layout.separator()
601 row = layout.row()
602 row.prop(mat, "specular_ramp_input", text="Input")
603 row.prop(mat, "specular_ramp_blend", text="Blend")
605 layout.prop(mat, "specular_ramp_factor", text="Factor")
608 XXX remove unused props and relayout as done for transparent sky
611 class MATERIAL_PT_halo(MaterialButtonsPanel, Panel):
612 bl_label = "Halo"
613 COMPAT_ENGINES = {'BLENDER_RENDER'}
615 @classmethod
616 def poll(cls, context):
617 mat = context.material
618 engine = context.scene.render.engine
619 return mat and (mat.type == 'HALO') and (engine in cls.COMPAT_ENGINES)
621 def draw(self, context):
622 layout = self.layout
624 mat = context.material # don't use node material
625 halo = mat.pov.halo
627 def number_but(layout, toggle, number, name, color):
628 row = layout.row(align=True)
629 row.prop(halo, toggle, text="")
630 sub = row.column(align=True)
631 sub.active = getattr(halo, toggle)
632 sub.prop(halo, number, text=name, translate=False)
633 if not color == "":
634 sub.prop(mat, color, text="")
636 split = layout.split()
638 col = split.column()
639 col.prop(mat, "alpha")
640 col.prop(mat, "diffuse_color", text="")
641 col.prop(halo, "seed")
643 col = split.column()
644 col.prop(halo, "size")
645 col.prop(halo, "hardness")
646 col.prop(halo, "add")
648 layout.label(text="Options:")
650 split = layout.split()
651 col = split.column()
652 col.prop(halo, "use_texture")
653 col.prop(halo, "use_vertex_normal")
654 col.prop(halo, "use_extreme_alpha")
655 col.prop(halo, "use_shaded")
656 col.prop(halo, "use_soft")
658 col = split.column()
659 number_but(col, "use_ring", "ring_count", iface_("Rings"), "mirror_color")
660 number_but(col, "use_lines", "line_count", iface_("Lines"), "specular_color")
661 number_but(col, "use_star", "star_tip_count", iface_("Star Tips"), "")
664 class MATERIAL_PT_flare(MaterialButtonsPanel, Panel):
665 bl_label = "Flare"
666 COMPAT_ENGINES = {'BLENDER_RENDER'}
668 @classmethod
669 def poll(cls, context):
670 mat = context.material
671 engine = context.scene.render.engine
672 return mat and (mat.type == 'HALO') and (engine in cls.COMPAT_ENGINES)
674 def draw_header(self, context):
675 halo = context.material.pov.halo
677 self.layout.prop(halo, "use_flare_mode", text="")
679 def draw(self, context):
680 layout = self.layout
682 mat = context.material # don't use node material
683 halo = mat.pov.halo
685 layout.active = halo.use_flare_mode
687 split = layout.split()
689 col = split.column()
690 col.prop(halo, "flare_size", text="Size")
691 col.prop(halo, "flare_boost", text="Boost")
692 col.prop(halo, "flare_seed", text="Seed")
694 col = split.column()
695 col.prop(halo, "flare_subflare_count", text="Subflares")
696 col.prop(halo, "flare_subflare_size", text="Subsize")
701 classes = (
702 MaterialStrandSettings,
706 def register():
707 for cls in classes:
708 register_class(cls)
710 bpy.types.Material.strand = PointerProperty(type=MaterialStrandSettings)
713 def unregister():
714 del bpy.types.Material.strand
716 for cls in reversed(classes):
717 unregister_class(cls)