水墨感动态纹样
其实不算混合纹理,混合颜色可能恰当一点。若要改成纹理,将Color的部分更换成图片就可以了。其实没有完全解决接缝问题,待修改。
不用噪声的版本我也挺喜欢的,但是实用性不是很大。
Shader "Custom/sd_MixedColor"
{
Properties
{
_MainTex("Main Color", 2D) = ""{}
_NoiseMap("Noise Map", 2D) = ""{}
_NoisePower("Power of Noise", Range(0, 10)) = 2
_ColorR("R Channel Color", Color) = (1,1,1,1)
_ColorG("G Channel Color", Color) = (1,1,1,1)
_ColorB("B Channel Color", Color) = (1,1,1,1)
_ColorA("A Channel Color", Color) = (1,1,1,1)
_PlaySpeed("Play Speed", Range(0.1, 1)) = 0.5
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard fullforwardshadows
#pragma target 3.0
sampler2D _MainTex, _NoiseMap;
struct Input
{
float2 uv_MainTex, uv_NoiseMap;
};
fixed4 _ColorR;
fixed4 _ColorG;
fixed4 _ColorB;
fixed4 _ColorA;
fixed _NoisePower;
fixed _PlaySpeed;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed scrollNoiseVal = _NoisePower * _Time;
//float4 noiseMap = tex2D(_NoiseMap,IN.uv_NoiseMap + scrollNoiseVal);
float4 noiseMap = tex2D(_NoiseMap,IN.uv_NoiseMap);
float2 center = (0.5, 0.5);
float2 dt = IN.uv_MainTex - center;
float n_dt = normalize(dt)* _PlaySpeed;
float4 blendData = tex2D(_MainTex,IN.uv_MainTex + n_dt * _SinTime + noiseMap * _NoisePower);
float4 finalColor;
finalColor = lerp(_ColorR, _ColorG, blendData.g);
finalColor = lerp(finalColor, _ColorB, blendData.b);
finalColor = lerp(finalColor, _ColorA, blendData.a);
finalColor.a = 1;
finalColor = saturate(finalColor);
o.Albedo = finalColor.rgb;
o.Alpha = finalColor.a;
}
ENDCG
}
FallBack "Diffuse"
}
没有噪声扰动的效果,还挺丝滑的:
海滩
深色海水部分其实是有纹理的 gif质量太差看不清
Shader "Custom/sd_MixedColor"
{
Properties
{
_MainTex("Blend Data", 2D) = ""{} //主blend纹理信息图
_NoiseMap("Noise Map", 2D) = ""{} //水波噪声图
_NoisePower("Power of Noise", Range(0, 0.3)) = 0.2 //噪声强度
_ColorR("R Channel Color", Color) = (1,1,1,1) //R空间颜色
_ColorG("G Channel Color", Color) = (1,1,1,1) //G空间颜色
_ColorB("B Channel Color", Color) = (1,1,1,1) //B空间颜色
_TexB("B Channel Tex", 2D) = ""{} //B空间贴图
_BTexA("Alpha of BTex", Range(0, 1)) = 0.5 //B空间贴图的Alpha值
_ColorA("A Channel Color", Color) = (1,1,1,1) //Alpha空间的颜色
_Alpha("Alpha of Water", Range(0, 1)) = 0.5 //整体水域Alpha值
}
SubShader
{
Tags { "RenderType"= "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Standard
#pragma target 3.0
sampler2D _MainTex, _NoiseMap;
sampler2D _TexB;
struct Input
{
float2 uv_MainTex, uv_NoiseMap;
float2 uv_TexB;
};
fixed4 _ColorR;
fixed4 _ColorG;
fixed4 _ColorB;
fixed _BTexA;
fixed4 _ColorA;
fixed _NoisePower;
fixed _Alpha;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
//贴图处理-------------------------
fixed scrollNoiseVal = _NoisePower * _Time;//噪声因子
float4 noiseMap = tex2D(_NoiseMap,IN.uv_NoiseMap + scrollNoiseVal);//使噪声map流动
float4 picB = lerp(_ColorB, tex2D(_TexB, IN.uv_TexB + noiseMap) * _ColorB, _BTexA);//控制B空间贴图的Alpha值
float4 blendData = tex2D(_MainTex,IN.uv_MainTex + noiseMap * _NoisePower + _SinTime.w * 0.1);//利用噪声扰动BlendUV
//颜色处理--------------------------
float4 finalColor;
finalColor = lerp(_ColorG, _ColorR, blendData.r);//为R空间赋值(G和B有混合)
finalColor = lerp(finalColor, _ColorG, blendData.g);//为R空间赋值
finalColor = lerp(finalColor, picB, blendData.b);//为B空间赋值
//Alpha设置------------------------
finalColor = lerp(finalColor, _ColorA, (1-_Alpha));//设置水域整体的Alpha(有水or无水)
finalColor = lerp(finalColor, _ColorA, (1 - blendData.a));//设置非水域部分的颜色
finalColor = saturate(finalColor);//标准化
//赋值------------------------------
o.Albedo = finalColor.rgb;
o.Alpha = finalColor.a;
}
ENDCG
}
FallBack "Diffuse"
}