在法线连续的情况下效果凑合,目前项目着急,先用着,以后有时间慢慢改进。
Shader "ShenDong/SimpleSection"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_UVMulti("UV Multi",float) = 1
}
SubShader
{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f
{
float3 normal : NORMAL;
float4 vertex : TEXCOORD0;
float4 screenvert : SV_POSITION;
};
sampler2D _MainTex;
float4 _MainTex_ST;
float _UVMulti;
float2 hash22(float2 p) {
p = float2(dot(p, float2(127.1, 311.7)), dot(p, float2(269.5, 183.3)));
return -1.0 + 2.0 * frac(sin(p) * 43758.5453123);
}
float perlin_noise(float2 p) {
float2 pi = floor(p);
float2 pf = p - pi;
float2 w = pf * pf * (3.0 - 2.0 * pf);
return lerp(lerp(dot(hash22(pi + float2(0.0, 0.0)), pf - float2(0.0, 0.0)),
dot(hash22(pi + float2(1.0, 0.0)), pf - float2(1.0, 0.0)), w.x),
lerp(dot(hash22(pi + float2(0.0, 1.0)), pf - float2(0.0, 1.0)),
dot(hash22(pi + float2(1.0, 1.0)), pf - float2(1.0, 1.0)), w.x), w.y);
}
v2f vert(appdata v)
{
v2f o;
o.vertex = v.vertex;
o.normal = v.normal;
o.screenvert = UnityObjectToClipPos(v.vertex);
return o;
}
fixed4 frag(v2f i) : SV_Target
{
float3 f3 = i.vertex.xyz;
f3 *= _UVMulti;
f3.x = frac(f3.x);
f3.y = frac(f3.y);
f3.z = frac(f3.z);
fixed4 c0 = tex2D(_MainTex, f3.xy);
fixed4 c1 = tex2D(_MainTex, f3.yz);
fixed4 c2 = tex2D(_MainTex, f3.zx);
return c0 * i.normal.z * i.normal.z + c1 * i.normal.x * i.normal.x + c2 * i.normal.y * i.normal.y;
}
ENDCG
}
}
}