Skip to content
#NVJOB Water Shader - simple and fast. Unity Asset.
C# HLSL ShaderLab HTML GLSL
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
Assets
ProjectSettings
.gitattributes
.gitignore
LICENSE
README.md

README.md

#NVJOB Water Shader - simple and fast 1.4.5

nvjob.github.io/unity/nvjob-water-shader

GitHub Logo

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


GitHub Logo

Prerequisites

To work on the project, you will need a Unity version of at least 2019.1.8 (64-bit).

Information

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.

An example of a script for the movement of water.

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);
    }
}

For working shaders on mobile platforms with Forward Rendering.

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;
    }
}

The rotation of the wind synchronously with water (optionally).

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);
    }
}

GitHub Logo

Video manual:

https://www.youtube.com/watch?v=Br8upLzvTVU
https://www.youtube.com/watch?v=94dRrLFMA1k


GitHub Logo GitHub Logo GitHub Logo


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

You can’t perform that action at this time.