普通的摇晃.ver
Shader "Custom/sd_Water3"
{
Properties
{
_WaterColor("Water Color 水体染色", Color) = (1,1,1,1)
_Alpha("Alpha", Range(0,1)) = 0.5
_MainTex ("Albedo (RGB) 水面贴图", 2D) = "white" {}
_WaveDen("Density of Waves 水波频率",Range(0,1.4)) = 0.8
_WaveIts("Intensity of Waves 水波强度",Range(-1, 1)) = 1
_WaveSpeed("Speed of Waves", Range(0.1, 80)) = 10
}
SubShader
{
Tags {
"RenderType"="Transparent"
"IgnoreProject" = "True"
"Queue" = "Transparent"}
LOD 200
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma surface surf Standard vertex:vert alpha:fade fragment frag
#pragma target 3.0
sampler2D _MainTex;
sampler2D _CameraDepthTexture;//内置变量
struct Input
{
float2 uv_MainTex;
};
fixed4 _WaterColor;
fixed _WaveDen, _WaveIts, _WaveSpeed, _Alpha;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _WaterColor;
o.Albedo = c.rgb;
o.Alpha = _Alpha;
}
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
float time = _WaveSpeed * _Time;
float waveValue = sin(time + v.vertex.x * _WaveDen) * _WaveIts;//偏移量
v.vertex.xyz = float3(v.vertex.x, v.vertex.y + waveValue, v.vertex.z);
}
ENDCG
}
FallBack "Diffuse"
}
波纹+扰动+Alpha.ver
Shader "HomeworkShader/Water"
{
Properties
{
_MainTint("Tint",Color) = (1,1,1,1)
_MainTex ("水纹贴图", 2D) = "white" {}
_WaterAlpha("水不透明度",Range(0,1)) = 0.5
_ScrollSpeed("贴图滚动速度", Range(0,10)) = 2
_NoiseTex("水波噪声贴图",2D) = "white"{}
_Amount("噪声影响因子", Range(0,2)) = 1
_Frequency("水波频率",Range(0,1.4)) = 0.8
_WaveSpeed("水波速度",Range(0.1, 80)) = 10
_Amplitude("水波振幅", Range(-1, 1)) = 1
_CWaveVal("水环振幅", Range(.01, 20)) = 1
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"RenderType"="Transparent"
}
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard alpha:fade
#pragma vertex vert
#pragma target 4.0
struct Input
{
float2 uv_MainTex;
float2 uv_StoneTex;
float2 uv_NoiseTex;
};
fixed4 _MainTint;
fixed _ScrollSpeed;
sampler2D _MainTex;
sampler2D _NoiseTex;
fixed _WaterAlpha;
fixed _Amount;
fixed _Frequency;
fixed _WaveSpeed;
fixed _Amplitude;
float _CWaveVal;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
//引入贴图
fixed2 scrolledUV = IN.uv_MainTex;
fixed2 noiseTex = IN.uv_NoiseTex;
//流动
fixed ScrollValue = _ScrollSpeed * _Time;//非交替定向流动
half4 n = tex2D (_NoiseTex,noiseTex) * _Amount;//噪声因子
scrolledUV += fixed2(ScrollValue + n.x, ScrollValue + n.y);//x,y方向各自偏移量
//圆环旋转
float2 center = (0.5, 0.5);//若要中点,注意与平铺值的一半对应;此处平铺为1,1
float2 dt = IN.uv_MainTex - center;
float len = length(dt);//偏移量
float intensity = sin(_SinTime.x * 3) * _CWaveVal;//旋转强度因子
float off = len * intensity;//对应uv旋转量
float2x2 rot = float2x2(cos(off), -sin(off), sin(off), cos(off));//二维空间旋转矩阵
dt = mul(rot, dt) + center;//乘旋转矩阵,加上需要偏移中心的量
half4 c = tex2D(_MainTex, dt + scrolledUV);//uv偏移(圆环与流动)
//赋值输出
o.Albedo = c.rgb * _MainTint;
o.Alpha = _WaterAlpha;
}
void vert(inout appdata_full v, out Input o)
{
UNITY_INITIALIZE_OUTPUT(Input,o);
float time = _WaveSpeed * _Time;
float waveValue = sin(time + v.vertex.x * _Frequency) * _Amplitude;//偏移量
v.vertex.xyz = float3(v.vertex.x, v.vertex.y + waveValue, v.vertex.z);//在y轴附加偏移量
}
ENDCG
}
FallBack "Diffuse"
}
平静的波光粼粼 + 混合纹理.ver
其实这一part的混合纹理用的不是很好,水面的高光部分完全可以用白色(颜色)替代。
Shader "Custom/sd_WaterBubble"
{
Properties
{
_RChannelTint("RChannel Tint", Color) = (1,1,1,1)
_BlendTex("Blend Channel混合指示图", 2D) = "white"{}
_RTex("Red Channel",2D) = ""{}
_GTex("Green Channel", 2D) = ""{}
_BTex("Blue Channel", 2D) = ""{}
_ATex("Alpha Channel",2D) = ""{}
_NoiseMap("Noise Map",2D) = ""{}
_Alpha("Alpha", Range(0,1)) = 0.5
}
SubShader
{
Tags {
"RenderType"="Transparent"
"Queue" = "Transparent"
"IgnoreProjector" = "True"
}
LOD 200
CGPROGRAM
#pragma surface surf Standard alpha:fade
#pragma target 4.0
sampler2D _BlendTex;
sampler2D _RTex;
sampler2D _GTex;
sampler2D _BTex;
sampler2D _ATex;
sampler2D _NoiseMap;
struct Input
{
fixed2 uv_BlendTex;
fixed2 uv_RTex;
fixed2 uv_GTex;
fixed2 uv_BTex;
fixed2 uv_ATex;
fixed2 uv_NoiseMap;
};
fixed _Alpha;
fixed4 _RChannelTint;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed2 noiseTex = IN.uv_NoiseMap;
fixed ScrollUV = _Time * 3;
half4 n = tex2D(_NoiseMap, noiseTex) * 2;
ScrollUV += fixed2(ScrollUV + n.x, ScrollUV + n.y);
fixed4 blendData = tex2D(_BlendTex, IN.uv_BlendTex + ScrollUV);
fixed4 rTex = tex2D(_RTex, IN.uv_RTex);
fixed4 gTex = tex2D(_GTex, IN.uv_GTex);
fixed4 bTex = tex2D(_BTex, IN.uv_BTex);
fixed4 aTex = tex2D(_ATex, IN.uv_ATex) * _RChannelTint;
float4 finalColor;
finalColor = lerp(rTex, gTex, blendData.g);
finalColor = lerp(finalColor, bTex, blendData.b);
finalColor = lerp(finalColor, aTex, blendData.a);
finalColor = saturate(finalColor);
o.Albedo = finalColor.rgb;
o.Alpha = _Alpha;
}
ENDCG
}
FallBack "Diffuse"
}