render_povray :

First try at fixing hair and strand for 2.8 render API: failed but improved
This commit is contained in:
Maurice Raybaud 2019-09-02 00:26:53 +02:00
parent cbb11b1a59
commit 86d2637065
3 changed files with 121 additions and 8 deletions

View File

@ -1714,7 +1714,62 @@ class MaterialSubsurfaceScattering(PropertyGroup):
name="Texture",
description="Texture scattering blend factor",
min=0.0, max=1.0, soft_min=0.0, soft_max=1.0, default=0.0, precision=3)
class MaterialStrandSettings(PropertyGroup):
bl_description = "Strand settings for the material",
blend_distance: FloatProperty(
name="Distance",
description="Worldspace distance over which to blend in the surface normal",
min=0.0, max=10.0, soft_min=0.0, soft_max=10.0, default=0.0, precision=3)
root_size: FloatProperty(
name="Root",
description="Start size of strands in pixels or Blender units",
min=0.25, default=1.0, precision=5)
shape: FloatProperty(
name="Shape",
description="Positive values make strands rounder, negative ones make strands spiky",
min=-0.9, max=0.9, default=0.0, precision=3)
size_min: FloatProperty(
name="Minimum",
description="Minimum size of strands in pixels",
min=0.001, max=10.0, default=1.0, precision=3)
tip_size: FloatProperty(
name="Tip",
description="End size of strands in pixels or Blender units",
min=0.0, default=1.0, precision=5)
use_blender_units: BoolProperty(
name="Blender Units",
description="Use Blender units for widths instead of pixels",
default=False)
use_surface_diffuse: BoolProperty(
name="Surface diffuse",
description="Make diffuse shading more similar to shading the surface",
default=False)
use_tangent_shading: BoolProperty(
name="Tangent Shading",
description="Use direction of strands as normal for tangent-shading",
default=True)
uv_layer: StringProperty(
name="UV Layer",
#icon="GROUP_UVS",
description="Name of UV map to override",
default="")
width_fade: FloatProperty(
name="Width Fade",
description="Transparency along the width of the strand",
min=0.0, max=2.0, default=0.0, precision=3)
# halo
# Halo settings for the material
@ -4295,6 +4350,7 @@ classes = (
MaterialRaytraceTransparency,
MaterialRaytraceMirror,
MaterialSubsurfaceScattering,
MaterialStrandSettings,
RenderPovSettingsObject,
RenderPovSettingsScene,
RenderPovSettingsText,
@ -4334,6 +4390,7 @@ def register():
bpy.types.Material.pov_raytrace_transparency = PointerProperty(type=MaterialRaytraceTransparency)
bpy.types.Material.pov = PointerProperty(type=RenderPovSettingsMaterial)
bpy.types.Material.pov_subsurface_scattering = PointerProperty(type=MaterialSubsurfaceScattering)
bpy.types.Material.strand = PointerProperty(type= MaterialStrandSettings)
bpy.types.Material.pov_raytrace_mirror = PointerProperty(type=MaterialRaytraceMirror)
bpy.types.Texture.pov = PointerProperty(type=RenderPovSettingsTexture)
bpy.types.Object.pov = PointerProperty(type=RenderPovSettingsObject)
@ -4350,6 +4407,7 @@ def unregister():
del bpy.types.Scene.pov
del bpy.types.Material.pov
del bpy.types.Material.pov_subsurface_scattering
del bpy.types.Material.strand
del bpy.types.Material.pov_raytrace_mirror
del bpy.types.Material.pov_raytrace_transparency
#del bpy.types.Modifier.pov

View File

@ -2113,11 +2113,16 @@ def write_pov(filename, scene=None, info_callback=None):
strandEnd = 0.01
strandShape = 0.0
# Set the number of particles to render count rather than 3d view display
pSys.set_resolution(scene, ob, 'RENDER')
#pSys.set_resolution(scene, ob, 'RENDER') # DEPRECATED
# When you render, the entire dependency graph will be
# evaluated at render resolution, including the particles.
# In the viewport it will be at viewport resolution.
# So there is no need fo render engines to use this function anymore,
# it's automatic now.
steps = pSys.settings.display_step
steps = 3 ** steps # or (power of 2 rather than 3) + 1 # Formerly : len(particle.hair_keys)
totalNumberOfHairs = ( len(pSys.particles) + len(pSys.child_particles) )
totalNumberOfHairs = ( pSys.settings.count + pSys.settings.rendered_child_count )
#hairCounter = 0
file.write('#declare HairArray = array[%i] {\n' % totalNumberOfHairs)
for pindex in range(0, totalNumberOfHairs):
@ -2135,7 +2140,7 @@ def write_pov(filename, scene=None, info_callback=None):
file.write('linear_spline ')
file.write('%i,\n' % (steps))
#changing world coordinates to object local coordinates by multiplying with inverted matrix
initCo = ob.matrix_world.inverted()*(pSys.co_hair(ob, pindex, 0))
initCo = ob.matrix_world.inverted() @ (pSys.co_hair(ob, particle_no = pindex, step = 0))
if ob.material_slots[pSys.settings.material - 1].material and ob.active_material is not None:
pmaterial = ob.material_slots[pSys.settings.material-1].material
for th in pmaterial.texture_slots:
@ -2159,7 +2164,7 @@ def write_pov(filename, scene=None, info_callback=None):
#only overwrite variable for each competing texture for now
initColor=th.texture.evaluate((initCo[0],initCo[1],initCo[2]))
for step in range(0, steps):
co = ob.matrix_world.inverted()*(pSys.co_hair(ob, pindex, step))
co = ob.matrix_world.inverted() @ (pSys.co_hair(ob, particle_no = pindex, step = step))
#for controlPoint in particle.hair_keys:
if pSys.settings.clump_factor != 0:
hDiameter = pSys.settings.clump_factor / 200.0 * random.uniform(0.5, 1)
@ -2256,8 +2261,12 @@ def write_pov(filename, scene=None, info_callback=None):
print('Number of tufts (particle systems)', len(ob.particle_systems))
# Set back the displayed number of particles to preview count
pSys.set_resolution(scene, ob, 'PREVIEW')
# pSys.set_resolution(scene, ob, 'PREVIEW') #DEPRECATED
# When you render, the entire dependency graph will be
# evaluated at render resolution, including the particles.
# In the viewport it will be at viewport resolution.
# So there is no need fo render engines to use this function anymore,
# it's automatic now.
if renderEmitter == False:
continue #don't render mesh, skip to next object.

View File

@ -1390,7 +1390,7 @@ class MATERIAL_PT_POV_sss(MaterialButtonsPanel, Panel):
sub.prop(sss, "back")
col.separator()
col.prop(sss, "error_threshold", text="Error")
class MATERIAL_PT_povray_activate_node(MaterialButtonsPanel, Panel):
bl_label = "Activate Node Settings"
bl_context = "material"
@ -1715,7 +1715,52 @@ class MATERIAL_PT_povray_caustics(MaterialButtonsPanel, Panel):
col.label(text="Caustics override is on, ")
col.label(text="but you didn't chose any !")
class MATERIAL_PT_strand(MaterialButtonsPanel, Panel):
bl_label = "Strand"
bl_options = {'DEFAULT_CLOSED'}
COMPAT_ENGINES = {'POVRAY_RENDER'}
@classmethod
def poll(cls, context):
mat = context.material
engine = context.scene.render.engine
return mat and (mat.type in {'SURFACE', 'WIRE', 'HALO'}) and (engine in cls.COMPAT_ENGINES)
def draw(self, context):
layout = self.layout
mat = context.material # don't use node material
tan = mat.strand
split = layout.split()
col = split.column()
sub = col.column(align=True)
sub.label(text="Size:")
sub.prop(tan, "root_size", text="Root")
sub.prop(tan, "tip_size", text="Tip")
sub.prop(tan, "size_min", text="Minimum")
sub.prop(tan, "use_blender_units")
sub = col.column()
sub.active = (not mat.pov.use_shadeless)
sub.prop(tan, "use_tangent_shading")
col.prop(tan, "shape")
col = split.column()
col.label(text="Shading:")
col.prop(tan, "width_fade")
ob = context.object
if ob and ob.type == 'MESH':
col.prop_search(tan, "uv_layer", ob.data, "uv_textures", text="")
else:
col.prop(tan, "uv_layer", text="")
col.separator()
sub = col.column()
sub.active = (not mat.pov.use_shadeless)
sub.label("Surface diffuse:")
sub = col.column()
sub.prop(tan, "blend_distance", text="Distance")
class MATERIAL_PT_povray_replacement_text(MaterialButtonsPanel, Panel):
bl_label = "Custom POV Code"
COMPAT_ENGINES = {'POVRAY_RENDER'}
@ -3154,6 +3199,7 @@ classes = (
MATERIAL_PT_POV_sss,
MATERIAL_MT_POV_sss_presets,
AddPresetSSS,
MATERIAL_PT_strand,
MATERIAL_PT_povray_activate_node,
MATERIAL_PT_povray_active_node,
MATERIAL_PT_POV_mirror,