init commit
This commit is contained in:
46
Packages/manifest.json
Normal file
46
Packages/manifest.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.unity.collab-proxy": "2.2.0",
|
||||
"com.unity.ide.rider": "3.0.26",
|
||||
"com.unity.ide.visualstudio": "2.0.22",
|
||||
"com.unity.ide.vscode": "1.2.5",
|
||||
"com.unity.render-pipelines.universal": "14.0.9",
|
||||
"com.unity.test-framework": "1.1.33",
|
||||
"com.unity.textmeshpro": "3.0.6",
|
||||
"com.unity.timeline": "1.7.6",
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"com.unity.visualscripting": "1.9.1",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
"com.unity.modules.androidjni": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
"com.unity.modules.assetbundle": "1.0.0",
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.cloth": "1.0.0",
|
||||
"com.unity.modules.director": "1.0.0",
|
||||
"com.unity.modules.imageconversion": "1.0.0",
|
||||
"com.unity.modules.imgui": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0",
|
||||
"com.unity.modules.particlesystem": "1.0.0",
|
||||
"com.unity.modules.physics": "1.0.0",
|
||||
"com.unity.modules.physics2d": "1.0.0",
|
||||
"com.unity.modules.screencapture": "1.0.0",
|
||||
"com.unity.modules.terrain": "1.0.0",
|
||||
"com.unity.modules.terrainphysics": "1.0.0",
|
||||
"com.unity.modules.tilemap": "1.0.0",
|
||||
"com.unity.modules.ui": "1.0.0",
|
||||
"com.unity.modules.uielements": "1.0.0",
|
||||
"com.unity.modules.umbra": "1.0.0",
|
||||
"com.unity.modules.unityanalytics": "1.0.0",
|
||||
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
|
||||
"com.unity.modules.unitywebrequestaudio": "1.0.0",
|
||||
"com.unity.modules.unitywebrequesttexture": "1.0.0",
|
||||
"com.unity.modules.unitywebrequestwww": "1.0.0",
|
||||
"com.unity.modules.vehicles": "1.0.0",
|
||||
"com.unity.modules.video": "1.0.0",
|
||||
"com.unity.modules.vr": "1.0.0",
|
||||
"com.unity.modules.wind": "1.0.0",
|
||||
"com.unity.modules.xr": "1.0.0",
|
||||
"com.github.skistua.unity-vimeditor": "https://gitee.com/b166er/unity-vimeditor.git"
|
||||
}
|
||||
}
|
||||
406
Packages/packages-lock.json
Normal file
406
Packages/packages-lock.json
Normal file
@@ -0,0 +1,406 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"com.github.skistua.unity-vimeditor": {
|
||||
"version": "https://gitee.com/b166er/unity-vimeditor.git",
|
||||
"depth": 0,
|
||||
"source": "git",
|
||||
"dependencies": {},
|
||||
"hash": "3c423b8df140f6b9ae80a492177a1c4c83331811"
|
||||
},
|
||||
"com.unity.burst": {
|
||||
"version": "1.8.9",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.mathematics": "1.2.1"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.collab-proxy": {
|
||||
"version": "2.2.0",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ext.nunit": {
|
||||
"version": "1.0.6",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ide.rider": {
|
||||
"version": "3.0.26",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.ext.nunit": "1.0.6"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ide.visualstudio": {
|
||||
"version": "2.0.22",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.test-framework": "1.1.9"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ide.vscode": {
|
||||
"version": "1.2.5",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.mathematics": {
|
||||
"version": "1.2.6",
|
||||
"depth": 1,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.render-pipelines.core": {
|
||||
"version": "14.0.9",
|
||||
"depth": 1,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"com.unity.modules.physics": "1.0.0",
|
||||
"com.unity.modules.terrain": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.render-pipelines.universal": {
|
||||
"version": "14.0.9",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.mathematics": "1.2.1",
|
||||
"com.unity.burst": "1.8.9",
|
||||
"com.unity.render-pipelines.core": "14.0.9",
|
||||
"com.unity.shadergraph": "14.0.9"
|
||||
}
|
||||
},
|
||||
"com.unity.searcher": {
|
||||
"version": "4.9.2",
|
||||
"depth": 2,
|
||||
"source": "registry",
|
||||
"dependencies": {},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.shadergraph": {
|
||||
"version": "14.0.9",
|
||||
"depth": 1,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.render-pipelines.core": "14.0.9",
|
||||
"com.unity.searcher": "4.9.2"
|
||||
}
|
||||
},
|
||||
"com.unity.test-framework": {
|
||||
"version": "1.1.33",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.ext.nunit": "1.0.6",
|
||||
"com.unity.modules.imgui": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.textmeshpro": {
|
||||
"version": "3.0.6",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.ugui": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.timeline": {
|
||||
"version": "1.7.6",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.modules.director": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.particlesystem": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"com.unity.ugui": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.ui": "1.0.0",
|
||||
"com.unity.modules.imgui": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.visualscripting": {
|
||||
"version": "1.9.1",
|
||||
"depth": 0,
|
||||
"source": "registry",
|
||||
"dependencies": {
|
||||
"com.unity.ugui": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
},
|
||||
"url": "https://packages.unity.cn"
|
||||
},
|
||||
"zzwater": {
|
||||
"version": "file:zzwater",
|
||||
"depth": 0,
|
||||
"source": "embedded",
|
||||
"dependencies": {
|
||||
"com.unity.render-pipelines.universal": "10.3.2"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.ai": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.androidjni": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.animation": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.assetbundle": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.audio": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.cloth": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.physics": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.director": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.imageconversion": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.imgui": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.jsonserialize": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.particlesystem": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.physics": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.physics2d": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.screencapture": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.imageconversion": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.subsystems": {
|
||||
"version": "1.0.0",
|
||||
"depth": 1,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.terrain": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.terrainphysics": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.physics": "1.0.0",
|
||||
"com.unity.modules.terrain": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.tilemap": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.physics2d": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.ui": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.uielements": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.ui": "1.0.0",
|
||||
"com.unity.modules.imgui": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.umbra": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.unityanalytics": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.unitywebrequest": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.unitywebrequestassetbundle": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.assetbundle": "1.0.0",
|
||||
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.unitywebrequestaudio": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||
"com.unity.modules.audio": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.unitywebrequesttexture": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||
"com.unity.modules.imageconversion": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.unitywebrequestwww": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
|
||||
"com.unity.modules.unitywebrequestaudio": "1.0.0",
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.assetbundle": "1.0.0",
|
||||
"com.unity.modules.imageconversion": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.vehicles": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.physics": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.video": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.audio": "1.0.0",
|
||||
"com.unity.modules.ui": "1.0.0",
|
||||
"com.unity.modules.unitywebrequest": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.vr": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.jsonserialize": "1.0.0",
|
||||
"com.unity.modules.physics": "1.0.0",
|
||||
"com.unity.modules.xr": "1.0.0"
|
||||
}
|
||||
},
|
||||
"com.unity.modules.wind": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {}
|
||||
},
|
||||
"com.unity.modules.xr": {
|
||||
"version": "1.0.0",
|
||||
"depth": 0,
|
||||
"source": "builtin",
|
||||
"dependencies": {
|
||||
"com.unity.modules.physics": "1.0.0",
|
||||
"com.unity.modules.jsonserialize": "1.0.0",
|
||||
"com.unity.modules.subsystems": "1.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Packages/zzwater/Editor.meta
Normal file
8
Packages/zzwater/Editor.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a742f44083e53427f96b79222fd150cc
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
239
Packages/zzwater/Editor/WaterMesh.cs
Normal file
239
Packages/zzwater/Editor/WaterMesh.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace zz.water.editor
|
||||
{
|
||||
[System.Serializable]
|
||||
public class WaterMesh
|
||||
{
|
||||
public enum Shape
|
||||
{
|
||||
Rectangle,
|
||||
Disk
|
||||
}
|
||||
public Shape shape;
|
||||
|
||||
[FormerlySerializedAs("size")]
|
||||
[Range(10, 1000)]
|
||||
public float scale = 100f;
|
||||
|
||||
[Tooltip("Distance between vertices")]
|
||||
[Range(0.15f, 10f)]
|
||||
public float vertexDistance = 1f;
|
||||
|
||||
public float UVTiling = 1f;
|
||||
|
||||
[Tooltip("Shifts the vertices in a random direction. Definitely use this when using flat shading")]
|
||||
[Range(0f, 1f)]
|
||||
public float noise;
|
||||
|
||||
[Min(0)]
|
||||
[Tooltip("The surface is normally flat, yet vertex displacement on the GPU such as waves can give the surface artificial height." +
|
||||
"\n\nThis can cause a Mesh Renderer to be prematurely culled, despite still actually being visible." +
|
||||
"\n\nThis value adds an artificial amount of height to the generate mesh's bounds, to avoid this from happening.")]
|
||||
public float boundsPadding = 4f;
|
||||
|
||||
/// <summary>
|
||||
/// Generated output mesh. Empty by default, use the Rebuild() function to generate one from the current settings.
|
||||
/// </summary>
|
||||
public Mesh mesh;
|
||||
|
||||
public Mesh Rebuild()
|
||||
{
|
||||
switch (shape)
|
||||
{
|
||||
case Shape.Rectangle: mesh = CreatePlane();
|
||||
break;
|
||||
case Shape.Disk: mesh = CreateCircle();
|
||||
break;
|
||||
}
|
||||
|
||||
return mesh;
|
||||
}
|
||||
|
||||
public static Mesh Create(Shape shape, float size, float vertexDistance, float uvTiling = 1f, float noise = 0f)
|
||||
{
|
||||
WaterMesh waterMesh = new WaterMesh();
|
||||
waterMesh.shape = shape;
|
||||
waterMesh.scale = size;
|
||||
waterMesh.vertexDistance = vertexDistance;
|
||||
waterMesh.UVTiling = uvTiling;
|
||||
waterMesh.noise = noise;
|
||||
|
||||
return waterMesh.Rebuild();
|
||||
}
|
||||
|
||||
// Get the index of point number 'x' in circle number 'c'
|
||||
private int GetPointIndex(int c, int x)
|
||||
{
|
||||
if (c < 0) return 0;
|
||||
|
||||
x = x % ((c + 1) * 6);
|
||||
|
||||
return (3 * c * (c + 1) + x + 1);
|
||||
}
|
||||
|
||||
private Mesh CreateCircle()
|
||||
{
|
||||
Mesh m = new Mesh();
|
||||
m.name = "WaterDisk";
|
||||
|
||||
int subdivisions = Mathf.FloorToInt(scale / vertexDistance);
|
||||
|
||||
float distance = 1f / subdivisions;
|
||||
|
||||
var vertices = new List<Vector3>();
|
||||
var uvs = new List<Vector2>();
|
||||
var uvs2 = new List<Vector2>();
|
||||
vertices.Add(Vector3.zero); //Center
|
||||
var tris = new List<int>();
|
||||
|
||||
// First pass => build vertices
|
||||
for (int loop = 0; loop < subdivisions; loop++)
|
||||
{
|
||||
float angleStep = (Mathf.PI * 2f) / ((loop + 1) * 6);
|
||||
for (int point = 0; point < (loop + 1) * 6; ++point)
|
||||
{
|
||||
Vector3 vPos = new Vector3(
|
||||
Mathf.Sin(angleStep * point) ,
|
||||
0f,
|
||||
Mathf.Cos(angleStep * point));
|
||||
|
||||
UnityEngine.Random.InitState(loop + point);
|
||||
vPos.x += UnityEngine.Random.Range(-noise * 0.01f, noise * 0.01f);
|
||||
vPos.z -= UnityEngine.Random.Range(noise * 0.01f, -noise * 0.01f);
|
||||
|
||||
vertices.Add(vPos * (scale * 0.5f) * distance * (loop + 1));
|
||||
}
|
||||
}
|
||||
|
||||
//Planar mapping
|
||||
for (int i = 0; i < vertices.Count; i++)
|
||||
{
|
||||
uvs.Add(new Vector2(0.5f + (vertices[i].x) * UVTiling,0.5f + (vertices[i].z) * UVTiling));
|
||||
//Lightmap UV's
|
||||
uvs2.Add(new Vector2(0.5f + (vertices[i].x / scale),0.5f + (vertices[i].z / scale)));
|
||||
}
|
||||
|
||||
// Second pass => connect vertices into triangles
|
||||
for (int circ = 0; circ < subdivisions; ++circ)
|
||||
{
|
||||
for (int point = 0, other = 0; point < (circ + 1) * 6; ++point)
|
||||
{
|
||||
if (point % (circ + 1) != 0)
|
||||
{
|
||||
// Create 2 triangles
|
||||
tris.Add(GetPointIndex(circ - 1, other + 1));
|
||||
tris.Add(GetPointIndex(circ - 1, other));
|
||||
tris.Add(GetPointIndex(circ, point));
|
||||
|
||||
tris.Add(GetPointIndex(circ, point));
|
||||
tris.Add(GetPointIndex(circ, point + 1));
|
||||
tris.Add(GetPointIndex(circ - 1, other + 1));
|
||||
++other;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create 1 inverse triangle
|
||||
tris.Add(GetPointIndex(circ, point));
|
||||
tris.Add(GetPointIndex(circ, point + 1));
|
||||
tris.Add(GetPointIndex(circ - 1, other));
|
||||
// Do not move to the next point in the smaller circle
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create the mesh
|
||||
|
||||
m.SetVertices(vertices);
|
||||
m.SetTriangles(tris, 0);
|
||||
m.RecalculateNormals();
|
||||
m.RecalculateTangents();
|
||||
m.SetUVs(0, uvs);
|
||||
m.SetUVs(1, uvs2);
|
||||
m.colors = new Color[vertices.Count];
|
||||
|
||||
m.bounds = new Bounds(Vector3.zero, new Vector3(scale, boundsPadding, scale));
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
private Mesh CreatePlane()
|
||||
{
|
||||
Mesh m = new Mesh();
|
||||
m.name = "WaterPlane";
|
||||
|
||||
scale = Mathf.Max(1f, scale);
|
||||
int subdivisions = Mathf.FloorToInt(scale / vertexDistance);
|
||||
|
||||
int xCount = subdivisions + 1;
|
||||
int zCount = subdivisions + 1;
|
||||
int numTriangles = subdivisions * subdivisions * 6;
|
||||
int numVertices = xCount * zCount;
|
||||
|
||||
Vector3[] vertices = new Vector3[numVertices];
|
||||
Vector2[] uvs = new Vector2[numVertices];
|
||||
Vector2[] uvs2 = new Vector2[numVertices];
|
||||
int[] triangles = new int[numTriangles];
|
||||
Vector4[] tangents = new Vector4[numVertices];
|
||||
Vector3[] normals = new Vector3[numVertices];
|
||||
Vector4 tangent = new Vector4(1f, 0f, 0f, -1f);
|
||||
|
||||
int index = 0;
|
||||
float scaleX = scale / subdivisions;
|
||||
float scaleY = scale / subdivisions;
|
||||
|
||||
float noiseScale = vertexDistance * 0.5f;
|
||||
|
||||
for (int z = 0; z < zCount; z++)
|
||||
{
|
||||
for (int x = 0; x < xCount; x++)
|
||||
{
|
||||
vertices[index] = new Vector3(x * scaleX - (scale * 0.5f), 0f, z * scaleY - (scale * 0.5f));
|
||||
|
||||
UnityEngine.Random.InitState(index);
|
||||
vertices[index].x += UnityEngine.Random.Range(-noise * noiseScale, noise * noiseScale);
|
||||
vertices[index].z -= UnityEngine.Random.Range(noise * noiseScale, -noise * noiseScale);
|
||||
|
||||
tangents[index] = tangent;
|
||||
uvs[index] = new Vector2(0.5f + (vertices[index].x) * UVTiling, 0.5f + (vertices[index].z) * UVTiling);
|
||||
//Lightmap UV's
|
||||
uvs2[index] = new Vector2(0.5f + vertices[index].x / scale, 0.5f + vertices[index].z / scale);
|
||||
normals[index] = Vector3.up;
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
index = 0;
|
||||
for (int z = 0; z < subdivisions; z++)
|
||||
{
|
||||
for (int x = 0; x < subdivisions; x++)
|
||||
{
|
||||
triangles[index] = (z * xCount) + x;
|
||||
triangles[index + 1] = ((z + 1) * xCount) + x;
|
||||
triangles[index + 2] = (z * xCount) + x + 1;
|
||||
|
||||
triangles[index + 3] = ((z + 1) * xCount) + x;
|
||||
triangles[index + 4] = ((z + 1) * xCount) + x + 1;
|
||||
triangles[index + 5] = (z * xCount) + x + 1;
|
||||
index += 6;
|
||||
}
|
||||
}
|
||||
|
||||
m.vertices = vertices;
|
||||
m.triangles = triangles;
|
||||
m.uv = uvs;
|
||||
m.uv2 = uvs2;
|
||||
m.tangents = tangents;
|
||||
m.normals = normals;
|
||||
m.colors = new Color[vertices.Length];
|
||||
m.bounds = new Bounds(Vector3.zero, new Vector3(scale, boundsPadding, scale));
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/zzwater/Editor/WaterMesh.cs.meta
Normal file
11
Packages/zzwater/Editor/WaterMesh.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf7a83bc3b7bd442a8f8867464fed7cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
135
Packages/zzwater/Editor/WaterMeshImporter.cs
Normal file
135
Packages/zzwater/Editor/WaterMeshImporter.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.AssetImporters;
|
||||
using UnityEngine;
|
||||
|
||||
namespace zz.water.editor
|
||||
{
|
||||
|
||||
[ScriptedImporter(1, FILE_EXTENSION)]
|
||||
public class WaterMeshImporter : ScriptedImporter
|
||||
{
|
||||
private const string FILE_EXTENSION = "watermesh";
|
||||
|
||||
[SerializeField] public WaterMesh waterMesh = new WaterMesh();
|
||||
|
||||
public override void OnImportAsset(AssetImportContext context)
|
||||
{
|
||||
waterMesh.Rebuild();
|
||||
context.AddObjectToAsset("mesh", waterMesh.mesh);
|
||||
context.SetMainObject(waterMesh.mesh);
|
||||
}
|
||||
|
||||
//Handles correct behaviour when double-clicking a .watermesh asset assigned to a field
|
||||
//Otherwise the OS prompts to open it
|
||||
[UnityEditor.Callbacks.OnOpenAsset]
|
||||
public static bool OnOpenAsset(int instanceID, int line)
|
||||
{
|
||||
Object target = EditorUtility.InstanceIDToObject(instanceID);
|
||||
|
||||
if (target is Mesh)
|
||||
{
|
||||
var path = AssetDatabase.GetAssetPath(instanceID);
|
||||
|
||||
if (Path.GetExtension(path) != "." + FILE_EXTENSION) return false;
|
||||
|
||||
Selection.activeObject = target;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[CustomEditor(typeof(WaterMeshImporter))]
|
||||
public class WaterMeshImporterEditor: ScriptedImporterEditor
|
||||
{
|
||||
private SerializedProperty waterMesh;
|
||||
|
||||
private SerializedProperty shape;
|
||||
|
||||
private SerializedProperty scale;
|
||||
private SerializedProperty UVTiling;
|
||||
|
||||
private SerializedProperty vertexDistance;
|
||||
|
||||
private SerializedProperty noise;
|
||||
private SerializedProperty boundsPadding;
|
||||
|
||||
private WaterMeshImporter importer;
|
||||
|
||||
private bool autoApplyChanges;
|
||||
|
||||
public override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
importer = (WaterMeshImporter)target;
|
||||
|
||||
waterMesh = serializedObject.FindProperty("waterMesh");
|
||||
|
||||
shape = waterMesh.FindPropertyRelative("shape");
|
||||
scale = waterMesh.FindPropertyRelative("scale");
|
||||
UVTiling = waterMesh.FindPropertyRelative("UVTiling");
|
||||
vertexDistance = waterMesh.FindPropertyRelative("vertexDistance");
|
||||
noise = waterMesh.FindPropertyRelative("noise");
|
||||
boundsPadding = waterMesh.FindPropertyRelative("boundsPadding");
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
serializedObject.Update();
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
EditorGUILayout.PropertyField(shape);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(scale);
|
||||
EditorGUILayout.PropertyField(vertexDistance);
|
||||
|
||||
int subdivisions = Mathf.FloorToInt(scale.floatValue / vertexDistance.floatValue);
|
||||
int vertexCount = Mathf.FloorToInt(subdivisions * subdivisions);
|
||||
|
||||
using (new EditorGUILayout.HorizontalScope())
|
||||
{
|
||||
GUILayout.Space(EditorGUIUtility.labelWidth);
|
||||
|
||||
Rect rect = EditorGUILayout.GetControlRect();
|
||||
EditorGUI.ProgressBar(rect, (float)vertexCount/65535f, $"Vertex count: {vertexCount:N1}/{65535f:N1}");
|
||||
}
|
||||
if(vertexCount > 65535)
|
||||
{
|
||||
EditorGUILayout.HelpBox("Vertex count (" + vertexCount + ") is too high. Decrease the scale, or increase the vertex distance.", MessageType.Error);
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
EditorGUILayout.PropertyField(UVTiling);
|
||||
EditorGUILayout.PropertyField(noise);
|
||||
EditorGUILayout.PropertyField(boundsPadding);
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
autoApplyChanges = EditorGUILayout.Toggle("Auto-apply changes", autoApplyChanges);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (autoApplyChanges && HasModified())
|
||||
{
|
||||
#if UNITY_2022_2_OR_NEWER
|
||||
this.SaveChanges();
|
||||
#else
|
||||
this.ApplyAndImport();
|
||||
#endif
|
||||
|
||||
importer = (WaterMeshImporter)target;
|
||||
}
|
||||
}
|
||||
|
||||
this.ApplyRevertGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/zzwater/Editor/WaterMeshImporter.cs.meta
Normal file
11
Packages/zzwater/Editor/WaterMeshImporter.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb1723d9808f34b8fa4c8c24d2a380d9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
13
Packages/zzwater/Editor/ZZWaterEditor.cs
Normal file
13
Packages/zzwater/Editor/ZZWaterEditor.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace zz.water.editor
|
||||
{
|
||||
public class ZZWaterEditor
|
||||
{
|
||||
|
||||
[MenuItem("Assets/Create/ZZWater/Mesh")]
|
||||
private static void CreateWaterPlaneAsset() {
|
||||
ProjectWindowUtil.CreateAssetWithContent("NewWatermesh.watermesh", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Packages/zzwater/Editor/ZZWaterEditor.cs.meta
Normal file
11
Packages/zzwater/Editor/ZZWaterEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50a0ab452c7c345b28e21848e21f41da
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Packages/zzwater/Editor/zzwater.editor.asmdef
Normal file
16
Packages/zzwater/Editor/zzwater.editor.asmdef
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"name": "zzwater.editor",
|
||||
"rootNamespace": "zz.water.editor",
|
||||
"references": [],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
7
Packages/zzwater/Editor/zzwater.editor.asmdef.meta
Normal file
7
Packages/zzwater/Editor/zzwater.editor.asmdef.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e0e85f981a1e47ecb3f4ed489b3234e
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/zzwater/Mats.meta
Normal file
8
Packages/zzwater/Mats.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3280de512508543b3ab76c723264ea84
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
142
Packages/zzwater/Mats/Ocean.mat
Normal file
142
Packages/zzwater/Mats/Ocean.mat
Normal file
@@ -0,0 +1,142 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!21 &2100000
|
||||
Material:
|
||||
serializedVersion: 8
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_Name: Ocean
|
||||
m_Shader: {fileID: 4800000, guid: e52380eaa118b4aa7adc141fb339553b, type: 3}
|
||||
m_Parent: {fileID: 0}
|
||||
m_ModifiedSerializedProperties: 0
|
||||
m_ValidKeywords: []
|
||||
m_InvalidKeywords: []
|
||||
m_LightmapFlags: 4
|
||||
m_EnableInstancingVariants: 0
|
||||
m_DoubleSidedGI: 0
|
||||
m_CustomRenderQueue: -1
|
||||
stringTagMap: {}
|
||||
disabledShaderPasses: []
|
||||
m_LockedProperties:
|
||||
m_SavedProperties:
|
||||
serializedVersion: 3
|
||||
m_TexEnvs:
|
||||
- _BaseMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _BumpMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailAlbedoMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailMask:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _DetailNormalMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _EmissionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MainTex:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _MetallicGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _OcclusionMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _ParallaxMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- _SpecGlossMap:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_Lightmaps:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_LightmapsInd:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
- unity_ShadowMasks:
|
||||
m_Texture: {fileID: 0}
|
||||
m_Scale: {x: 1, y: 1}
|
||||
m_Offset: {x: 0, y: 0}
|
||||
m_Ints: []
|
||||
m_Floats:
|
||||
- _AlphaClip: 0
|
||||
- _AlphaToMask: 0
|
||||
- _Blend: 0
|
||||
- _BlendModePreserveSpecular: 1
|
||||
- _BumpScale: 1
|
||||
- _ClearCoatMask: 0
|
||||
- _ClearCoatSmoothness: 0
|
||||
- _Cull: 2
|
||||
- _Cutoff: 0.5
|
||||
- _DetailAlbedoMapScale: 1
|
||||
- _DetailNormalMapScale: 1
|
||||
- _DstBlend: 0
|
||||
- _DstBlendAlpha: 0
|
||||
- _EnvironmentReflections: 1
|
||||
- _GlossMapScale: 0
|
||||
- _Glossiness: 0
|
||||
- _GlossyReflections: 0
|
||||
- _Metallic: 0
|
||||
- _OcclusionStrength: 1
|
||||
- _Parallax: 0.005
|
||||
- _QueueOffset: 0
|
||||
- _ReceiveShadows: 1
|
||||
- _Smoothness: 0.5
|
||||
- _SmoothnessTextureChannel: 0
|
||||
- _SpecularHighlights: 1
|
||||
- _Speed: 1
|
||||
- _SrcBlend: 1
|
||||
- _SrcBlendAlpha: 1
|
||||
- _Surface: 0
|
||||
- _WaveCount: 2
|
||||
- _WaveDistance: 0.8
|
||||
- _WaveHeight: 0.25
|
||||
- _WaveNormalStr: 0.5
|
||||
- _WaveSpeed: 2
|
||||
- _WaveSteepness: 0.1
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 1
|
||||
m_Colors:
|
||||
- _BaseColor: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Color: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _Direction: {r: 0, g: -1, b: 0, a: 0}
|
||||
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
|
||||
- _SpecColor: {r: 0.19999996, g: 0.19999996, b: 0.19999996, a: 1}
|
||||
- _WaveDirection: {r: 1, g: 1, b: 1, a: 1}
|
||||
- _WaveFadeDistance: {r: 150, g: 300, b: 0, a: 0}
|
||||
m_BuildTextureStacks: []
|
||||
--- !u!114 &1635733923474585344
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 11
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
version: 7
|
||||
8
Packages/zzwater/Mats/Ocean.mat.meta
Normal file
8
Packages/zzwater/Mats/Ocean.mat.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78d9bfe8efde04cf3adb769d7539ebf7
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 2100000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Packages/zzwater/package.json
Normal file
22
Packages/zzwater/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "zzwater",
|
||||
"description": "simplify Stylized water for the Universal Render Pipeline",
|
||||
"version": "1.6.0",
|
||||
"unity": "2021.3",
|
||||
"unityRelease": "16f1",
|
||||
"displayName": "zzwater",
|
||||
"dependencies": {
|
||||
"com.unity.render-pipelines.universal": "10.3.2"
|
||||
},
|
||||
"author": {
|
||||
"name": "Skistua",
|
||||
"email": "contact@staggart.xyz"
|
||||
},
|
||||
"keywords": [
|
||||
"water",
|
||||
"shader",
|
||||
"stylized",
|
||||
"mobile",
|
||||
"urp"
|
||||
]
|
||||
}
|
||||
7
Packages/zzwater/package.json.meta
Normal file
7
Packages/zzwater/package.json.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a59136cc9415c4004bf9129c3ac0af48
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/zzwater/shaders.meta
Normal file
8
Packages/zzwater/shaders.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a45f0495658a448c8829efdfc5415ab0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/zzwater/shaders/libs.meta
Normal file
8
Packages/zzwater/shaders/libs.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eee4bbf1e344f4122b2c5beb05048c2d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
56
Packages/zzwater/shaders/libs/Common.hlsl
Normal file
56
Packages/zzwater/shaders/libs/Common.hlsl
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
#ifndef WATER_COMMON_INCLUDED
|
||||
#define WATER_COMMON_INCLUDED
|
||||
|
||||
//As per the "Shader" section of the documentation, this is primarily used for synchronizing animations in networked applications.
|
||||
#define TIME_FRAG_INPUT input.uv.z
|
||||
#define TIME_VERTEX_OUTPUT output.uv.z
|
||||
|
||||
#define TIME ((TIME_FRAG_INPUT * _Speed) * -_Direction.xy)
|
||||
#define TIME_VERTEX ((TIME_VERTEX_OUTPUT * _Speed) * -_Direction.xy)
|
||||
|
||||
#define HORIZONTAL_DISPLACEMENT_SCALAR 0.01
|
||||
#define UP_VECTOR float3(0,1,0)
|
||||
#define RAD2DEGREE 57.29578
|
||||
|
||||
struct WaterSurface
|
||||
{
|
||||
float3 positionWS;
|
||||
float3 viewDelta; //Un-normalized view direction,
|
||||
float3 viewDir;
|
||||
|
||||
//Normal from the base geometry, in world-space
|
||||
float3 vertexNormal;
|
||||
|
||||
float3 albedo;
|
||||
float3 offset;
|
||||
float alpha;
|
||||
};
|
||||
|
||||
struct SceneDepth
|
||||
{
|
||||
float raw;
|
||||
float linear01;
|
||||
float eye;
|
||||
};
|
||||
|
||||
#define FAR_CLIP _ProjectionParams.z
|
||||
#define NEAR_CLIP _ProjectionParams.y
|
||||
//Scale linear values to the clipping planes for orthographic projection (unity_OrthoParams.w = 1 = orthographic)
|
||||
#define DEPTH_SCALAR (FAR_CLIP - NEAR_CLIP)
|
||||
|
||||
//Return depth based on the used technique (buffer, vertex color, baked texture)
|
||||
SceneDepth SampleDepth(float4 screenPos)
|
||||
{
|
||||
SceneDepth depth = (SceneDepth)0;
|
||||
|
||||
screenPos.xyz /= screenPos.w;
|
||||
|
||||
depth.raw = SampleSceneDepth(screenPos.xy);
|
||||
depth.eye = LinearEyeDepth(depth.raw, _ZBufferParams);
|
||||
depth.linear01 = Linear01Depth(depth.raw, _ZBufferParams) * DEPTH_SCALAR;
|
||||
|
||||
return depth;
|
||||
}
|
||||
|
||||
#endif
|
||||
7
Packages/zzwater/shaders/libs/Common.hlsl.meta
Normal file
7
Packages/zzwater/shaders/libs/Common.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d21056e9736804a9ba0680085db36f45
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
61
Packages/zzwater/shaders/libs/ForwardPass.hlsl
Normal file
61
Packages/zzwater/shaders/libs/ForwardPass.hlsl
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
struct SceneData
|
||||
{
|
||||
float4 positionSS; //Unnormalized
|
||||
float2 screenPos; //Normalized and no refraction
|
||||
float3 positionWS;
|
||||
|
||||
float viewDepth;
|
||||
float verticalDepth;
|
||||
};
|
||||
|
||||
void PopulateSceneData(inout SceneData scene, in Varyings input, in WaterSurface water, in float3 camPos)
|
||||
{
|
||||
scene.positionSS = input.screenPos;
|
||||
scene.screenPos = input.screenPos.xy / input.screenPos.w;
|
||||
|
||||
//Default for disabled depth texture
|
||||
scene.viewDepth = 1;
|
||||
scene.verticalDepth = 1;
|
||||
|
||||
//Screen depth Projection to world position
|
||||
SceneDepth depth = SampleDepth(scene.positionSS);
|
||||
float3 projWorldPos = depth.eye * (water.viewDir / input.screenPos.w) - camPos;
|
||||
scene.positionWS = -projWorldPos;
|
||||
|
||||
const float sceneDepth = depth.eye;
|
||||
const float clipSpaceDepth = LinearEyeDepth(input.positionCS.z, _ZBufferParams);
|
||||
//Z-distance to opaque surface
|
||||
scene.viewDepth = sceneDepth - clipSpaceDepth;
|
||||
|
||||
//Distance to opaque geometry in normal direction
|
||||
scene.verticalDepth = length((water.positionWS - scene.positionWS) * water.vertexNormal);
|
||||
//scene.verticalDepth = DepthDistance(water.positionWS, scene.positionWS, water.waveNormal * normalSign);
|
||||
}
|
||||
|
||||
float4 ForwardPassFragment(Varyings input) : SV_Target
|
||||
{
|
||||
WaterSurface water = (WaterSurface)0;
|
||||
SceneData scene = (SceneData)0;
|
||||
float3 camPos = GetCurrentViewPosition();
|
||||
|
||||
|
||||
float3 normalWS = normalize(input.normalWS.xyz);
|
||||
float3 WorldTangent = input.tangent.xyz;
|
||||
float3 WorldBiTangent = input.bitangent.xyz;
|
||||
//wPos.x in w-component
|
||||
float3 positionWS = float3(input.normalWS.w, input.tangent.w, input.bitangent.w);
|
||||
|
||||
water.alpha = 1.0;
|
||||
water.positionWS = positionWS;
|
||||
water.viewDelta = camPos - scene.positionWS;
|
||||
water.viewDir = normalize(water.viewDelta);
|
||||
water.vertexNormal = normalize(input.normalWS.xyz);
|
||||
|
||||
half VdotN = 1.0 - saturate(dot(water.viewDir, normalWS));
|
||||
|
||||
|
||||
PopulateSceneData(scene, input, water, camPos);
|
||||
|
||||
return float4(scene.viewDepth.xxx, 1);
|
||||
}
|
||||
7
Packages/zzwater/shaders/libs/ForwardPass.hlsl.meta
Normal file
7
Packages/zzwater/shaders/libs/ForwardPass.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95ba63cd357fb4f8f9c245d81f3e78a3
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Packages/zzwater/shaders/libs/Input.hlsl
Normal file
17
Packages/zzwater/shaders/libs/Input.hlsl
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
CBUFFER_START(UnityPerMaterial)
|
||||
|
||||
float2 _Direction;
|
||||
float _Speed;
|
||||
|
||||
//Waves
|
||||
float _WaveSpeed;
|
||||
half _WaveHeight;
|
||||
half _WaveNormalStr;
|
||||
float _WaveDistance;
|
||||
half2 _WaveFadeDistance;
|
||||
float _WaveSteepness;
|
||||
uint _WaveCount;
|
||||
half4 _WaveDirection;
|
||||
|
||||
CBUFFER_END
|
||||
7
Packages/zzwater/shaders/libs/Input.hlsl.meta
Normal file
7
Packages/zzwater/shaders/libs/Input.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95a615afb06ca4ffdba1edec02894c54
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
35
Packages/zzwater/shaders/libs/URP.hlsl
Normal file
35
Packages/zzwater/shaders/libs/URP.hlsl
Normal file
@@ -0,0 +1,35 @@
|
||||
|
||||
//Stylized Water 2
|
||||
//Staggart Creations (http://staggart.xyz)
|
||||
//Copyright protected under Unity Asset Store EULA
|
||||
|
||||
#ifndef PIPELINE_INCLUDED
|
||||
#define PIPELINE_INCLUDED
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderVariablesFunctions.hlsl"
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl"
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
|
||||
|
||||
#ifdef POST_PROCESSING //These would have the core blit library included
|
||||
#define UNITY_CORE_SAMPLERS_INCLUDED
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_CORE_SAMPLERS_INCLUDED //Backwards compatibility for <2023.1+
|
||||
#define UNITY_CORE_SAMPLERS_INCLUDED
|
||||
|
||||
SamplerState sampler_LinearClamp;
|
||||
SamplerState sampler_PointClamp;
|
||||
SamplerState sampler_PointRepeat;
|
||||
SamplerState sampler_LinearRepeat;
|
||||
#endif
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
|
||||
|
||||
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
7
Packages/zzwater/shaders/libs/URP.hlsl.meta
Normal file
7
Packages/zzwater/shaders/libs/URP.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4cafd3b397c0142d8a82101a49d68e45
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
65
Packages/zzwater/shaders/libs/Vertex.hlsl
Normal file
65
Packages/zzwater/shaders/libs/Vertex.hlsl
Normal file
@@ -0,0 +1,65 @@
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float4 uv : TEXCOORD0;
|
||||
float4 normalOS : NORMAL;
|
||||
float4 tangentOS : TANGENT;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 uv : TEXCOORD0;
|
||||
|
||||
half4 fogFactorAndVertexLight : TEXCOORD1; // x: fogFactor, yzw: vertex light
|
||||
|
||||
//wPos.x in w-component
|
||||
float4 normalWS : NORMAL;
|
||||
//wPos.y in w-component
|
||||
float4 tangent : TANGENT;
|
||||
//wPos.z in w-component
|
||||
float4 bitangent : TEXCOORD4;
|
||||
|
||||
float4 screenPos : TEXCOORD5;
|
||||
|
||||
float4 positionCS : SV_POSITION;
|
||||
|
||||
UNITY_VERTEX_INPUT_INSTANCE_ID
|
||||
};
|
||||
|
||||
|
||||
Varyings LitPassVertex(Attributes input)
|
||||
{
|
||||
Varyings output = (Varyings)0;
|
||||
|
||||
UNITY_SETUP_INSTANCE_ID(input);
|
||||
UNITY_TRANSFER_INSTANCE_ID(input, output);
|
||||
|
||||
output.uv.xy = input.uv.xy;
|
||||
output.uv.z = _TimeParameters.x;
|
||||
output.uv.w = 0;
|
||||
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
||||
|
||||
VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS.xyz, input.tangentOS);
|
||||
|
||||
float2 uv = positionWS.xz;
|
||||
|
||||
//WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, lerp(1, 0, vertexColor.b), _WaveFadeDistance.x, _WaveFadeDistance.y);
|
||||
WaveInfo waves = GetWaveInfo(uv, TIME_VERTEX * _WaveSpeed, _WaveHeight, 1, _WaveFadeDistance.x, _WaveFadeDistance.y);
|
||||
|
||||
//Apply vertex displacements
|
||||
positionWS += waves.position.xyz;
|
||||
|
||||
output.positionCS = TransformWorldToHClip(positionWS);
|
||||
|
||||
output.screenPos = ComputeScreenPos(output.positionCS);
|
||||
|
||||
output.normalWS = float4(normalInput.normalWS, positionWS.x);
|
||||
output.tangent = float4(normalInput.tangentWS, positionWS.y);
|
||||
output.bitangent = float4(normalInput.bitangentWS, positionWS.z);
|
||||
|
||||
return output;
|
||||
}
|
||||
7
Packages/zzwater/shaders/libs/Vertex.hlsl.meta
Normal file
7
Packages/zzwater/shaders/libs/Vertex.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1b8012d27dd264d5b8cdfb43d1dd1998
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
102
Packages/zzwater/shaders/libs/Waves.hlsl
Normal file
102
Packages/zzwater/shaders/libs/Waves.hlsl
Normal file
@@ -0,0 +1,102 @@
|
||||
|
||||
|
||||
struct WaveInfo
|
||||
{
|
||||
float3 position;
|
||||
float3 normal;
|
||||
};
|
||||
|
||||
float3 GerstnerOffset4(float2 xzVtx, float4 steepness, float4 amp, float4 freq, float4 speed, float4 dirAB, float4 dirCD)
|
||||
{
|
||||
float3 offsets;
|
||||
|
||||
float4 AB = steepness.xxyy * dirAB.xyzw * amp.xxyy;
|
||||
float4 CD = steepness.zzww * dirCD.xyzw * amp.zzww;
|
||||
|
||||
float4 dotABCD = freq.xyzw * float4(dot(dirAB.xy, xzVtx), dot(dirAB.zw, xzVtx), dot(dirCD.xy, xzVtx), dot(dirCD.zw, xzVtx));
|
||||
|
||||
float4 COS = cos(dotABCD + speed); float4 SIN = sin(dotABCD + speed);
|
||||
|
||||
offsets.x = dot(COS, float4(AB.xz, CD.xz));
|
||||
offsets.z = dot(COS, float4(AB.yw, CD.yw));
|
||||
offsets.y = dot(SIN, amp); //Remap to only positive values;
|
||||
|
||||
return offsets;
|
||||
}
|
||||
|
||||
float3 GerstnerNormal4(float2 xzVtx, float4 amp, float4 freq, float4 speed, float4 dirAB, float4 dirCD)
|
||||
{
|
||||
float3 nrml = float3(0, 2.0, 0);
|
||||
|
||||
float4 AB = freq.xxyy * amp.xxyy * dirAB.xyzw;
|
||||
float4 CD = freq.zzww * amp.zzww * dirCD.xyzw;
|
||||
|
||||
float4 dotABCD = freq.xyzw * float4(dot(dirAB.xy, xzVtx), dot(dirAB.zw, xzVtx), dot(dirCD.xy, xzVtx), dot(dirCD.zw, xzVtx));
|
||||
|
||||
float4 COS = cos(dotABCD + speed);
|
||||
|
||||
nrml.x -= dot(COS, float4(AB.xz, CD.xz));
|
||||
nrml.z -= dot(COS, float4(AB.yw, CD.yw));
|
||||
|
||||
nrml.xz *= _WaveNormalStr;
|
||||
nrml = normalize(nrml);
|
||||
|
||||
return nrml;
|
||||
}
|
||||
|
||||
void Gerstner(inout float3 offs, inout float3 nrml,
|
||||
float2 position,
|
||||
float4 amplitude, float4 frequency, float4 steepness,
|
||||
float4 speed, float4 directionAB, float4 directionCD)
|
||||
{
|
||||
offs += GerstnerOffset4(position, steepness, amplitude, frequency, speed, directionAB, directionCD);
|
||||
nrml += GerstnerNormal4(position, amplitude, frequency, speed, directionAB, directionCD);
|
||||
}
|
||||
|
||||
#define WAVE_COUNT _WaveCount
|
||||
#define MAX_WAVE_COUNT 5
|
||||
|
||||
|
||||
#define STEEPNESS_SCALE 0.01
|
||||
|
||||
//v1.1.8+
|
||||
WaveInfo GetWaveInfo(float2 position, float2 time, float height, float mask, float fadeStart, float fadeEnd)
|
||||
{
|
||||
WaveInfo waves = (WaveInfo)0;
|
||||
|
||||
float4 amp = float4(0.3, 0.35, 0.25, 0.25);
|
||||
float4 freq = float4(1.3, 1.35, 1.25, 1.25) * (1-_WaveDistance) * 3.0;
|
||||
const float4 speed = float4(1.2* time.x, 1.375* time.y, 1.1 * time.x, time.y) ; //Pre-multiplied with time
|
||||
const float4 dir1 = float4(0.3, 0.85, 0.85, 0.25) * _WaveDirection;
|
||||
const float4 dir2 = float4(0.1, 0.9, -0.5, -0.5) * _WaveDirection;
|
||||
const float4 steepness = float4(12.0, 12.0, 12.0, 12.0) * _WaveSteepness * lerp(1.0, MAX_WAVE_COUNT, 1/WAVE_COUNT);
|
||||
|
||||
//Distance based scalar
|
||||
float pixelDist = length(GetCurrentViewPosition().xz - position.xy);
|
||||
float fadeFactor = saturate((fadeEnd - pixelDist ) / (fadeEnd-fadeStart));
|
||||
|
||||
for (uint i = 0; i <= WAVE_COUNT; i++)
|
||||
{
|
||||
float t = 1+((float)i / (float)WAVE_COUNT);
|
||||
freq *= t;
|
||||
amp *= fadeFactor;
|
||||
|
||||
Gerstner(/*out*/ waves.position, /*out*/ waves.normal, position, amp, freq, steepness, speed, dir1, dir2);
|
||||
}
|
||||
|
||||
waves.normal = normalize(waves.normal);
|
||||
//Average
|
||||
waves.position.y /= WAVE_COUNT;
|
||||
//waves.normal.xz *= WAVE_COUNT;
|
||||
|
||||
waves.position.xz *= STEEPNESS_SCALE * height * mask;
|
||||
waves.position.y *= height * mask;
|
||||
|
||||
return waves;
|
||||
}
|
||||
|
||||
//Depricated
|
||||
WaveInfo GetWaveInfo(float2 position, float2 time, float fadeStart, float fadeEnd)
|
||||
{
|
||||
return GetWaveInfo(position, time, 1.0, 1.0, fadeStart, fadeEnd);
|
||||
}
|
||||
7
Packages/zzwater/shaders/libs/Waves.hlsl.meta
Normal file
7
Packages/zzwater/shaders/libs/Waves.hlsl.meta
Normal file
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9f90fe52c92f4d888cec5bf14c4cb9f
|
||||
ShaderIncludeImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
71
Packages/zzwater/shaders/ocean.shader
Normal file
71
Packages/zzwater/shaders/ocean.shader
Normal file
@@ -0,0 +1,71 @@
|
||||
Shader "zzwater/ocean"
|
||||
{
|
||||
Properties
|
||||
{
|
||||
_Direction("Animation direction", Vector) = (0,-1,0,0)
|
||||
_Speed("Animation Speed", Float) = 1
|
||||
|
||||
//waves
|
||||
_WaveSpeed("Speed", Float) = 2
|
||||
_WaveHeight("Height", Range(0 , 10)) = 0.25
|
||||
|
||||
_WaveNormalStr("Normal Strength", Range(0 , 32)) = 0.5
|
||||
_WaveDistance("Distance", Range(0 , 1)) = 0.8
|
||||
_WaveFadeDistance("Wave fade distance (Start/End)", Vector) = (150, 300, 0, 0)
|
||||
|
||||
_WaveSteepness("Steepness", Range(0 , 5)) = 0.1
|
||||
_WaveCount("Count", Range(1 , 5)) = 1
|
||||
_WaveDirection("Direction", vector) = (1,1,1,1)
|
||||
}
|
||||
|
||||
SubShader
|
||||
{
|
||||
Tags
|
||||
{
|
||||
"RenderType" = "Transparent"
|
||||
"RenderPipeline" = "UniversalPipeline"
|
||||
"UniversalMaterialType" = "Lit"
|
||||
"IgnoreProjector" = "True"
|
||||
"Queue" = "Transparent+0"
|
||||
}
|
||||
|
||||
Pass
|
||||
{
|
||||
Name "ForwardLit"
|
||||
Tags { "LightMode"="UniversalForward" }
|
||||
|
||||
Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
|
||||
ZWrite Off
|
||||
Cull Back
|
||||
ZTest LEqual
|
||||
ZClip On
|
||||
|
||||
HLSLPROGRAM
|
||||
|
||||
#pragma target 3.0
|
||||
|
||||
#pragma multi_compile_instancing
|
||||
#pragma instancing_options renderinglayer
|
||||
#include_with_pragmas "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/URP.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Common.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Input.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Waves.hlsl"
|
||||
#include "Packages/zzwater/shaders/libs/Vertex.hlsl"
|
||||
|
||||
#pragma vertex Vertex
|
||||
|
||||
Varyings Vertex(Attributes v)
|
||||
{
|
||||
return LitPassVertex(v);
|
||||
}
|
||||
|
||||
#pragma fragment ForwardPassFragment
|
||||
#include "Packages/zzwater/shaders/libs/ForwardPass.hlsl"
|
||||
|
||||
ENDHLSL
|
||||
|
||||
}
|
||||
}
|
||||
FallBack "Diffuse"
|
||||
}
|
||||
9
Packages/zzwater/shaders/ocean.shader.meta
Normal file
9
Packages/zzwater/shaders/ocean.shader.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e52380eaa118b4aa7adc141fb339553b
|
||||
ShaderImporter:
|
||||
externalObjects: {}
|
||||
defaultTextures: []
|
||||
nonModifiableTextures: []
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user