Adopt Shapespark vegetation assets
This commit is contained in:
1 parent
cd9cde0127
commit
dbb5705d8e
135 files changed
+9401
-737
No files matched your search
+46
-25
@@ -37,15 +37,13 @@ FOLIAGE_EMISSION = 0.25
|
||||
|
||||
# Multiplier on a cut-out foliage albedo before export.
|
||||
#
|
||||
# This is the knob that actually controls how dark the trees read, and it
|
||||
# exists because the apple atlas is genuinely dark: its green texels average
|
||||
# sRGB (0.249, 0.35, 0.12), a deep forest green, and the bark is darker still.
|
||||
# Rendered at true albedo that is correct — but nothing else in this scene is
|
||||
# at true albedo. Every other material goes through Cesium export contracts
|
||||
# (grass mixes 72% toward a bright green, the ribbed facade 86% toward white,
|
||||
# 0.18 emission on the buildings), all hand-tuned against Cesium's washed-out
|
||||
# default lighting. A new asset dropped in untuned is the one thing rendering
|
||||
# honestly, and next to the rest it reads as black.
|
||||
# This legacy profile exists for dark alpha-cut foliage from older .blend files.
|
||||
# Rendered at true albedo those assets are correct, but nothing else in this
|
||||
# scene is at true albedo. Every other material goes through Cesium export
|
||||
# contracts (grass mixes 72% toward a bright green, the ribbed facade 86% toward
|
||||
# white, 0.18 emission on the buildings), all hand-tuned against Cesium's
|
||||
# washed-out default lighting. A new asset dropped in untuned is the one thing
|
||||
# rendering honestly, and next to the rest it reads as black.
|
||||
#
|
||||
# A gain rather than a tint, because a tint is what the other materials use and
|
||||
# it is wrong here: they are single-surface, this is an atlas holding leaves,
|
||||
@@ -56,15 +54,26 @@ FOLIAGE_ALBEDO_GAIN = 2.1
|
||||
|
||||
# Saturation multiplier applied with the gain, around each texel's own
|
||||
# luminance. The gain alone lifts the crown to the right brightness but leaves
|
||||
# it reading grey-green at distance: this atlas is desaturated to begin with
|
||||
# (mean saturation 0.22), and mip-averaging a crown mixes leaves with bark and
|
||||
# sky-gaps, pulling it further toward neutral exactly when the tree gets small.
|
||||
# it reading grey-green at distance: alpha-cut atlases are often desaturated to
|
||||
# begin with, and mip-averaging a crown mixes leaves with bark and sky-gaps,
|
||||
# pulling it further toward neutral exactly when the tree gets small.
|
||||
#
|
||||
# Scaling the distance from luminance pushes the leaves green without touching
|
||||
# what is already neutral much, and without the hue shift a green tint would
|
||||
# force on the trunk — bark just becomes a warmer brown, which it should be.
|
||||
FOLIAGE_SATURATION = 1.75
|
||||
|
||||
# Shapespark foliage is already graded brighter than legacy cut-out foliage.
|
||||
# Reusing the heavy gain/saturation/emission makes it read yellow-green and
|
||||
# glowing in Cesium, so these card materials get a gentler export profile.
|
||||
SHAPESPARK_FOLIAGE_ALBEDO_GAIN = 1.12
|
||||
SHAPESPARK_FOLIAGE_SATURATION = 1.0
|
||||
SHAPESPARK_FOLIAGE_EMISSION = 0.06
|
||||
SHAPESPARK_FOLIAGE_PREFIXES = (
|
||||
"branch-", "shrubbery-", "high-grass-", "hedge-",
|
||||
"clover-", "flowers-",
|
||||
)
|
||||
|
||||
# Legacy fallback for .blend files created before materials carried their own
|
||||
# `cesium_export` custom property. New scenes should get these values from
|
||||
# catalog.MATERIALS[*]["cesium"], serialized by osmassets.materials.from_spec().
|
||||
@@ -184,11 +193,11 @@ def source_alpha_clipped(material):
|
||||
"""Whether the source material carries its silhouette in a texture alpha.
|
||||
|
||||
Two conditions, because either alone gives a wrong answer. A link into the
|
||||
Principled Alpha input is not enough: shrub_02 arrives from glTF with a
|
||||
Math node wired there even though its JPEG diffuse is opaque, and taking
|
||||
that at face value re-encodes an opaque texture as a PNG and makes Cesium
|
||||
alpha-test 270 tufts for nothing. An alpha channel alone is not enough
|
||||
either: fat_tree.png is RGBA with every texel at 1.0.
|
||||
Principled Alpha input is not enough: retired glTF lawn assets arrived with
|
||||
a Math node wired there even though the JPEG diffuse was opaque, and taking
|
||||
that at face value re-encoded an opaque texture as a PNG and made Cesium
|
||||
alpha-test hundreds of tufts for nothing. An alpha channel alone is not
|
||||
enough either; it can be fully opaque.
|
||||
|
||||
So ask both — the author wired alpha, and the texture actually cuts.
|
||||
"""
|
||||
@@ -201,6 +210,17 @@ def source_alpha_clipped(material):
|
||||
return diffuse is not None and image_has_cutout(diffuse)
|
||||
|
||||
|
||||
def foliage_export_profile(material):
|
||||
name = material.name.lower()
|
||||
if name.startswith(SHAPESPARK_FOLIAGE_PREFIXES):
|
||||
return (
|
||||
SHAPESPARK_FOLIAGE_ALBEDO_GAIN,
|
||||
SHAPESPARK_FOLIAGE_SATURATION,
|
||||
SHAPESPARK_FOLIAGE_EMISSION,
|
||||
)
|
||||
return FOLIAGE_ALBEDO_GAIN, FOLIAGE_SATURATION, FOLIAGE_EMISSION
|
||||
|
||||
|
||||
_CUTOUT_CACHE = {}
|
||||
|
||||
|
||||
@@ -253,12 +273,12 @@ def alpha_dilated_image(source, name, threshold=0.5, passes=8, gain=1.0,
|
||||
saturation=1.0):
|
||||
"""Flood the opaque colour outward underneath the cut-out, and lift it.
|
||||
|
||||
SpeedTree writes pure black wherever a leaf card is cut away — 97% of the
|
||||
apple atlas's transparent area is exactly (0, 0, 0). An alpha mask hides
|
||||
that at full resolution, but Cesium mip-maps the texture and every mip
|
||||
level averages those black texels into the leaf edges, so the crown grows a
|
||||
dark fringe that thickens with distance. Blender's preview renders at mip
|
||||
0 and never shows it, which is why this only surfaces in the viewer.
|
||||
Some legacy leaf-card atlases write pure black wherever a card is cut away.
|
||||
An alpha mask hides that at full resolution, but Cesium mip-maps the texture
|
||||
and every mip level averages those black texels into the leaf edges, so the
|
||||
crown grows a dark fringe that thickens with distance. Blender's preview
|
||||
renders at mip 0 and never shows it, which is why this only surfaces in the
|
||||
viewer.
|
||||
|
||||
Replacing the colour under the cut-out with its nearest opaque neighbours
|
||||
leaves no black to bleed. Alpha is copied through untouched, so the
|
||||
@@ -385,6 +405,7 @@ def make_export_material(material):
|
||||
# Foliage that carries its silhouette in the texture's alpha has to keep
|
||||
# that channel; every other material is flattened to opaque below.
|
||||
alpha_clipped = source_alpha_clipped(material)
|
||||
foliage_gain, foliage_saturation, foliage_emission = foliage_export_profile(material)
|
||||
if material.name == "Tree Crown":
|
||||
diffuse = tree_crown_image()
|
||||
else:
|
||||
@@ -394,7 +415,7 @@ def make_export_material(material):
|
||||
safe_name = material.name.replace(" ", "_")
|
||||
diffuse = alpha_dilated_image(
|
||||
diffuse, f"{EXPORT_PREFIX}{safe_name} Dilated",
|
||||
gain=FOLIAGE_ALBEDO_GAIN, saturation=FOLIAGE_SATURATION)
|
||||
gain=foliage_gain, saturation=foliage_saturation)
|
||||
if has_base_color_override:
|
||||
diffuse = None
|
||||
normal = None
|
||||
@@ -454,7 +475,7 @@ def make_export_material(material):
|
||||
elif "Emission" in bsdf.inputs:
|
||||
links.new(diffuse_node.outputs["Color"], bsdf.inputs["Emission"])
|
||||
if "Emission Strength" in bsdf.inputs:
|
||||
bsdf.inputs["Emission Strength"].default_value = FOLIAGE_EMISSION
|
||||
bsdf.inputs["Emission Strength"].default_value = foliage_emission
|
||||
elif "Alpha" in bsdf.inputs:
|
||||
bsdf.inputs["Alpha"].default_value = 1.0
|
||||
return result
|
||||
|
||||
Reference in new issue
Block a user