给我写一段卡通PBR皮肤shader
时间: 2023-11-27 21:55:02 浏览: 136
DoubleSide(PBR).shader
好的,以下是一段卡通PBR皮肤shader的示例代码(基于Unity引擎):
```
Shader "Custom/CartoonPBR" {
Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_NormalMap ("Normal Map", 2D) = "bump" {}
_Metallic ("Metallic", Range(0,1)) = 0
_Smoothness ("Smoothness", Range(0,1)) = 0.5
_EmissionColor ("Emissive Color", Color) = (0,0,0,0)
_EmissionIntensity ("Emissive Intensity", Range(0,1)) = 0
}
SubShader {
Tags {"Queue"="Transparent" "RenderType"="Opaque"}
CGPROGRAM
#pragma surface surf Standard
sampler2D _MainTex;
sampler2D _NormalMap;
float _Metallic;
float _Smoothness;
float _EmissionIntensity;
fixed4 _EmissionColor;
struct Input {
float2 uv_MainTex;
float3 worldPos;
float3 worldNormal;
};
void surf (Input IN, inout SurfaceOutputStandard o) {
// Albedo
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
// Normal map
o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
// Metallic
o.Metallic = _Metallic;
// Smoothness
o.Smoothness = _Smoothness;
// Emission
o.Emission = _EmissionColor.rgb * _EmissionIntensity;
// Specular
o.Specular = 0.2;
// Translucency
o.Subsurface = 0.5;
o.SubsurfaceColor = c.rgb;
// Rim lighting
float rim = 1.0 - saturate(dot(IN.worldNormal, normalize(IN.worldPos - _WorldSpaceCameraPos)));
o.Emission += _EmissionColor.rgb * rim * _EmissionIntensity;
}
ENDCG
}
FallBack "Diffuse"
}
```
这个shader实现了卡通PBR皮肤效果,包括漫反射、法线贴图、金属度、光滑度、自发光、高光、透光和边缘光等。你可以根据需要调整各个参数,使得皮肤看起来更加逼真或是更加卡通。
阅读全文