Shader代码
顶点着色器实现水面的起伏效果
片元着色器实现波纹效果(没有运行,所以看上去是规律的黑色斑点。。。)
各种函数实现取自Unity官网对ShaderGraph的Node的解析
Properties
{
_MainTex ("Texture", 2D) = "white" {
}
_WaterSpeed("波浪起伏的速度", float) = 0.2
_WaterScale("波浪的范围", float) = 2
_RippleSpeed("波纹的速度",float) = 1
_RippleDensity("波纹的密度",float) = 1
_RippleRate("波纹的大小系数",float) = 1
_RippleColor("波纹的颜色",color) = (1,1,1,1)
_WaveColor("海水的颜色",color) = (1,1,1,1)
}
SubShader
{
Tags {
"RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
// make fog work
#pragma multi_compile_fog
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal: NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 objPos:TEXCOORD1;
float3 Objnormal: NORMAL;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _WaterSpeed;
float _WaterScale;
float _RippleSpeed