FurShell: scale-aware length/curvature + X-ray glow mirror
The fur is drawn from a CPU-baked unit-scale mesh whose instance matrix carries the avatar's world scale, so the extrusion scaled fully 1:1 with the player (hider 0.5 / hunter 1.5). That read as too-short fur on the small hider and too-long on the big hunter, and the curvature droop was sized off the raw unity_ObjectToWorld which doesn't carry the per-instance scale in the RenderMeshInstanced path. - FurShellRenderer pushes the avatar's lossyScale (_FurObjScale) plus a new Fur Scale Influence (0..1, default 0.5) that blends the fur SIZE between fully proportional (1) and a constant world length (0). The shader pre-divides the object-space displacement so the net world length follows effScale; curl droop and wind use the same effScale, keeping the curl SHAPE invariant across avatar sizes and influence settings. - The body's see-through X-ray reveal (forward half) is mirrored onto the visible fur so strands glow WITH the reveal instead of hiding it under opaque fur. FurShellRenderer pulls the live colour/pulse/flash from the sibling MeshPainter (new getters), in phase with the body. A new X-Ray Fur Strength (default 0.2) tames the per-shell accumulation, since the body writes the glow once (opaque) but the fur stacks N transparent shells that each composite it. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
d9e4aec927
commit
9dc8f21528
3 files changed
+132
-5
No files matched your search
@@ -59,6 +59,28 @@ Shader "Custom/FurShell"
|
||||
_WindSpeed("Wind Speed", Range(0.0, 10.0)) = 2.0
|
||||
_WindFrequency("Wind Spatial Frequency", Range(0.0, 10.0)) = 1.0
|
||||
_WindDirection("Wind Direction (object XZ)", Vector) = (1, 0, 0, 0)
|
||||
|
||||
// Avatar world scale, pushed by FurShellRenderer (transform.lossyScale). Drives the curvature droop
|
||||
// so the curl stays proportional at any player size; 1 = authored size (see the vertex shader).
|
||||
[HideInInspector] _FurObjScale("Object Scale (driven by FurShellRenderer)", Float) = 1
|
||||
// How strongly the avatar scale drives the fur SIZE: 1 = fully proportional (fur shrinks/grows with the
|
||||
// avatar), 0 = constant world size (same absolute fur length at any avatar scale). Proportional fur
|
||||
// reads as too short on the small hider and too long on the big hunter, so this blends between them.
|
||||
[HideInInspector] _FurScaleInfluence("Scale Influence (driven by FurShellRenderer)", Range(0, 1)) = 0.5
|
||||
|
||||
[Header(XRay Reveal)]
|
||||
// See-through reveal glow mirrored from the sibling MeshPainter's body X-ray so the fur strands glow
|
||||
// WITH the reveal instead of hiding it under opaque fur. rgb = HDR glow colour, a = fade master.
|
||||
// Default (0,0,0,0) => additive term is zero, so the fur looks unchanged until a reveal fades in.
|
||||
[HDR] _XRayColor("X-Ray Overlay Color", Color) = (0, 0, 0, 0)
|
||||
// Breathing pulse kept identical to the body halves (PlayerCamo.hlsl / XRayOverlay) so they stay in phase.
|
||||
_XRayPulseSpeed("X-Ray Pulse Speed", Float) = 3
|
||||
_XRayPulseStrength("X-Ray Pulse Strength", Range(0, 1)) = 0.5
|
||||
_XRayPulseShape("X-Ray Pulse Shape", Range(1, 8)) = 3
|
||||
// The fur draws _ShellCount stacked TRANSPARENT shells; the additive glow below would composite once
|
||||
// PER overlapping layer and blow out (the body writes it once, opaque). This scales the per-shell glow
|
||||
// down so the stacked total reads at roughly the body's intensity. Tune to match the body glow.
|
||||
_XRayFurStrength("X-Ray Fur Strength (tames shell stacking)", Range(0, 1)) = 0.2
|
||||
}
|
||||
|
||||
SubShader
|
||||
@@ -127,6 +149,13 @@ Shader "Custom/FurShell"
|
||||
float _WindSpeed;
|
||||
float _WindFrequency;
|
||||
float4 _WindDirection;
|
||||
float _FurObjScale;
|
||||
float _FurScaleInfluence;
|
||||
half4 _XRayColor;
|
||||
half _XRayPulseSpeed;
|
||||
half _XRayPulseStrength;
|
||||
half _XRayPulseShape;
|
||||
half _XRayFurStrength;
|
||||
CBUFFER_END
|
||||
|
||||
TEXTURE2D(_BaseMap);
|
||||
@@ -173,13 +202,24 @@ Shader "Custom/FurShell"
|
||||
float count = max(_ShellCount, 1.0);
|
||||
float h = (count <= 1.0) ? 0.0 : (float)shellIndex / (count - 1.0);
|
||||
|
||||
// Effective fur-size scale. The instance matrix already multiplies the object-space fur
|
||||
// displacement by the avatar's world scale (_FurObjScale), so at full influence the fur is
|
||||
// fully proportional (small avatar => small fur, like the body). _FurScaleInfluence blends
|
||||
// that toward a CONSTANT world size (influence 0 => same absolute fur length at any avatar
|
||||
// size), because fully proportional fur reads as too short on the small hider and too long on
|
||||
// the big hunter. dispComp pre-divides the object-space offset so that after the matrix's
|
||||
// *_FurObjScale the NET world displacement equals effScale, not _FurObjScale.
|
||||
float objScale = max(_FurObjScale, 1e-4);
|
||||
float effScale = lerp(1.0, objScale, _FurScaleInfluence);
|
||||
float dispComp = effScale / objScale;
|
||||
|
||||
// extrude along the normal; bend the tips down with h^2 for a gravity/curl droop.
|
||||
// The (h + 0.02) lifts the whole stack a hair off the surface: the root (h=0) would else
|
||||
// sit exactly on the opaque body and z-fight it - the fur draws a CPU-baked mesh while the
|
||||
// body uses GPU skinning, so their depths are not bit-identical, and now that fur is
|
||||
// transparent (ZWrite Off) it can't rely on a depth write to win the tie. 0.02 of the shell
|
||||
// length is invisible but separates the root cleanly.
|
||||
float3 posOS = input.positionOS.xyz + input.normalOS * (_ShellLength * (h + 0.02));
|
||||
float3 posOS = input.positionOS.xyz + input.normalOS * (_ShellLength * (h + 0.02) * dispComp);
|
||||
|
||||
// wind sway: nudge each shell along the wind direction (object XZ) by a time-varying
|
||||
// amount. The phase is offset by object-space position so a gust rolls across the surface,
|
||||
@@ -189,17 +229,20 @@ Shader "Custom/FurShell"
|
||||
float wlen = length(wdir);
|
||||
wdir = (wlen > 1e-4) ? (wdir / wlen) : float2(1.0, 0.0);
|
||||
float phase = _Time.y * _WindSpeed + (input.positionOS.x + input.positionOS.z) * _WindFrequency;
|
||||
posOS.xz += wdir * (_WindStrength * _ShellLength * h * h * sin(phase));
|
||||
posOS.xz += wdir * (_WindStrength * _ShellLength * h * h * sin(phase) * dispComp);
|
||||
|
||||
// Gravity/curl bends toward WORLD down. Applied AFTER moving to world space and using ONLY
|
||||
// unity_ObjectToWorld (positions/normals already prove that matrix correct). The previous
|
||||
// object-space approach relied on unity_WorldToObject, which is NOT reliably populated in the
|
||||
// RenderMeshInstanced path - when it falls back to identity the droop follows the mesh's own
|
||||
// local down, so on the rotated player the fur hung sideways instead of toward true down.
|
||||
// objScale keeps the droop magnitude consistent with the normal extrusion (object units).
|
||||
float3 positionWS = TransformObjectToWorld(posOS);
|
||||
float objScale = length(mul((float3x3)unity_ObjectToWorld, float3(0.0, 1.0, 0.0)));
|
||||
positionWS.y -= _Curvature * _ShellLength * h * h * objScale;
|
||||
// Curl droop in world down. It uses the SAME effScale as the extrusion above (not the raw
|
||||
// _FurObjScale), so the curl keeps its SHAPE relative to the fur length at any avatar size and
|
||||
// at any influence setting - dialing the length toward constant carries the droop with it
|
||||
// instead of leaving it too strong on the shrunk hider / too weak on the grown hunter. Applied
|
||||
// after moving to world space, so the droop follows true world down regardless of player rotation.
|
||||
positionWS.y -= _Curvature * _ShellLength * h * h * effScale;
|
||||
|
||||
VertexNormalInputs vn = GetVertexNormalInputs(input.normalOS);
|
||||
|
||||
@@ -341,6 +384,18 @@ Shader "Custom/FurShell"
|
||||
half rim = pow(saturate(1.0h - saturate(dot(N, V))), _RimPower) * _RimStrength * h;
|
||||
color += rim * mainLight.color * albedo;
|
||||
|
||||
// X-Ray reveal glow on the VISIBLE fur, mirroring the body's forward half (PlayerCamo.hlsl)
|
||||
// EXACTLY so the strands glow IN PHASE with the body instead of hiding its reveal under
|
||||
// opaque fur. Additive HDR term; _XRayColor.a is the eased fade master (0 when off => fur
|
||||
// unchanged). FurShellRenderer pushes the same colour/pulse/flash state the sibling
|
||||
// MeshPainter drives on the body, so on/occluded stays consistent between fur and body.
|
||||
half xrayCurve = pow(0.5h - 0.5h * cos(_Time.y * _XRayPulseSpeed), _XRayPulseShape);
|
||||
half xrayPulse = 1.0h - _XRayPulseStrength * (1.0h - xrayCurve);
|
||||
// _XRayFurStrength tames the per-shell accumulation: the body adds this term once (opaque),
|
||||
// but the fur stacks _ShellCount transparent shells that each composite it, so the raw term
|
||||
// over-brightens. Scaling it per shell brings the stacked total back near the body's glow.
|
||||
color += _XRayColor.rgb * (_XRayColor.a * xrayPulse * _XRayFurStrength);
|
||||
|
||||
return half4(color, alpha);
|
||||
}
|
||||
ENDHLSL
|
||||
|
||||
Reference in new issue
Block a user