Transparent 투명 쉐이더

Transparent 쉐이더 기본형

Shader "Custom/AlphaBlend" {
 Properties {
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
 }

 SubShader {
  Tags { "RenderType"="Opaque" "Queue" = "Transparent" } // 알파 적용 "Queue" = Transparent : 불투명 다음에 그림( 렌더링 순서 )
  LOD 200
  
  Cull off// 양면 렌더링

  CGPROGRAM
  #pragma surface surf Lambert noambient alpha:fade // 알파모드 : alpha:fade

  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 "Legacy shaders/Transparent/VertexLit"
}

Transparent Cut Out

Shader "Custom/AlphaBlend" {
 Properties {
  // 컷 오프 사용시 반드시 _Color 프로퍼티 가 있어야 한다 없으면 그림자 안나옴
  _Color ("Main Color", color ) = (1,1,1,1)
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
  _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 // 0.5( 회색 )를 기준으로 더 어두운색은 보이지 않고 높은색은 보이도록 한다.
 }

 SubShader {
  Tags { "RenderType"="TransparentCutout" "Queue" = "AlphaTest" } // 알파 테스트 ( Cut Off )  
  Cull off// 양면 렌더링

  CGPROGRAM
  #pragma surface surf Lambert  alphatest:_Cutoff // 알파모드 : alpha:fade

  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 "Legacy Shaders/Transparent/Cutout/VertexLit"
}


알파 블랜딩 기본 ( 컷 아웃 )

Shader "Custom/AlphaBlend" {
 Properties {
  // 컷 오프 사용시 반드시 _Color 프로퍼티 가 있어야 한다 없으면 그림자 안나옴
  _Color ("Main Color", color ) = (1,1,1,1)
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
  _Cutoff("Alpha cutoff", Range(0,1)) = 0.5 // 0.5( 회색 )를 기준으로 더 어두운색은 보이지 않고 높은색은 보이도록 한다.
 }

 SubShader {
  Tags { "RenderType"="TransparentCutout" "Queue" = "AlphaTest" } // 알파 테스트 ( Cut Off )  
  Cull off// 양면 렌더링

  CGPROGRAM
  #pragma surface surf Lambert  alphatest:_Cutoff // 알파모드 : alpha:fade

  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 "Legacy Shaders/Transparent/Cutout/VertexLit"
}

커스텀 알파 블랜딩 ( 페이드 알파 )

Shader "Custom/CustomBlending" {
 Properties {
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
 }
  SubShader{
  Tags { "RenderType" = "Opaque" "Queue" = "Transparent" }
  zwrite off
  blend SrcAlpha OneMinusSrcAlpha //알파모드 적용

  CGPROGRAM
  #pragma surface surf Lambert keepalpha

  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/CustomBlending" {
 Properties {
  // 유니티 쉐이더 스타트업 484 페이지
  _TintColor ("Color", color) = (0.5,0.5,0.5,0.5)
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
  [Enum(UnityEngine.Rendering.BlendMode)]_SrcBlend("SrcBlend Mode",float) = 5
  [Enum(UnityEngine.Rendering.BlendMode)]_DstBlend("DstBlend Mode",float) = 10
 }
  SubShader{
  Tags { "RenderType" = "Opaque" "Queue" = "Transparent" "IgnoreProjector" = "True" }
  zwrite off
  blend [_SrcBlend] [_DstBlend]
  cull off

  CGPROGRAM
  #pragma surface surf nolight keepalpha noforwardadd nolightmap noambient novertexlights noshadow

  sampler2D _MainTex;
  float4 _TintColor;

  struct Input {
   float2 uv_MainTex;
   float4 color:COLOR;
  };

  void surf (Input IN, inout SurfaceOutput o) {
   fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
   c = c * 2 * _TintColor * IN.color;
   o.Emission = c.rgb;
   o.Alpha = c.a;
  }

  float4 Lightingnolight(SurfaceOutput s, float3 lightDir, float atten) {
   return float4(0, 0, 0, s.Alpha);
  }
  ENDCG
 }
 FallBack "Diffuse"
}


2pass 사용하여 오브젝트 투명하게 만들기 
Shader "Custom/2PassAlphaBlend" {
 Properties {
  _MainTex ("Albedo (RGB)", 2D) = "white" {}
  _AlphaValue("AlphaValue" , Range(0,1) ) = 0.5
 }
 SubShader {
  Tags { "RenderType"="Opaque" "Queue" = "Transparent" }
  
  //first pass zwrite on ( 깊이값 ) Rendering Off 깊이값만 가지고 렌더링은 하지 않음
  zwrite on
  ColorMask 0 // 렌더링 하지 않음
  CGPROGRAM
  #pragma surface surf nolight noambiebt noforwardadd nolightmap novertexlights noshadow
  struct Input {
   float4 color:COLOR;
  };
  void surf(Input IN, inout SurfaceOutput o) {

  }
  float4 Lightingnolight(SurfaceOutput s, float3 lightDir, float atten) {
   return float4(0, 0, 0, 0);
  }
  ENDCG

  //second pass zwrite off
  zwrite off
  CGPROGRAM
  #pragma surface surf Lambert alpha:fade

  sampler2D _MainTex;
  float _AlphaValue;
  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 = _AlphaValue;
  }
  ENDCG

 }
 FallBack "Diffuse"
}


댓글