Import images: add file handler
[blender-addons.git] / render_povray / particles_properties.py
blobcea1fe449d0438104dc45a43c5bf949f09c44bdf
1 # SPDX-FileCopyrightText: 2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """Declare shading properties exported to POV textures."""
6 import bpy
7 from bpy.utils import register_class, unregister_class
8 from bpy.types import PropertyGroup
9 from bpy.props import (
10 StringProperty,
11 BoolProperty,
12 FloatProperty,
13 PointerProperty,
17 class MaterialStrandSettings(PropertyGroup):
18 """Declare strand properties controllable in UI and translated to POV."""
20 bl_description = ("Strand settings for the material",)
22 blend_distance: FloatProperty(
23 name="Distance",
24 description="Worldspace distance over which to blend in the surface normal",
25 min=0.0,
26 max=10.0,
27 soft_min=0.0,
28 soft_max=10.0,
29 default=0.0,
30 precision=3,
33 root_size: FloatProperty(
34 name="Root",
35 description="Start size of strands in pixels or Blender units",
36 min=0.25,
37 default=1.0,
38 precision=5,
41 shape: FloatProperty(
42 name="Shape",
43 description="Positive values make strands rounder, negative ones make strands spiky",
44 min=-0.9,
45 max=0.9,
46 default=0.0,
47 precision=3,
50 size_min: FloatProperty(
51 name="Minimum",
52 description="Minimum size of strands in pixels",
53 min=0.001,
54 max=10.0,
55 default=1.0,
56 precision=3,
59 tip_size: FloatProperty(
60 name="Tip",
61 description="End size of strands in pixels or Blender units",
62 min=0.0,
63 default=1.0,
64 precision=5,
67 use_blender_units: BoolProperty(
68 name="Blender Units",
69 description="Use Blender units for widths instead of pixels",
70 default=False,
73 use_surface_diffuse: BoolProperty(
74 name="Surface diffuse",
75 description="Make diffuse shading more similar to shading the surface",
76 default=False,
79 use_tangent_shading: BoolProperty(
80 name="Tangent Shading",
81 description="Use direction of strands as normal for tangent-shading",
82 default=True,
85 uv_layer: StringProperty(
86 name="UV Layer",
87 # icon="GROUP_UVS",
88 description="Name of UV map to override",
89 default="",
92 width_fade: FloatProperty(
93 name="Width Fade",
94 description="Transparency along the width of the strand",
95 min=0.0,
96 max=2.0,
97 default=0.0,
98 precision=3,
101 # halo
103 # Halo settings for the material
104 # Type: MaterialHalo, (readonly, never None)
107 # darkness
109 # Minnaert darkness
110 # Type: float in [0, 2], default 0.0
112 # diffuse_color
114 # Diffuse color of the material
115 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
117 # diffuse_fresnel
119 # Power of Fresnel
120 # Type: float in [0, 5], default 0.0
122 # diffuse_fresnel_factor
124 # Blending factor of Fresnel
125 # Type: float in [0, 5], default 0.0
127 # diffuse_intensity
129 # Amount of diffuse reflection
130 # Type: float in [0, 1], default 0.0
132 # diffuse_ramp
134 # Color ramp used to affect diffuse shading
135 # Type: ColorRamp, (readonly)
137 # diffuse_ramp_blend
139 # Blending method of the ramp and the diffuse color
140 # 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’
142 # diffuse_ramp_factor
144 # Blending factor (also uses alpha in Colorband)
145 # Type: float in [0, 1], default 0.0
147 # diffuse_ramp_input
149 # How the ramp maps on the surface
150 # Type: enum in [‘SHADER’, ‘ENERGY’, ‘NORMAL’, ‘RESULT’], default ‘SHADER’
152 # diffuse_shader
154 # LAMBERT Lambert, Use a Lambertian shader.
155 # OREN_NAYAR Oren-Nayar, Use an Oren-Nayar shader.
156 # TOON Toon, Use a toon shader.
157 # MINNAERT Minnaert, Use a Minnaert shader.
158 # FRESNEL Fresnel, Use a Fresnel shader.
160 # Type: enum in [‘LAMBERT’, ‘OREN_NAYAR’, ‘TOON’, ‘MINNAERT’, ‘FRESNEL’], default ‘LAMBERT’
162 # diffuse_toon_size
164 # Size of diffuse toon area
165 # Type: float in [0, 3.14], default 0.0
167 # diffuse_toon_smooth
169 # Smoothness of diffuse toon area
170 # Type: float in [0, 1], default 0.0
172 # emit
174 # Amount of light to emit
175 # Type: float in [0, inf], default 0.0
177 # halo
179 # Halo settings for the material
180 # Type: MaterialHalo, (readonly, never None)
182 # invert_z
184 # Render material’s faces with an inverted Z buffer (scanline only)
185 # Type: boolean, default False
187 # light_group
189 # Limit lighting to lamps in this Group
190 # Type: Group
192 # line_color
194 # Line color used for Freestyle line rendering
195 # Type: float array of 4 items in [0, inf], default (0.0, 0.0, 0.0, 0.0)
197 # line_priority
199 # The line color of a higher priority is used at material boundaries
200 # Type: int in [0, 32767], default 0
202 # mirror_color
204 # Mirror color of the material
205 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
207 # node_tree
209 # Node tree for node based materials
210 # Type: NodeTree, (readonly)
212 # offset_z
214 # Give faces an artificial offset in the Z buffer for Z transparency
215 # Type: float in [-inf, inf], default 0.0
217 # paint_active_slot
219 # Index of active texture paint slot
220 # Type: int in [0, 32767], default 0
222 # paint_clone_slot
224 # Index of clone texture paint slot
225 # Type: int in [0, 32767], default 0
227 # pass_index
229 # Index number for the “Material Index” render pass
230 # Type: int in [0, 32767], default 0
232 # physics
234 # Game physics settings
235 # Type: MaterialPhysics, (readonly, never None)
237 # preview_render_type
239 # Type of preview render
241 # FLAT Flat, Flat XY plane.
242 # SPHERE Sphere, Sphere.
243 # CUBE Cube, Cube.
244 # MONKEY Monkey, Monkey.
245 # HAIR Hair, Hair strands.
246 # SPHERE_A World Sphere, Large sphere with sky.
248 # Type: enum in [‘FLAT’, ‘SPHERE’, ‘CUBE’, ‘MONKEY’, ‘HAIR’, ‘SPHERE_A’], default ‘FLAT’
250 # roughness
252 # Oren-Nayar Roughness
253 # Type: float in [0, 3.14], default 0.0
255 # shadow_buffer_bias
257 # Factor to multiply shadow buffer bias with (0 is ignore)
258 # Type: float in [0, 10], default 0.0
260 # shadow_cast_alpha
262 # Shadow casting alpha, in use for Irregular and Deep shadow buffer
263 # Type: float in [0.001, 1], default 0.0
265 # shadow_only_type
267 # How to draw shadows
269 # SHADOW_ONLY_OLD Shadow and Distance, Old shadow only method.
270 # SHADOW_ONLY Shadow Only, Improved shadow only method.
271 # SHADOW_ONLY_SHADED Shadow and Shading, Improved shadow only method which also renders lightless areas as shadows.
273 # Type: enum in [‘SHADOW_ONLY_OLD’, ‘SHADOW_ONLY’, ‘SHADOW_ONLY_SHADED’], default ‘SHADOW_ONLY_OLD’
275 # shadow_ray_bias
277 # Shadow raytracing bias to prevent terminator problems on shadow boundary
278 # Type: float in [0, 0.25], default 0.0
280 # specular_color
282 # Specular color of the material
283 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
285 # specular_hardness
287 # How hard (sharp) the specular reflection is
288 # Type: int in [1, 511], default 0
290 # specular_intensity
292 # How intense (bright) the specular reflection is
293 # Type: float in [0, 1], default 0.0
295 # specular_ior
297 # Specular index of refraction
298 # Type: float in [1, 10], default 0.0
300 # specular_ramp
302 # Color ramp used to affect specular shading
303 # Type: ColorRamp, (readonly)
305 # specular_ramp_blend
307 # Blending method of the ramp and the specular color
308 # 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’
310 # specular_ramp_factor
312 # Blending factor (also uses alpha in Colorband)
313 # Type: float in [0, 1], default 0.0
315 # specular_ramp_input
317 # How the ramp maps on the surface
318 # Type: enum in [‘SHADER’, ‘ENERGY’, ‘NORMAL’, ‘RESULT’], default ‘SHADER’
319 # specular_shader
321 # COOKTORR CookTorr, Use a Cook-Torrance shader.
322 # PHONG Phong, Use a Phong shader.
323 # BLINN Blinn, Use a Blinn shader.
324 # TOON Toon, Use a toon shader.
325 # WARDISO WardIso, Use a Ward anisotropic shader.
327 # Type: enum in [‘COOKTORR’, ‘PHONG’, ‘BLINN’, ‘TOON’, ‘WARDISO’], default ‘COOKTORR’
329 # specular_slope
331 # The standard deviation of surface slope
332 # Type: float in [0, 0.4], default 0.0
334 # specular_toon_size
336 # Size of specular toon area
337 # Type: float in [0, 1.53], default 0.0
339 # specular_toon_smooth
341 # Smoothness of specular toon area
342 # Type: float in [0, 1], default 0.0
344 # strand
346 # Strand settings for the material
347 # Type: MaterialStrand, (readonly, never None)
349 # subsurface_scattering
351 # Subsurface scattering settings for the material
352 # Type: MaterialSubsurfaceScattering, (readonly, never None)
354 # texture_paint_images
356 # Texture images used for texture painting
357 # Type: bpy_prop_collection of Image, (readonly)
359 # texture_paint_slots
361 # Texture slots defining the mapping and influence of textures
362 # Type: bpy_prop_collection of TexPaintSlot, (readonly)
364 # texture_slots
366 # Texture slots defining the mapping and influence of textures
367 # Type: MaterialTextureSlots bpy_prop_collection of MaterialTextureSlot, (readonly)
369 # type
371 # Material type defining how the object is rendered
373 # SURFACE Surface, Render object as a surface.
374 # WIRE Wire, Render the edges of faces as wires (not supported in raytracing).
375 # VOLUME Volume, Render object as a volume.
376 # HALO Halo, Render object as halo particles.
378 # Type: enum in [‘SURFACE’, ‘WIRE’, ‘VOLUME’, ‘HALO’], default ‘SURFACE’
380 # use_cast_shadows
382 # Allow this material to cast shadows
383 # Type: boolean, default False
385 # use_cast_shadows_only
387 # Make objects with this material appear invisible (not rendered), only casting shadows
388 # Type: boolean, default False
390 # use_cubic
392 # Use cubic interpolation for diffuse values, for smoother transitions
393 # Type: boolean, default False
395 # use_diffuse_ramp
397 # Toggle diffuse ramp operations
398 # Type: boolean, default False
400 # use_face_texture
402 # Replace the object’s base color with color from UV map image textures
403 # Type: boolean, default False
405 # use_face_texture_alpha
407 # Replace the object’s base alpha value with alpha from UV map image textures
408 # Type: boolean, default False
410 # use_full_oversampling
412 # Force this material to render full shading/textures for all anti-aliasing samples
413 # Type: boolean, default False
415 # use_light_group_exclusive
417 # Material uses the light group exclusively - these lamps are excluded from other scene lighting
418 # Type: boolean, default False
420 # use_light_group_local
422 # When linked in, material uses local light group with the same name
423 # Type: boolean, default False
425 # use_mist
427 # Use mist with this material (in world settings)
428 # Type: boolean, default False
430 # use_nodes
432 # Use shader nodes to render the material
433 # Type: boolean, default False
435 # use_object_color
437 # Modulate the result with a per-object color
438 # Type: boolean, default False
440 # use_only_shadow
442 # Render shadows as the material’s alpha value, making the material transparent except for shadowed areas
443 # Type: boolean, default False
445 # use_ray_shadow_bias
447 # Prevent raytraced shadow errors on surfaces with smooth shaded normals (terminator problem)
448 # Type: boolean, default False
450 # use_raytrace
452 # Include this material and geometry that uses it in raytracing calculations
453 # Type: boolean, default False
455 # use_shadeless
457 # Make this material insensitive to light or shadow
458 # Type: boolean, default False
460 # use_shadows
462 # Allow this material to receive shadows
463 # Type: boolean, default False
465 # use_sky
467 # Render this material with zero alpha, with sky background in place (scanline only)
468 # Type: boolean, default False
470 # use_specular_ramp
472 # Toggle specular ramp operations
473 # Type: boolean, default False
475 # use_tangent_shading
477 # Use the material’s tangent vector instead of the normal for shading - for anisotropic shading effects
478 # Type: boolean, default False
480 # use_textures
482 # Enable/Disable each texture
483 # 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)
485 # use_transparency
487 # Render material as transparent
488 # Type: boolean, default False
490 # use_transparent_shadows
492 # Allow this object to receive transparent shadows cast through other objects
493 # Type: boolean, default False
495 # use_uv_project
497 # Use to ensure UV interpolation is correct for camera projections (use with UV project modifier)
498 # Type: boolean, default False
500 # use_vertex_color_light
502 # Add vertex colors as additional lighting
503 # Type: boolean, default False
505 # use_vertex_color_paint
507 # Replace object base color with vertex colors (multiply with ‘texture face’ face assigned textures)
508 # Type: boolean, default False
510 # volume
512 # Volume settings for the material
513 # Type: MaterialVolume, (readonly, never None)
515 (mat.type in {'SURFACE', 'WIRE', 'VOLUME'})
516 "use_transparency")
520 mat.use_transparency and mat.pov.transparency_method == 'Z_TRANSPARENCY'
525 col.prop(mat, "use_raytrace")
526 col.prop(mat, "use_full_oversampling")
528 sub.prop(mat, "use_sky")
531 col.prop(mat, "use_cast_shadows", text="Cast")
532 col.prop(mat, "use_cast_shadows_only", text="Cast Only")
533 col.prop(mat, "use_cast_buffer_shadows")
535 sub.active = mat.use_cast_buffer_shadows
536 sub.prop(mat, "shadow_cast_alpha", text="Casting Alpha")
537 col.prop(mat, "use_cast_approximate")
541 col.prop(mat, "diffuse_color", text="")
543 sub.active = (not mat.use_shadeless)
545 sub.prop(mat, "diffuse_intensity", text="Intensity")
548 col.prop(mat, "diffuse_shader", text="")
549 col.prop(mat, "use_diffuse_ramp", text="Ramp")
552 if mat.diffuse_shader == 'OREN_NAYAR':
553 col.prop(mat, "roughness")
554 elif mat.diffuse_shader == 'MINNAERT':
555 col.prop(mat, "darkness")
556 elif mat.diffuse_shader == 'TOON':
558 row.prop(mat, "diffuse_toon_size", text="Size")
559 row.prop(mat, "diffuse_toon_smooth", text="Smooth")
560 elif mat.diffuse_shader == 'FRESNEL':
562 row.prop(mat, "diffuse_fresnel", text="Fresnel")
563 row.prop(mat, "diffuse_fresnel_factor", text="Factor")
565 if mat.use_diffuse_ramp:
567 col.template_color_ramp(mat, "diffuse_ramp", expand=True)
571 row.prop(mat, "diffuse_ramp_input", text="Input")
572 row.prop(mat, "diffuse_ramp_blend", text="Blend")
574 col.prop(mat, "diffuse_ramp_factor", text="Factor")
579 col.prop(mat, "specular_color", text="")
580 col.prop(mat, "specular_intensity", text="Intensity")
582 col.prop(mat, "specular_shader", text="")
583 col.prop(mat, "use_specular_ramp", text="Ramp")
585 if mat.pov.specular_shader in {'COOKTORR', 'PHONG'}:
586 col.prop(mat, "specular_hardness", text="Hardness")
587 elif mat.pov.specular_shader == 'BLINN':
589 row.prop(mat, "specular_hardness", text="Hardness")
590 row.prop(mat, "specular_ior", text="IOR")
591 elif mat.pov.specular_shader == 'WARDISO':
592 col.prop(mat, "specular_slope", text="Slope")
593 elif mat.pov.specular_shader == 'TOON':
595 row.prop(mat, "specular_toon_size", text="Size")
596 row.prop(mat, "specular_toon_smooth", text="Smooth")
598 if mat.use_specular_ramp:
599 layout.separator()
600 layout.template_color_ramp(mat, "specular_ramp", expand=True)
601 layout.separator()
603 row = layout.row()
604 row.prop(mat, "specular_ramp_input", text="Input")
605 row.prop(mat, "specular_ramp_blend", text="Blend")
607 layout.prop(mat, "specular_ramp_factor", text="Factor")
610 XXX remove unused props and relayout as done for transparent sky
613 class MATERIAL_PT_halo(MaterialButtonsPanel, Panel):
614 bl_label = "Halo"
615 COMPAT_ENGINES = {'BLENDER_RENDER'}
617 @classmethod
618 def poll(cls, context):
619 mat = context.material
620 engine = context.scene.render.engine
621 return mat and (mat.type == 'HALO') and (engine in cls.COMPAT_ENGINES)
623 def draw(self, context):
624 layout = self.layout
626 mat = context.material # don't use node material
627 halo = mat.pov.halo
629 def number_but(layout, toggle, number, name, color):
630 row = layout.row(align=True)
631 row.prop(halo, toggle, text="")
632 sub = row.column(align=True)
633 sub.active = getattr(halo, toggle)
634 sub.prop(halo, number, text=name, translate=False)
635 if not color == "":
636 sub.prop(mat, color, text="")
638 split = layout.split()
640 col = split.column()
641 col.prop(mat, "alpha")
642 col.prop(mat, "diffuse_color", text="")
643 col.prop(halo, "seed")
645 col = split.column()
646 col.prop(halo, "size")
647 col.prop(halo, "hardness")
648 col.prop(halo, "add")
650 layout.label(text="Options:")
652 split = layout.split()
653 col = split.column()
654 col.prop(halo, "use_texture")
655 col.prop(halo, "use_vertex_normal")
656 col.prop(halo, "use_extreme_alpha")
657 col.prop(halo, "use_shaded")
658 col.prop(halo, "use_soft")
660 col = split.column()
661 number_but(col, "use_ring", "ring_count", iface_("Rings"), "mirror_color")
662 number_but(col, "use_lines", "line_count", iface_("Lines"), "specular_color")
663 number_but(col, "use_star", "star_tip_count", iface_("Star Tips"), "")
666 class MATERIAL_PT_flare(MaterialButtonsPanel, Panel):
667 bl_label = "Flare"
668 COMPAT_ENGINES = {'BLENDER_RENDER'}
670 @classmethod
671 def poll(cls, context):
672 mat = context.material
673 engine = context.scene.render.engine
674 return mat and (mat.type == 'HALO') and (engine in cls.COMPAT_ENGINES)
676 def draw_header(self, context):
677 halo = context.material.pov.halo
679 self.layout.prop(halo, "use_flare_mode", text="")
681 def draw(self, context):
682 layout = self.layout
684 mat = context.material # don't use node material
685 halo = mat.pov.halo
687 layout.active = halo.use_flare_mode
689 split = layout.split()
691 col = split.column()
692 col.prop(halo, "flare_size", text="Size")
693 col.prop(halo, "flare_boost", text="Boost")
694 col.prop(halo, "flare_seed", text="Seed")
696 col = split.column()
697 col.prop(halo, "flare_subflare_count", text="Subflares")
698 col.prop(halo, "flare_subflare_size", text="Subsize")
703 classes = (
704 MaterialStrandSettings,
708 def register():
709 for cls in classes:
710 register_class(cls)
712 bpy.types.Material.strand = PointerProperty(type=MaterialStrandSettings)
715 def unregister():
716 del bpy.types.Material.strand
718 for cls in reversed(classes):
719 unregister_class(cls)