Unity3D Shader :浮雕

Shader "Custom/Test" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader {
pass{
Tags{"LightMode"="ForwardBase"}
Cull off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"


float4 _Color;
sampler2D _MainTex;
float4 _MainTex_ST;
float _Size;


struct v2f{
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
v2f vert(appdata_full v)
{
v2f o;
o.pos=UnityObjectToClipPos(v.vertex);
o.uv=TRANSFORM_TEX(v.texcoord,_MainTex);
return o;
}
float4 frag(v2f i):SV_Target
{
float3 m_n=tex2D(_MainTex,i.uv).rgb;
float3 m_l=tex2D(_MainTex,i.uv+float2(1/_ScreenParams.x,1/_ScreenParams.y)).rgb;
float3 diff=abs(m_n-m_l);
float max=diff.r>diff.g?diff.r:diff.g;
max=max>diff.b?max:diff.b;
float gray=clamp(max+0.4,0,1);
float4 c;
c=float4(gray.xxx,1)*_Color;
return c;
}
ENDCG
}
}
FallBack "Diffuse"

}



猜你喜欢

转载自blog.csdn.net/weixin_42452001/article/details/80737645