2016-10-27 3 views
1

나는 2D 스프라이트에 대 한 반짝이 할 수있는 유니티 쉐이더를 가지고 : 유니티 반짝 쉐이더 오버레이 2D 스프라이트

그러나 2D 스프라이트의 픽셀이 반짝 쉐이더 뒤에있는이 코드

//Kaan Yamanyar,Levent Seckin 
 
Shader "Sprites/ShinyDefault" 
 
{ 
 
\t Properties 
 
\t { 
 
\t \t [PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {} 
 
\t _Color("Tint", Color) = (1,1,1,1) 
 
\t \t _ShineLocation("ShineLocation", Range(0,1)) = 0 
 
\t \t _ShineWidth("ShineWidth", Range(0,1)) = 0 
 
\t \t [MaterialToggle] PixelSnap("Pixel snap", Float) = 0 
 
\t } 
 

 
\t \t SubShader 
 
\t { 
 
\t \t Tags 
 
\t { 
 
\t \t "Queue" = "Transparent" 
 
\t \t "IgnoreProjector" = "True" 
 
\t \t "RenderType" = "Transparent" 
 
\t \t "PreviewType" = "Plane" 
 
\t \t "CanUseSpriteAtlas" = "False" 
 
\t } 
 

 
\t \t Cull Off 
 
\t \t Lighting Off 
 
\t \t ZWrite Off 
 
\t \t Blend One OneMinusSrcAlpha 
 

 
\t \t Pass 
 
\t { 
 
\t \t CGPROGRAM 
 
#pragma vertex vert 
 
#pragma fragment frag 
 
#pragma multi_compile _ PIXELSNAP_ON 
 
#include "UnityCG.cginc" 
 

 
\t \t struct appdata_t 
 
\t { 
 
\t \t float4 vertex : POSITION; 
 
\t \t float4 color : COLOR; 
 
\t \t float2 texcoord : TEXCOORD0; 
 
\t }; 
 

 
\t struct v2f 
 
\t { 
 
\t \t float4 vertex : SV_POSITION; 
 
\t \t fixed4 color : COLOR; 
 
\t \t float2 texcoord : TEXCOORD0; 
 
\t }; 
 

 
\t fixed4 _Color; 
 

 
\t v2f vert(appdata_t IN) 
 
\t { 
 
\t \t v2f OUT; 
 
\t \t OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); 
 
\t \t OUT.texcoord = IN.texcoord; 
 
\t \t OUT.color = IN.color * _Color; 
 
#ifdef PIXELSNAP_ON 
 
\t \t OUT.vertex = UnityPixelSnap(OUT.vertex); 
 
#endif 
 

 
\t \t return OUT; 
 
\t } 
 

 
\t sampler2D _MainTex; 
 
\t sampler2D _AlphaTex; 
 
\t float _AlphaSplitEnabled; 
 
\t float _ShineLocation; 
 
\t float _ShineWidth; 
 

 
\t fixed4 SampleSpriteTexture(float2 uv) 
 
\t { 
 
\t \t fixed4 color = tex2D(_MainTex, uv); 
 

 
#if UNITY_TEXTURE_ALPHASPLIT_ALLOWED 
 
\t \t if (_AlphaSplitEnabled) 
 
\t \t \t color.a = tex2D(_AlphaTex, uv).r; 
 
#endif //UNITY_TEXTURE_ALPHASPLIT_ALLOWED 
 

 

 

 

 
\t \t float lowLevel = _ShineLocation - _ShineWidth; 
 
\t \t float highLevel = _ShineLocation + _ShineWidth; 
 
\t \t float currentDistanceProjection = (uv.x + uv.y)/2; 
 
\t \t if (currentDistanceProjection > lowLevel && currentDistanceProjection < highLevel) { 
 
\t \t \t float whitePower = 1 - (abs(currentDistanceProjection - _ShineLocation)/_ShineWidth); 
 
\t \t \t color.rgb += color.a * whitePower; 
 
\t \t } 
 

 
\t \t return color; 
 
\t } 
 

 
\t fixed4 frag(v2f IN) : SV_Target 
 
\t { 
 
\t \t fixed4 c = SampleSpriteTexture(IN.texcoord) * IN.color; 
 
\t c.rgb *= c.a; 
 

 
\t return c; 
 
\t } 
 
\t \t ENDCG 
 
\t } 
 
\t } 
 
}
. 이제이 셰이더 오버레이 스프라이트 만 표시하고 스프라이트의 모든 픽셀은 표시되지 않습니다.

어떻게하면됩니까?

답변

0

셰이더를 사용하는 렌더러에 대해 SortingLayer 또는 OrderInLayer을 설정해야합니다. > 프로젝트 설정 - -

예를 들어

, 편집으로 이동> 태그와 레이어와 레이어라는 이름의 오버레이 층을 정의하고 스프라이트에 의해 사용되는 레이어 후 배치 :

[shaderedObject].GetComponent<Renderer>().sortingLayerName = "overlay layer"; 
관련 문제