outline
|
Shader "Custom/101_outline-2pass" { Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
|
|
|
SubShader { Tags { "RenderType"="Opaque" }
cull front
//1st pass CGPROGRAM #pragma surface surf Nolight vertex:vert noshadow noambient <![if !supportLineBreakNewLine]> <![endif]>
|
//vertex:vert 버텍스 함수 시작임을 나타낸다. //noshadow: 만약 그림자 패스에도 확장된 버텍스 영향을 주고 싶다면, addshadow라고 써준다. //noambient : 앰비언트 없애고 //nolight : 빛도 없애고
|
|
sampler2D _MainTex;
void vert(inout appdata_full v)
{ //float4 vertex : POSITION; // 모든 베텍스 쉐이더에 있음. //float4 tangent : TANGENT; // appdata_full과 tan에 있다. //float3 normal : NORMAL; // 모든 베텍스 쉐이더에 있음.. //float4 texcoord : TEXCOORD0; // 모든 베텍스 쉐이더에 있음. //float4 texcoord1 : TEXCOORD1;//appdata_full에만 있다. //float4 texcoord2 : TEXCOORD2; //appdata_full에만 있다. //float4 texcoord3 : TEXCOORD3; //appdata_full에만 있다. //float4 color : COLOR; //appdata_full에만 있다. //UNITY_VERTEX_INPUT_INSTANCE_ID // 모든 베텍스 쉐이더에 있음.
//v.vertex.y = v.vertex.y + 0.1; // 이렇게 하면 모든 버텍스가 y축으로 0.1만큼 이동됨.(실제 오브젝트가 이동은 아님) //v.vertex.y+= 0.1; 라고 써도 위랑 같음(+= 띄워 쓰면 안됨.)
//v.vertex.xyz = v.vertex.xyz +v. normal.xyz; // 버텍스가 확장된다. //v.vertex.xyz+= v.vertex.xyz; 위랑 같은거임
v.vertex.xyz+= v.normal.xyz*0.005; // 버텍스가 확장된다.
}
|
//appdata_base:position, normal and one texture coordinates : 위치, 노멀, 텍스쳐 좌표계
//appdata_tan: position, tangent, normal and one texture coordinates : 위치, 탄젠트, 노멀, 1개의 텍스쳐 좌표계
//appdata_full: position, tangent, normal, four texture coordinates and color :위치, 탄젠트, 노멀, 4개의 텍스쳐 좌표계와 버텍스 컬러
//3가지중 당연히 base가 가장 가벼움.
|
|
struct Input { float4 color:COLOR; // 필요없는데 아무것도 없으면 문제가 생기기 때문에 아무거나 넣은거. };
void surf (Input IN, inout SurfaceOutput o) { // 아무것도 없어도 문제가 안생김. // Albedo가 없는 이유: 라이팅 계산조차 필요하지 않기 때문에 컬러를 넣을 필요가 없음. 검은색이니깐 }
float4 LightingNolight( SurfaceOutput s,float3 lightDir, float atten) { return float4(0,0,0,1); }
ENDCG
|
|
|
cull back
//2nd pass CGPROGRAM #pragma surface surf Lambert
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; } ENDCG
} FallBack "Diffuse" }
|
|
|
|
|
|
|
|
끊어지는 음영 카툰
|
Shader "Custom/102_IF_CUT_shadow" { Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
} SubShader { Tags { "RenderType"="Opaque" }
|
|
|
cull back
//2nd pass CGPROGRAM #pragma surface surf Toon noambient
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) { float ndotl = dot(s.Normal,lightDir);//*0.5+0.5; //half Lambert로 만든거임.
if (ndotl>0.7) { ndotl=1; } else if (ndotl>0.4) { ndotl=0.3; } else { ndotl=0; }
|
|
|
//return ndotl; 텍스쳐 없이 컬러 음영만 테스트시 float4 final; final.rgb=s.Albedo * ndotl *_LightColor0.rgb; final.a=s.Alpha;
return final; }
ENDCG
} FallBack "Diffuse"
|
|
|
|
|
Fresnel outline
|
Shader "Custom/102_IF_CUT_shadow" { Properties {
_MainTex ("Albedo (RGB)", 2D) = "white" {}
} SubShader { Tags { "RenderType"="Opaque" }
|
|
|
cull back
//2nd pass CGPROGRAM #pragma surface surf Toon noambient
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, float3 viewDir, float atten) { float ndotl = dot(s.Normal,lightDir);//*0.5+0.5; //half Lambert로 만든거임.
if (ndotl>0.7) { ndotl=1; } else if (ndotl>0.4) { ndotl=0.3; } else { ndotl=0; }
|
|
|
float rim = abs(dot(s.Normal,viewDir)); if(rim>0.3) { rim =1; } else { rim =-1; }
|
else 부분이 0이 아닌 이유는 최종적으로 ambient color가 더해지면서 검은색 선이 ambient color로 밝아지기 때문이다. 그영향을 없애려고 마이너스-1이 들어간것입니다.
|
|
//return ndotl; 텍스쳐 없이 컬러 음영만 테스트시 float4 final; final.rgb=s.Albedo * ndotl *_LightColor0.rgb; final.a=s.Alpha;
return final; }
ENDCG
} FallBack "Diffuse"
|
|