VWater is the system I created to render and simulate bodies of water in Vertigo 2. It is very lightweight and optimized for VR. Although it was used successfully in production, it has some idiosyncrasies and it's not quite a drag and drop solution.
![Multicolored pools of water](https://private-user-images.githubusercontent.com/29665945/347117246-9eb3f423-966b-4e9e-9ce1-0522ec8f77c0.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NjQ3NTAsIm5iZiI6MTcyNDQ2NDQ1MCwicGF0aCI6Ii8yOTY2NTk0NS8zNDcxMTcyNDYtOWViM2Y0MjMtOTY2Yi00ZTllLTljZTEtMDUyMmVjOGY3N2MwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI0VDAxNTQxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWEzYTQ0NGZkZTJkNGVhMTgzMDgxYjEyMjQ0MzIyYWJhNDg4ZTM0ZWIzZmY1MWZhZGZkYmVjMmFmOTE0ODhmMWYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.HD7oEmMTf-jYrq3C9BI7aqZsgHU33vgp_DoC7Y2iG38)
- Physically based light absorption and scattering
- GPU-driven ripple simulation
- Multiple bodies of water with different water levels, materials, and physical properties
- Underwater view rendering
- Basic buoyancy physics for rigidbodies
- Water masking inside boats
- Crest Ocean System compatibility
- Bodies of water must be axis aligned cuboids
- Water surface mesh is a flat plane, no tesselation or displacement
- Water flow is limited to a single direction per body of water
- Shaders only support the built in render pipeline
![View halfway underwater](https://private-user-images.githubusercontent.com/29665945/347120874-e33e5882-2f7d-422d-be94-9d7ea6a1ccc7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NjQ3NTAsIm5iZiI6MTcyNDQ2NDQ1MCwicGF0aCI6Ii8yOTY2NTk0NS8zNDcxMjA4NzQtZTMzZTU4ODItMmY3ZC00MjJkLWJlOTQtOWQ3ZWE2YTFjY2M3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI0VDAxNTQxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdhZmYxYjNmMTk2MjU4ZDA0MmE3ZGZkZDk1YWNkZjM5ZGQxYWI3ZTY0MzFiYzUxOWM5MWYxZmM5N2VmNjBhMWQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.nt3t8diszvHR_fnCdOI7A8z3-ax4VXvOCIJ76OeLRqo)
![A boat](https://private-user-images.githubusercontent.com/29665945/347121254-c8463b27-7895-43e9-ac43-be8a217f6b34.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ0NjQ3NTAsIm5iZiI6MTcyNDQ2NDQ1MCwicGF0aCI6Ii8yOTY2NTk0NS8zNDcxMjEyNTQtYzg0NjNiMjctNzg5NS00M2U5LWFjNDMtYmU4YTIxN2Y2YjM0LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MjQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODI0VDAxNTQxMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWZjYTVhMTRjYWZiZjUxZTQzOWU2MDlhNjk1MDM0OTFjZTQ2MDg0OGMyYjE3OWQwZmExN2RkMjc5OGEzYWJhODUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.1i1kYlImaeNq1Xnf1gnIrqSth41pIeAFf9_pnGPt_KU)
Before you start, make sure there is a VWaterManager and VWaterDynamicsManager instance in your scene. There is a prefab with both of these scripts you can use.
You can use any mesh for a body of water, but the most basic place to start is a plane. Assign a VWater material to the plane, and add a second material slot for the "VWater Bottom" material (ignore the warning) if you want to render underwater. The water needs a VWater component, a VWaterRenderer component, and a trigger box collider (or multiple!) to define the shape of the water.
You can scale the water non uniformly, the material uses world space UVs.
There is a basic water plane included in the Prefabs folder. I rarely use anything other than the basic plane, but you can use other meshes for waterfalls and such. Note that the water physics and rendering will still treat the water as a plane, however.
Underwater rendering is handled automatically whenever a camera enters a body of water. You shouldn't need to worry about it. You can toggle it off for each body of water if you want to, and you should if you know the player will never enter a certain body of water.
To add buoyancy physics to a rigidbody, add the WaterBody component. Set the "Main Collider" field to the rigidbody's largest collider. If it has a lot of small colliders, consider adding a large encompassing collider, setting it as a trigger, and using that.
If you want the rigidbody to leave ripples in the water, add a VWaterDynamicFlowSource component, and set the WaterBody "Wake" field to that component.
To add ripples from other sources, you can use independent VWaterDynamicFlowSource components, or call VWaterDynamicsManager.instance.AddFlow() yourself.
Masking is used to cut holes in the surface of the water, which is most useful for boats. See the included boat prefab for an example.
Masks need a MeshRenderer with the VWaterMask material, a trigger, and a VWaterMask component
How your character interacts with water depends on the game. I've commented out the code in WaterBody that would normally handle character submersion. I implemented swimming physics in the character controller itself, so I've left that out of this repository completely. In the "Extras" folder I've included the script, WaterHead, that I use to play sounds and muffle audio when your head goes underwater, and also simulate drowning. You'll have to do some extra work to get it working though.