Stylized Water 3
5.Scripting
By large this is a shader asset. Though because aspects revolving around Height Sampling are related to scripting, there are a couple of C# functions in place that can aid development.
All these functions have IntelliSense summaries, which can be viewed in your IDE, next to any overload variations. If necessary, each parameter is described there.
StylizedWater3.WaterObject.Find
Using the Height Query System‘s CPU method requires a reference to a Water Object
component. This is so the Y-position (water level) and material (wave settings) can be accessed.
This function is a quick way to find a Water Object
below or above a given position. It won’t be efficient to rely entirely on this, especially not every frame. Its performance impact scales up by the number of Water Objects in the scene.
Floating Origins systems
To offset the water’s world-position coordinates in the shader, you can set the offset value through StylizedWater3.WaterObject.PositionOffset = <a Vector3>
. This also affects the Height Query System correctly.
Network synchronized waves
All the shader effects, including the waves, use the global _TimeParameters
shader value set by Unity as a time index. This translates to UnityEngine.Time.time
.
If you’re running a networked application, it may be important to ensure the waves are identical for all players (especially when using buoyancy). This is possible by overriding the time index used by the shader.
Through script, pass your time value every frame through StylizedWater3.WaterObject.CustomTime = <a float>
. This function will pass the time value to the shader and buoyancy calculations, and keeps them in sync.
To disable this behaviour, pass in a value lower than 0.