Giter VIP home page Giter VIP logo

nvjob-water-shader-simple-and-fast's Introduction

#NVJOB Water Shader - simple and fast 1.4.5

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

nvjob-water-shader-simple-and-fast's People

Contributors

nvjob avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.