-
Notifications
You must be signed in to change notification settings - Fork 13
Globals
The globals feature enable users to read global data from your application, for example, the player position. These data become available in VFX Graphs without requiring to bind the values individually at the component level using property binders.
In order to define Global values, you need to create :
- A VFX Globals definition asset, that define the data structure
- (can be created from the Asset Create Menu, in the Visual Effect Category)
- An HLSL include. This include will be referenced in the VFX Globals Definition.
- (the include can be generated/updated using the inspector menu)
In order to Read these values, you can now use the Get Globals node, a node that will ask for the Definition Asset, and display the defined properties accordingly.
IMPORTANT In order to sample these values in a context, you will also need to include the generated HLSL include using the Include Globals block on any block that will be connected to a GetGlobals. The Include Globals ask for a definition asset.
You can include multiple Global definitions, however including the same globals (or globals with same name) will end up in compilation errors.
Finally, In order to set the values from CSharp Scripts, simply use the Shader.SetGlobal...()
API. For example :
[ExecuteAlways]
[RequireComponent(typeof(SphereCollider))]
public class SetSphereGlobal : MonoBehaviour
{
SphereCollider m_Collider;
private void OnEnable()
{
m_Collider = GetComponent<SphereCollider>();
}
private void Update()
{
Shader.SetGlobalVector("spherePosition", transform.position);
Shader.SetGlobalFloat("sphereRadius", m_Collider.radius * transform.localScale.x);
}
}
- Blocks and Features
- Other Runtime Features