셰이더 (Shader)/유니티 쉐이더 스타트업 - 정종필
[Unity/Shader] 파트16-3 : 알파 블렌딩 제작
Minkyu Lee
2023. 8. 25. 00:50

알파 블렌딩을 실습한다.
반투명을 만드는 것이다.
풀은 예시일 뿐이다.
실제로 반투명을 풀에다 적용하진 않는다. (풀은 보통 AlphaTest (Cutout)을 사용한다.)
코드
Shader "Custom/part16-3"
{
Properties
{
_MainTex ("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent" "Queue"="Transparent"}
// Queue는 그리는 순서를 의미한다. Transparent라고 적으면 불투명 다음에 그린다는 의미다.
cull off // 양면
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha:fade // *
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Legacy Shaders/Transparent/VertexLit" // 플랜 모양으로 생성되는 그림자를 없앤다. Transparent계열의 쉐이더 이름으로 바꾼 것이다.
}