一、效果图
网上随便找的一张图,大家可以去网上搜一下资源
卡通效果.png
二、代码部分
下面的实现代码使用表面着色器书写的
Shader "Custom/ExtrusionShader" {
Properties {
//主贴图、法线贴图、人物变形范围属性
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_BumpTex("BumpTex",2D)=""{}
_Power("power",Range(0,0.2))=0.1
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows Vertex:Vert
//将贴图储存在sampler2D中
sampler2D _MainTex;
sampler2D _BumpTex;
//定义_Power
fixed _Power;
//输入结构2个贴图的uv坐标
struct Input {
float2 uv_MainTex;
float2 uv_BumpTex;
};
//实现人物变形的方法,将顶点的坐标值加上顶点的法线坐标,再乘上变形范围
void Vert(inout appdata_full v)
{
v.vertex.xyz += v.normal * _Power;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo comes from a texture tinted by color
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) ;
o.Albedo=c.rgb;
o.Normal = UnpackNormal(tex2D(_BumpTex,IN.uv_BumpTex));
}
ENDCG
}
FallBack "Diffuse"
}
网友评论