반응형
텍스쳐 한 장을 받는 쉐이더 스크립터를 만들어준다.
Toon 으로 커스텀 라이트를 만들어준다.
Shader "Custom/Test"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Toon noambient
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, float3 lightDir, float atten)
{
return float4(1,0,0,1);
}
ENDCG
}
FallBack "Diffuse"
}
----
하프램버트를 적용시켜준다. (제일 어두운 부분이 0.5)
라이팅툰 안에 if문을 써 줄 수 있다.
2단계로 쪼개는 것
3단계로 쪼갤 수도 있다 .
if 문을 쓰면 너무 길어진다.
똑같은 공식이 있다.
--
알베도 적용
---
범프 추가
Shader "Custom/Test"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Normal ("_Normal (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Toon noambient
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Normal;
struct Input
{
float2 uv_MainTex;
float2 uv_Normal;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Normal = UnpackNormal(tex2D(_Normal,IN.uv_Normal));
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, float3 lightDir, float atten)
{
float ndotl = dot(s.Normal , lightDir) * 0.5 + 0.3;
//if(ndotl > 0.7){
// ndotl = 1;
//}
//else if(ndotl > 0.4)
//{
// ndotl = 0.3;
//}
//else{
// ndotl = 0;
//}
ndotl = ndotl * 10; // 쪼갤 단계
ndotl = ceil(ndotl) / 10;
return float4(ndotl * s.Albedo.rgb, 1);
}
ENDCG
}
FallBack "Diffuse"
}
------
겉에 외곽선도 넣어보자.
외곽선을 넣을러면, 1pass에 외곽 2pass에 텍스쳐링이 들어가야한다.
Shader "Custom/Test"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Normal ("_Normal (RGB)", 2D) = "white" {}
_Thickness("LineThick", Float) = 0.0035
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Cull Front
CGPROGRAM
#pragma surface surf NoLight vertex:vert
#pragma target 3.0
sampler2D _MainTex;
float _Thickness;
void vert(inout appdata_full v){
v.vertex.xyz = v.vertex.xyz + v.normal.xyz * _Thickness;
}
struct Input
{
float2 uv_MainTex;
float4 color:COLOR;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Emission = float4(1,0,0,1);
o.Alpha = c.a;
}
float4 LightingNoLight(SurfaceOutput s, float3 lightDir, float atten)
{
return float4(0,0,0,1);
}
ENDCG
Cull Back
CGPROGRAM
#pragma surface surf Toon noambient
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Normal;
struct Input
{
float2 uv_MainTex;
float2 uv_Normal;
};
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Normal = UnpackNormal(tex2D(_Normal,IN.uv_Normal));
o.Albedo = c.rgb;
o.Alpha = c.a;
}
float4 LightingToon(SurfaceOutput s, float3 lightDir, float atten)
{
float ndotl = dot(s.Normal , lightDir) * 0.5 + 0.3;
ndotl = ndotl * 10; // 쪼갤 단계
ndotl = ceil(ndotl) / 10;
return float4(ndotl * s.Albedo.rgb, 1);
}
ENDCG
}
FallBack "Diffuse"
}
반응형
'Unity > 그래픽스프로그래밍' 카테고리의 다른 글
0507_Diffuse Warping 만들어보기 (0) | 2021.05.07 |
---|---|
0507 _ 툰쉐이더 _ 1pass로 음영 표시하기 (0) | 2021.05.07 |
0507_ 외곽선 만들어보기 (0) | 2021.05.07 |
0507 _ Lim 라이트를 커스텀 라이트로 옮기기 (0) | 2021.05.07 |
0506_ Lambert에서 BlinnPhong 스펙큘러 만들기 (0) | 2021.05.06 |