タイトル通りですが、UnityのUGUIでImageスプライトをグレーで原色、白で真っ白、黒で真っ黒になる様にして尚且つRectMask2Dのコンポーネントも効く様にしたいのですがうまく出来ませんでした。
カラーの変更で真っ白真っ黒になる様には出来ましたがマスクが効きませんでした。
どうすればマスクも反映される様に出来るのでしょうか?宜しくお願い致します。
↓とりあえず出来ている白、黒にできるシェーダーです
Shader
1Shader "Sprites/Default_Custom" 2{ 3 Properties 4 { 5 [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {} 6 _Color ("Tint", Color) = (1,1,1,1) 7 [MaterialToggle] PixelSnap ("Pixel snap", Float) = 0 8 } 9 10 SubShader 11 { 12 Tags 13 { 14 "Queue"="Transparent" 15 "IgnoreProjector"="True" 16 "RenderType"="Transparent" 17 "PreviewType"="Plane" 18 "CanUseSpriteAtlas"="True" 19 } 20 21 Cull Off 22 Lighting Off 23 ZWrite Off 24 Blend One OneMinusSrcAlpha 25 26 Pass 27 { 28 CGPROGRAM 29 #pragma vertex vert 30 #pragma fragment frag 31 #pragma target 2.0 32 #pragma multi_compile _ PIXELSNAP_ON 33 #pragma multi_compile _ ETC1_EXTERNAL_ALPHA 34 #include "UnityCG.cginc" 35 36 struct appdata_t 37 { 38 float4 vertex : POSITION; 39 float4 color : COLOR; 40 float2 texcoord : TEXCOORD0; 41 }; 42 43 struct v2f 44 { 45 float4 vertex : SV_POSITION; 46 fixed4 color : COLOR; 47 float2 texcoord : TEXCOORD0; 48 }; 49 50 fixed4 _Color; 51 52 v2f vert(appdata_t IN) 53 { 54 v2f OUT; 55 OUT.vertex = UnityObjectToClipPos(IN.vertex); 56 OUT.texcoord = IN.texcoord; 57 OUT.color = IN.color * _Color; 58 #ifdef PIXELSNAP_ON 59 OUT.vertex = UnityPixelSnap (OUT.vertex); 60 #endif 61 62 return OUT; 63 } 64 65 sampler2D _MainTex; 66 sampler2D _AlphaTex; 67 68 fixed4 SampleSpriteTexture (float2 uv) 69 { 70 fixed4 color = tex2D (_MainTex, uv); 71 72#if ETC1_EXTERNAL_ALPHA 73 // get the color from an external texture (usecase: Alpha support for ETC1 on android) 74 color.a = tex2D (_AlphaTex, uv).r; 75#endif //ETC1_EXTERNAL_ALPHA 76 77 return color; 78 } 79 80 fixed4 frag(v2f IN) : SV_Target 81 { 82 fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color; 83 c.rgb = c.rgb*2+max(fixed3(0,0,0),IN.color.rgb-0.5)*2; 84 c.rgb *= c.a; 85 return c; 86 } 87 ENDCG 88 } 89 } 90}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/07 09:59
2018/09/07 10:43
2018/09/07 10:49