Shader "Custom/Outline_2Pass" {
Properties{
_MainTex("Albedo", 2D) = "white" {}
_BumpMap("BumpMap", 2D) = "bump" {}
_OutlineColor("OutlineColor", Color) = (1,1,1,1)
_Outline("Outline", Range(0.0005, 0.01)) = 0.01
}
SubShader{
Tags { "RenderType" = "Opaque" }
Cull front
// Pass1
CGPROGRAM
#pragma surface surf NoLighting vertex:vert noshadow noambient
struct Input {
float4 color : Color;
};
float4 _OutlineColor;
float _Outline;
void vert(inout appdata_full v)
{
v.vertex.xyz += v.normal.xyz * _Outline;
}
void surf(Input In, inout SurfaceOutput o)
{
}
float4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
return _OutlineColor;
}
ENDCG
// Pass2
Cull back
CGPROGRAM
#pragma surface surf Toon noambient
float4 _Color;
sampler2D _MainTex;
sampler2D _BumpMap;
struct Input {
float2 uv_MainTex;
float2 uv_BumpMap;
float4 color : Color;
};
void surf(Input In, inout SurfaceOutput o)
{
float4 c = tex2D(_MainTex, In.uv_MainTex);
o.Albedo = c.rgb;
o.Normal = UnpackNormal(tex2D(_BumpMap, In.uv_BumpMap));
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
float ndotl = dot(s.Normal, lightDir) * 0.5 + 0.5;
if (ndotl > 0.7) {
ndotl = 1;
}
else if (ndotl > 0.4) {
ndotl = 0.3;
}
else {
ndotl = 0;
}
float4 final;
final.rgb = s.Albedo * ndotl * _LightColor0.rgb;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
'개발 > Unity, C#' 카테고리의 다른 글
C# 생성자와 가상 함수 (0) | 2021.05.09 |
---|---|
Unity C# Enum 사용시 Garbage 문제??? (0) | 2021.03.01 |
Unity 하드웨어 스펙으로 자동 옵션 세팅하기 (0) | 2020.10.18 |
Unity 배경을 투명하게 캡처하는 방법 (1) | 2020.07.26 |
C# Closure 클로저 (0) | 2020.04.18 |