All you have to write is one function:
// 0..1
float BridgeValue()
{
return /* your logic */;
}
and your animator gets the result as a parameter.
The included tool creates a self-contained instance that you can bundle with your package.
Since you can’t script on avatars, sending data from the GPU to the CPU is not possible, but the GPU can make a frame take longer, and an animator can measure frame times. When the value changes, the shader spends a little extra GPU time on one frame, and the animator picks up on the slow frame one bit at a time. When nothing changes, the cost of the system is effectively zero.
ShaderBridge/Value in your FX controller follow how brightly the avatar is lit.<Name> Emitter.mat in play mode and watch <Prefix>/Value follow.BridgeValue() in Emitter/<Name> Emitter.shader. Creating the instance again wont overwrite this file.Avatars subfolder if there is one, it only holds files the installer made for your test avatar.BridgeValue()tex2Dlod at fixed coordinates, instead of something that depends on the vertex or pixel.BridgeVert / BridgeFrag and the ShaderBridge.cginc include. To use a shader you already have, add those and pick Existing Shader before instancing._BridgeHysteresis, 0.25 levels by default) stops flickering when the value sits right between two levels. A 1 bit system turns on above 0.75 and off below 0.25. Set it to 0 for a plain 0.5 threshold.| Parameter | Type | |
|---|---|---|
<Prefix>/Value | Float | The value, 0..1. Wearer only. |
<Prefix>/Level | Float | The same as a whole number, 0..2^bits−1. |
<Prefix>/RawValue, <Prefix>/RawLevel | Float | Faster, but can briefly show in-between values. Same as Value/Level without Stable Output. |
<Prefix>/Synced | Bool or Int | Synced copy for everyone. |
All other <Prefix>/... parameters are internal.
FX Animator Layers: 11 + bits (one less without sync)
Skinned Meshes: 1
Material Slots: 1
Synced Parameter Bits: 1 for 1 bit, 8 for more (0 without sync)
Avatar
└── <Name>
└── Emitter
If you run into problems or need help, message me on Discord: hfcRed
Shader To Animator Bridge is under the MIT License and free to use and redistribute. The systems you make with it are yours to ship however you like.
com.hfcred.shadertoanimatorbridge
Undefined
1.0.0
2022.3 or later
No dependencies
No legacy packages