Stylized Water 2 documentation

Stylized Water 2

Stylized Water 2
Version: 1.6.2
Review

4.4.Components & Utilities #

Water Object

You’ll find this component on every prefab. It merely provides an easy way to identify which objects in the scene represent water. Currently, the Planar Reflection Renderer component, Underwater Rendering extension and Buoyancy API make use of this.

The component caches the mesh and material used, so these can be retrieved instantly. Next to providing access to a MaterialPropertyBlock. The transform may also be used, to fetch the water level.

Water Mesh asset

The package comes paired with a utility that can generate plane or circle meshes, to be used with the water shader. This makes it easy to add subdivions to a mesh, without having to leave Unity. When using waves, a mesh requires a sufficient vertex density.

To create one:

Right-click in the project window and go to Create->Water->Mesh. This creates a new .watermesh asset, which is essentially a regular mesh, so can be assigned to any Mesh Filter component.

Adding too many subdivisions (+65k vertices) will result in a mangled mesh.

API

The StylizedWater2.WaterMesh class can instantiated, in order to create a mesh through custom scripts. You can change any of the public properties, then call the Rebuild() function to generate a mesh using the current settings.

Or access the static StylizedWater2.WaterMesh.Create function to create a mesh directly.

Water Grid

This component lives up to its name, it creates a grid of water meshes around its position.

It can created through:

  • Add Component->Stylized Water 2->Water Grid
  • GameObject->3D Object->Water->Grid
  • Window->Stylized Water 2->Create water grid

The “Follow target” transform field can be set so the grid follows this around on the XZ axis. The position is snapped to the nearest vertex, so waves will not appear to wobble when the grid is moved.

For the water surface to appear consistent when moving, the UV Source under the “General” tab in the material UI must be set to “World XZ Projected” (default setting).

This can be utilized to create water tiles for streaming systems, or faking an infinite ocean to some extent.

Large water bodies, with dynamic vertex subdivision (near the camera) delves into something like a CDLOD system (similar to terrain/planet rendering). This is far outside of the scope of this asset.

Because the created tile mesh is procedural in nature, it’ll be regenerated when the component is used in a prefab. This’ll be quite fast though!

Align Transform To Waves

This component makes a Transform and all of its child objects snap to the water surface. It does so, by recalculating the material’s wave pattern, making it possible to mirror the wave animations in code.

  • Because the script sets the orientation of the Transform, modifying all axis, it cannot be rotated manually or through other scripts. Instead, set the rotation of the child objects directly.
  • This script alters the transform’s Y-position, so it cannot be modified by anything else. The X/Z position of the transform can be changed freely by other actors.

This cannot be used in combination with RigidBodies. Gravity will attempt to pull down the object, creating a constant tug war between the Physics and Transform domains. This typically manifests as extreme jittering.

Hierarchy set up when looking to modify the rotation, on top of the wave orientation

 

 

 

 

 

 

The “WavesExample” scene shows this component in action

Yes No Suggest edit
Last updated on December 14, 2023
7 of 7 users found this section helpful
Suggest Edit