1 # SPDX-FileCopyrightText: 2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 """Declare shading properties exported to POV textures."""
7 from bpy
.utils
import register_class
, unregister_class
8 from bpy
.types
import PropertyGroup
9 from bpy
.props
import (
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(
24 description
="Worldspace distance over which to blend in the surface normal",
33 root_size
: FloatProperty(
35 description
="Start size of strands in pixels or Blender units",
43 description
="Positive values make strands rounder, negative ones make strands spiky",
50 size_min
: FloatProperty(
52 description
="Minimum size of strands in pixels",
59 tip_size
: FloatProperty(
61 description
="End size of strands in pixels or Blender units",
67 use_blender_units
: BoolProperty(
69 description
="Use Blender units for widths instead of pixels",
73 use_surface_diffuse
: BoolProperty(
74 name
="Surface diffuse",
75 description
="Make diffuse shading more similar to shading the surface",
79 use_tangent_shading
: BoolProperty(
80 name
="Tangent Shading",
81 description
="Use direction of strands as normal for tangent-shading",
85 uv_layer
: StringProperty(
88 description
="Name of UV map to override",
92 width_fade
: FloatProperty(
94 description
="Transparency along the width of the strand",
103 # Halo settings for the material
104 # Type: MaterialHalo, (readonly, never None)
110 # Type: float in [0, 2], default 0.0
114 # Diffuse color of the material
115 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
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
129 # Amount of diffuse reflection
130 # Type: float in [0, 1], default 0.0
134 # Color ramp used to affect diffuse shading
135 # Type: ColorRamp, (readonly)
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
149 # How the ramp maps on the surface
150 # Type: enum in [‘SHADER’, ‘ENERGY’, ‘NORMAL’, ‘RESULT’], default ‘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’
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
174 # Amount of light to emit
175 # Type: float in [0, inf], default 0.0
179 # Halo settings for the material
180 # Type: MaterialHalo, (readonly, never None)
184 # Render material’s faces with an inverted Z buffer (scanline only)
185 # Type: boolean, default False
189 # Limit lighting to lamps in this Group
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)
199 # The line color of a higher priority is used at material boundaries
200 # Type: int in [0, 32767], default 0
204 # Mirror color of the material
205 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
209 # Node tree for node based materials
210 # Type: NodeTree, (readonly)
214 # Give faces an artificial offset in the Z buffer for Z transparency
215 # Type: float in [-inf, inf], default 0.0
219 # Index of active texture paint slot
220 # Type: int in [0, 32767], default 0
224 # Index of clone texture paint slot
225 # Type: int in [0, 32767], default 0
229 # Index number for the “Material Index” render pass
230 # Type: int in [0, 32767], default 0
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.
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’
252 # Oren-Nayar Roughness
253 # Type: float in [0, 3.14], default 0.0
257 # Factor to multiply shadow buffer bias with (0 is ignore)
258 # Type: float in [0, 10], default 0.0
262 # Shadow casting alpha, in use for Irregular and Deep shadow buffer
263 # Type: float in [0.001, 1], default 0.0
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’
277 # Shadow raytracing bias to prevent terminator problems on shadow boundary
278 # Type: float in [0, 0.25], default 0.0
282 # Specular color of the material
283 # Type: float array of 3 items in [0, inf], default (0.0, 0.0, 0.0)
287 # How hard (sharp) the specular reflection is
288 # Type: int in [1, 511], default 0
292 # How intense (bright) the specular reflection is
293 # Type: float in [0, 1], default 0.0
297 # Specular index of refraction
298 # Type: float in [1, 10], default 0.0
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’
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’
331 # The standard deviation of surface slope
332 # Type: float in [0, 0.4], default 0.0
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
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)
366 # Texture slots defining the mapping and influence of textures
367 # Type: MaterialTextureSlots bpy_prop_collection of MaterialTextureSlot, (readonly)
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’
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
392 # Use cubic interpolation for diffuse values, for smoother transitions
393 # Type: boolean, default False
397 # Toggle diffuse ramp operations
398 # Type: boolean, default False
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
427 # Use mist with this material (in world settings)
428 # Type: boolean, default False
432 # Use shader nodes to render the material
433 # Type: boolean, default False
437 # Modulate the result with a per-object color
438 # Type: boolean, default False
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
452 # Include this material and geometry that uses it in raytracing calculations
453 # Type: boolean, default False
457 # Make this material insensitive to light or shadow
458 # Type: boolean, default False
462 # Allow this material to receive shadows
463 # Type: boolean, default False
467 # Render this material with zero alpha, with sky background in place (scanline only)
468 # Type: boolean, default False
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
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)
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
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
512 # Volume settings for the material
513 # Type: MaterialVolume, (readonly, never None)
515 (mat.type in {'SURFACE', 'WIRE', 'VOLUME'})
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:
600 layout.template_color_ramp(mat, "specular_ramp", expand=True)
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):
615 COMPAT_ENGINES = {'BLENDER_RENDER'}
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):
626 mat = context.material # don't use node material
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)
636 sub.prop(mat, color, text="")
638 split = layout.split()
641 col.prop(mat, "alpha")
642 col.prop(mat, "diffuse_color", text="")
643 col.prop(halo, "seed")
646 col.prop(halo, "size")
647 col.prop(halo, "hardness")
648 col.prop(halo, "add")
650 layout.label(text="Options:")
652 split = layout.split()
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")
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):
668 COMPAT_ENGINES = {'BLENDER_RENDER'}
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):
684 mat = context.material # don't use node material
687 layout.active = halo.use_flare_mode
689 split = layout.split()
692 col.prop(halo, "flare_size", text="Size")
693 col.prop(halo, "flare_boost", text="Boost")
694 col.prop(halo, "flare_seed", text="Seed")
697 col.prop(halo, "flare_subflare_count", text="Subflares")
698 col.prop(halo, "flare_subflare_size", text="Subsize")
704 MaterialStrandSettings
,
712 bpy
.types
.Material
.strand
= PointerProperty(type=MaterialStrandSettings
)
716 del bpy
.types
.Material
.strand
718 for cls
in reversed(classes
):
719 unregister_class(cls
)