Drive parallax height and relief from the painted occlusion channel
Reuse the existing occlusion paint channel (no new map, MAP_COUNT stays 3): 0.5 is neutral, above 0.5 raises a hill, below 0.5 sinks a hole and also fades ambient occlusion (saturate(2*occ)). Bind the MSO map to _ParallaxMap, enable _PARALLAXMAP, derive a relief normal from the height gradient, and reseed unpainted occlusion to 0.5 so untouched surfaces stay visually neutral. Pin the _PARALLAXMAP runtime variant in the build keep-alive material. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
e349446fb7
commit
fdcb4f8d8a
6 files changed
+78
-13
No files matched your search
@@ -148,12 +148,14 @@ public partial class MeshPainter
|
||||
_seedCanonical = new Color32[MAP_COUNT][];
|
||||
_seedCanonical[MAP_ALBEDO] = BuildBaseColors();
|
||||
|
||||
// Mask map seed from the material scalars: R = metallic, G = occlusion (255 =
|
||||
// unoccluded, so the look is unchanged until painted), B = 0, A = smoothness.
|
||||
// Mask map seed from the material scalars: R = metallic, G = occlusion/height, B = 0,
|
||||
// A = smoothness. G = 128 (= 0.5) is the NEUTRAL height: no parallax/relief and AO =
|
||||
// saturate(2*0.5) = 1 (no darkening), so the unpainted look is unchanged. Painting G
|
||||
// below 0.5 carves a hole (and darkens), above 0.5 raises a hill (see PlayerCamoLit).
|
||||
float metallic0 = _materialInstance.HasProperty(MetallicId) ? _materialInstance.GetFloat(MetallicId) : 0f;
|
||||
float smoothness0 = _materialInstance.HasProperty(SmoothnessId) ? _materialInstance.GetFloat(SmoothnessId) : 0.5f;
|
||||
_seedCanonical[MAP_MSO] = FillCanonical(new Color32(
|
||||
(byte)(Mathf.Clamp01(metallic0) * 255f), 255, 0, (byte)(Mathf.Clamp01(smoothness0) * 255f)));
|
||||
(byte)(Mathf.Clamp01(metallic0) * 255f), 128, 0, (byte)(Mathf.Clamp01(smoothness0) * 255f)));
|
||||
|
||||
// Emission: keep the existing look (black if the material's emission is off).
|
||||
Color emission0 = Color.black;
|
||||
@@ -232,6 +234,18 @@ public partial class MeshPainter
|
||||
_materialInstance.EnableKeyword("_OCCLUSIONMAP");
|
||||
if (_materialInstance.HasProperty(OcclusionStrengthId)) _materialInstance.SetFloat(OcclusionStrengthId, 1f);
|
||||
}
|
||||
|
||||
// Height: the same mask map is also bound to _ParallaxMap (see MapProps), so the painted
|
||||
// occlusion value (G) doubles as a 0.5-centred height. _PARALLAXMAP turns on URP's single-
|
||||
// step parallax (ApplyPerPixelDisplacement) AND our relief-normal/AO remap in PlayerCamoLit.
|
||||
// Lift _Parallax off its floor so the displacement is actually visible (the relief normal is
|
||||
// the dominant cue; this just adds subtle motion parallax). Live-tunable on the instance.
|
||||
if (_materialInstance.HasProperty(ParallaxMapId))
|
||||
{
|
||||
_materialInstance.EnableKeyword("_PARALLAXMAP");
|
||||
if (_materialInstance.HasProperty(ParallaxId) && _materialInstance.GetFloat(ParallaxId) < 0.02f)
|
||||
_materialInstance.SetFloat(ParallaxId, 0.02f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Pushes the global emission intensity to the material's _EmissionColor (live-tunable).</summary>
|
||||
|
||||
Reference in new issue
Block a user