Expose the camo knobs in the HUD, persist and replicate them
Surface the PlayerCamoLit material knobs (HalfLambert, HalfLambert brightness, specular dampen) as material-backed properties on MeshPainter, guarded by an IsReady gate since the HUD binds before the material instance exists. Wire the three HUD sliders to them and seed the sliders from the live material once the painter is ready. Persist the values into the same HUD JSON as the brush settings (with a hasCamoValues flag so pre-camo save files never clobber the authored material) and carry them across a scene-switch respawn. Replicate them owner-authoritatively via a NetworkVariable in PlayerPaintSync, exactly like emission intensity, so remotes and late joiners show the same camo. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
b5bd1fdb8b
commit
7c84f6ba92
4 files changed
+187
-1
No files matched your search
@@ -56,6 +56,41 @@ public partial class MeshPainter : MonoBehaviour
|
||||
/// the pre-spawn window, a remote replica, or any binding gap - never paints from local input.</summary>
|
||||
public bool PaintingEnabled { get; set; } = false;
|
||||
|
||||
/// <summary>True once Start has built the material instance and mesh caches (the camo knobs below
|
||||
/// become readable from the material). The HUD binds in the avatar's OnNetworkSpawn, which runs
|
||||
/// BEFORE this Start, so it must wait for this before reading the camo knobs into its sliders.</summary>
|
||||
public bool IsReady => _setupValid;
|
||||
|
||||
/// <summary>
|
||||
/// Live camouflage knobs on the player's <c>Custom/PlayerCamoLit</c> material instance, surfaced so
|
||||
/// the paint HUD can tune them at runtime. Backed directly by the material instance, which is the
|
||||
/// authored source of truth: the getter reads it, the setter writes it. Both are a no-op when the
|
||||
/// material lacks the property (non-camo shader) or before Start builds the instance, so they never
|
||||
/// clobber the authored value. Runtime tuning is persisted by the HUD (PaintHud.Persistence saves them
|
||||
/// to the same JSON as the brush values and carries them across a scene-switch respawn) and replicated
|
||||
/// to other peers owner-authoritatively by <see cref="PlayerPaintSync"/>, so remotes show the same camo.
|
||||
/// </summary>
|
||||
public float CamoHalfLambert
|
||||
{
|
||||
get => _materialInstance && _materialInstance.HasProperty(HalfLambertId) ? _materialInstance.GetFloat(HalfLambertId) : 0f;
|
||||
set { if (_materialInstance && _materialInstance.HasProperty(HalfLambertId)) _materialInstance.SetFloat(HalfLambertId, value); }
|
||||
}
|
||||
|
||||
/// <summary>Companion to <see cref="CamoHalfLambert"/>: additive brightness shift (-1..1) of the
|
||||
/// flattened diffuse term, so the body tone can be tuned to match the scene.</summary>
|
||||
public float CamoHalfLambertBrightness
|
||||
{
|
||||
get => _materialInstance && _materialInstance.HasProperty(HalfLambertBrightnessId) ? _materialInstance.GetFloat(HalfLambertBrightnessId) : 0f;
|
||||
set { if (_materialInstance && _materialInstance.HasProperty(HalfLambertBrightnessId)) _materialInstance.SetFloat(HalfLambertBrightnessId, value); }
|
||||
}
|
||||
|
||||
/// <summary>Companion to <see cref="CamoHalfLambert"/>: scales down the direct specular highlight.</summary>
|
||||
public float CamoSpecularDampen
|
||||
{
|
||||
get => _materialInstance && _materialInstance.HasProperty(SpecularDampenId) ? _materialInstance.GetFloat(SpecularDampenId) : 0f;
|
||||
set { if (_materialInstance && _materialInstance.HasProperty(SpecularDampenId)) _materialInstance.SetFloat(SpecularDampenId, value); }
|
||||
}
|
||||
|
||||
[Header("Backend")]
|
||||
[Tooltip("ON = GPU painting (fast), OFF = CPU painting. Can be toggled live in Play mode.")]
|
||||
public bool useGpu = true;
|
||||
@@ -268,6 +303,9 @@ public partial class MeshPainter : MonoBehaviour
|
||||
private static readonly int EmissionColorId = Shader.PropertyToID("_EmissionColor");
|
||||
private static readonly int OcclusionMapId = Shader.PropertyToID("_OcclusionMap");
|
||||
private static readonly int OcclusionStrengthId = Shader.PropertyToID("_OcclusionStrength");
|
||||
private static readonly int HalfLambertId = Shader.PropertyToID("_HalfLambert");
|
||||
private static readonly int HalfLambertBrightnessId = Shader.PropertyToID("_HalfLambertBrightness");
|
||||
private static readonly int SpecularDampenId = Shader.PropertyToID("_SpecularDampen");
|
||||
private static readonly int BrushColorId = Shader.PropertyToID("_BrushColor");
|
||||
private static readonly int ColorWriteMaskId = Shader.PropertyToID("_ColorWriteMask");
|
||||
private static readonly int BrushCenterId = Shader.PropertyToID("_BrushCenter");
|
||||
|
||||
Reference in new issue
Block a user