Simple and fast water shader. This shader is suitable for scenes where water is not a key element of the scene, but a decorative element. Supported rendering path deferred and forward. It works on all platforms.
Previous Versions - github.com/nvjob/nvjob-water-shader-old-versions
To work on the project, you will need a Unity version of at least 2019.1.8 (64-bit).
The movement of the waves is carried out using global shader variables: _WaterLocalUvX, _WaterLocalUvZ, _WaterLocalUvNX, _WaterLocalUvNZ.
_WaterLocalUvX, _WaterLocalUvZ - Offset main texture.
_WaterLocalUvNX, _WaterLocalUvNZ - Offset normal map texture.
using UnityEngine;
public class Water : MonoBehaviour
{
public float UvRotateSpeed = 0.4f;
public float UvRotateDistance = 2.0f;
public float UvBumpRotateSpeed = 0.4f;
public float UvBumpRotateDistance = 2.0f;
Vector2 lwVector, lwNVector;
private void Awake()
{
lwVector = Vector2.zero;
lwNVector = Vector2.zero;
}
void Update()
{
lwVector = Quaternion.AngleAxis(Time.time * UvRotateSpeed, Vector3.forward) * Vector2.one * UvRotateDistance;
lwNVector = Quaternion.AngleAxis(Time.time * UvBumpRotateSpeed, Vector3.forward) * Vector2.one * UvBumpRotateDistance;
Shader.SetGlobalFloat("_WaterLocalUvX", lwVector.x);
Shader.SetGlobalFloat("_WaterLocalUvZ", lwVector.y);
Shader.SetGlobalFloat("_WaterLocalUvNX", lwNVector.x);
Shader.SetGlobalFloat("_WaterLocalUvNZ", lwNVector.y);
}
}
In asset this fix is already added to the general script.
using UnityEngine;
[ExecuteInEditMode]
public class depthTextureFix : MonoBehaviour
{
void OnEnable()
{
GetComponent<Camera>().depthTextureMode = DepthTextureMode.Depth;
}
}
using UnityEngine;
public class WindZoneRot : MonoBehaviour
{
Transform tr;
private void Awake()
{
tr = transform;
}
void LateUpdate()
{
tr.rotation = Quaternion.LookRotation(new Vector3(Shader.GetGlobalFloat("_WaterLocalUvNX"), 0, Shader.GetGlobalFloat("_WaterLocalUvNZ")), Vector3.zero) * Quaternion.Euler(0, -40, 0);
}
}
https://www.youtube.com/watch?v=Br8upLzvTVU
https://www.youtube.com/watch?v=94dRrLFMA1k
Authors: #NVJOB Nicholas Veselov - nvjob.github.io
License: MIT License. Clarification of licenses - nvjob.github.io/mit-license
Support: nvjob.github.io/support
Report a Problem / Issue Tracker / FAQ: nvjob.github.io/reportaproblem