[펌] Unity Serface Shader에서 Alpha 적용
[요약]
1) Tags { "Queue"="Transparent" "RenderType" = "Opaque" }
2) #pragma surface surf Lambert alpha
----------------------------------------------------------------------------
Three steps:
Add objects rendered with this shader to the Transparent queue by adding “Queue”=“Transparent” to the subshader’s Tags list.
Add “alpha” to the surface function declaration, after the lighting function declaration, so the line becomes “#pragma surface surf Lambert alpha”
Actually set the alpha to something in the surface function, i.e. set o.Alpha = whatever you want.
I have done these modifications and used the _ColorTint’s alpha channel in the example. Then the shader becomes this:
Shader "-smn-/GlowingBorder" {
Properties {
_ColorTint("ColorTint", Color) = (1,1,1,1)
_MainTex("Main Texture", 2D) = "white" {}
_BumpMap("Normal Map", 2D) = "bump" {}
_RimColorOuter("Rim Color Outer", Color) = (1,1,1,1)
_RimColorInner("Rim Color Inner", Color) = (1,1,1,1)
_RimPowerOuter("Rim Power Outer", Range(0.0, 7.0)) = 3.0
_RimPowerInner("Rim Power Inner", Range(0.0, 20.0)) = 3.0
}
SubShader {
Tags { "Queue"="Transparent" "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert alpha
struct Input {
float4 color : COLOR;
float2 uv_MainTex;
float2 uv_BumpMap;
float3 viewDir;
};
float4 _ColorTint;
sampler2D _MainTex;
sampler2D _BumpMap;
float4 _RimColorOuter;
float4 _RimColorInner;
float _RimPowerOuter;
float _RimPowerInner;
void surf (Input IN, inout SurfaceOutput o) {
IN.color = _ColorTint;
o.Albedo = tex2D(_MainTex, IN.uv_MainTex).rgb * IN.color;
o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
o.Alpha = _ColorTint.a; // For example. Could also be the alpha channel on the interpolated vertex color (IN.color.a), or the one from the texture.
half rimOuter = 1.0 -saturate(dot(normalize(IN.viewDir), o.Normal));
half rimInner = saturate(dot(normalize(IN.viewDir), o.Normal));
o.Emission = (_RimColorOuter.rgb * pow(rimOuter, _RimPowerOuter)) + (_RimColorInner.rgb * pow(rimInner, _RimPowerInner)) ;
}
ENDCG
}
FallBack "Diffuse"
}
[출처] https://discussions.unity.com/t/how-can-i-add-alpha-channel-to-this-shader/100942
'Unity3D > Shader' 카테고리의 다른 글
[링크] 스리 유리풍 UI의 만드는 방법을 해설 -글라스 모피즘- (GlassShader) (0) | 2024.06.12 |
---|---|
[링크] [unity3d] 서피스 쉐이더 정리 (0) | 2023.08.11 |
[링크] Chromakey 동영상 투명하게 플레이 하는 Tip (0) | 2023.07.06 |
[링크] Unity Toon Shader(with Outline) (0) | 2023.02.22 |
[링크] Unity-Chan Toon Shader 2.0 (UTS2) (0) | 2021.11.30 |