반응형
새로 만들어서 텍스쳐 한장을 받는 스크립터를 만들어준다.
커스텀 라이팅을 해줍니다 .
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 Lighting_Toon(SurfaceOutput s, float3 lightDir, float atten){
return 0;
}
ENDCG
}
FallBack "Diffuse"
}
---
하프램버트로 바꾸기
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 Lighting_Toon(SurfaceOutput s, float3 lightDir, float atten){
float ndotl = dot(s.Normal, lightDir) *0.5 +0.5;
return 0;
}
ENDCG
}
FallBack "Diffuse"
}
---
5면을 나눠어진 음영 쉐이딩 해줌
hader "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 Lighting_Toon(SurfaceOutput s, float3 lightDir, float atten){
float ndotl = dot(s.Normal, lightDir) *0.5 +0.5;
ndotl = ndotl * 5;
ndotl = ceil(ndotl) / 5;
return ndotl;
}
ENDCG
}
FallBack "Diffuse"
}
---
Rim 만들어주기
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 Lighting_Toon(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten){
//half-lambert
float ndotl = dot(s.Normal, lightDir) *0.5 +0.5;
ndotl = ndotl * 5;
ndotl = ceil(ndotl) / 5;
//Rim
float rim = dot(s.Normal, viewDir);
float4 final;
final.rgb = ndotl * s.Albedo;
final.a = s.Alpha;
return rim;
}
ENDCG
}
FallBack "Diffuse"
}
Rim을 이용해서 1pass로 외곽선 만들어 줄 수 있다.
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 Lighting_Toon(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten){
//half-lambert
float ndotl = dot(s.Normal, lightDir) *0.5 +0.5;
ndotl = ndotl * 5;
ndotl = ceil(ndotl) / 5;
//Rim
float rim = abs(dot(s.Normal, viewDir));
if(rim > 0.3){
rim = 1;
}
else{
rim = -1;
}
float4 final;
final.rgb = ndotl * s.Albedo;
final.a = s.Alpha;
return rim;
}
ENDCG
}
FallBack "Diffuse"
}
----
1pass 로도 외곽선 가능
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 Lighting_Toon(SurfaceOutput s, float3 lightDir, float3 viewDir, float atten){
//half-lambert
float ndotl = dot(s.Normal, lightDir) *0.5 +0.5;
ndotl = ndotl * 5;
ndotl = ceil(ndotl) / 5;
//Rim
float rim = abs(dot(s.Normal, viewDir));
if(rim > 0.3){
rim = 1;
}
else{
rim = -1;
}
float4 final;
final.rgb = ndotl * s.Albedo * rim;
final.a = s.Alpha;
return final;
}
ENDCG
}
FallBack "Diffuse"
}
반응형
'Unity > 그래픽스프로그래밍' 카테고리의 다른 글
0507 _ 큐브맵 만들어서, 물체에 월드 노멀, 리플렉션 적용시기키 (0) | 2021.05.07 |
---|---|
0507_Diffuse Warping 만들어보기 (0) | 2021.05.07 |
0507 _ 툰쉐이더 _ 음영을 계단식 -> 2pass 로 외곽 만들어준다. (0) | 2021.05.07 |
0507_ 외곽선 만들어보기 (0) | 2021.05.07 |
0507 _ Lim 라이트를 커스텀 라이트로 옮기기 (0) | 2021.05.07 |