回答編集履歴
1
つなぎ目ブレンドに特化したバージョンを検討
test
CHANGED
@@ -239,3 +239,239 @@
|
|
239
239
|
|
240
240
|
|
241
241
|
![結果](56f7d0778df4ec5261342620f98e876d.gif)
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
#追記
|
246
|
+
|
247
|
+
不透明にしたいエッジを選択する方式を検討してみました。同じくSprites-Default.shaderをベースに下記のように改造し...
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
```ShaderLab
|
252
|
+
|
253
|
+
// Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
Shader "Sprites/Edge Gradient Alpha"
|
258
|
+
|
259
|
+
{
|
260
|
+
|
261
|
+
Properties
|
262
|
+
|
263
|
+
{
|
264
|
+
|
265
|
+
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
|
266
|
+
|
267
|
+
_Color ("Tint", Color) = (1,1,1,1)
|
268
|
+
|
269
|
+
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
|
270
|
+
|
271
|
+
[HideInInspector] _RendererColor ("RendererColor", Color) = (1,1,1,1)
|
272
|
+
|
273
|
+
[HideInInspector] _Flip ("Flip", Vector) = (1,1,1,1)
|
274
|
+
|
275
|
+
[PerRendererData] _AlphaTex ("External Alpha", 2D) = "white" {}
|
276
|
+
|
277
|
+
[PerRendererData] _EnableExternalAlpha ("Enable External Alpha", Float) = 0
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
[Space]
|
282
|
+
|
283
|
+
[Header(Gradient)]
|
284
|
+
|
285
|
+
_GradientAlpha1 ("Alpha 1", Range(0, 1)) = 0
|
286
|
+
|
287
|
+
_GradientAlpha2 ("Alpha 2", Range(0, 1)) = 1
|
288
|
+
|
289
|
+
[PowerSlider(2.0)] _GradientExponent ("Exponent", Range(0.125, 8)) = 2
|
290
|
+
|
291
|
+
[Toggle] _GradientEdgeTop ("Top", Float) = 0
|
292
|
+
|
293
|
+
[Toggle] _GradientEdgeBottom ("Bottom", Float) = 0
|
294
|
+
|
295
|
+
[Toggle] _GradientEdgeLeft ("Left", Float) = 0
|
296
|
+
|
297
|
+
[Toggle] _GradientEdgeRight ("Right", Float) = 0
|
298
|
+
|
299
|
+
}
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
SubShader
|
304
|
+
|
305
|
+
{
|
306
|
+
|
307
|
+
Tags
|
308
|
+
|
309
|
+
{
|
310
|
+
|
311
|
+
"Queue"="Transparent"
|
312
|
+
|
313
|
+
"IgnoreProjector"="True"
|
314
|
+
|
315
|
+
"RenderType"="Transparent"
|
316
|
+
|
317
|
+
"PreviewType"="Plane"
|
318
|
+
|
319
|
+
"CanUseSpriteAtlas"="True"
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
Cull Off
|
326
|
+
|
327
|
+
Lighting Off
|
328
|
+
|
329
|
+
ZWrite Off
|
330
|
+
|
331
|
+
Blend One OneMinusSrcAlpha
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
Pass
|
336
|
+
|
337
|
+
{
|
338
|
+
|
339
|
+
CGPROGRAM
|
340
|
+
|
341
|
+
#pragma vertex vert
|
342
|
+
|
343
|
+
#pragma fragment frag
|
344
|
+
|
345
|
+
#pragma target 2.0
|
346
|
+
|
347
|
+
#pragma multi_compile_instancing
|
348
|
+
|
349
|
+
#pragma multi_compile _ PIXELSNAP_ON
|
350
|
+
|
351
|
+
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
|
352
|
+
|
353
|
+
#include "UnitySprites.cginc"
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
float _GradientAlpha1;
|
358
|
+
|
359
|
+
float _GradientAlpha2;
|
360
|
+
|
361
|
+
float _GradientExponent;
|
362
|
+
|
363
|
+
float _GradientEdgeTop;
|
364
|
+
|
365
|
+
float _GradientEdgeBottom;
|
366
|
+
|
367
|
+
float _GradientEdgeLeft;
|
368
|
+
|
369
|
+
float _GradientEdgeRight;
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
struct v2fCustom
|
374
|
+
|
375
|
+
{
|
376
|
+
|
377
|
+
float4 vertex : SV_POSITION;
|
378
|
+
|
379
|
+
fixed4 color : COLOR;
|
380
|
+
|
381
|
+
float2 texcoord : TEXCOORD0;
|
382
|
+
|
383
|
+
float2 position : TEXCOORD1; // グラデーション用の位置
|
384
|
+
|
385
|
+
UNITY_VERTEX_OUTPUT_STEREO
|
386
|
+
|
387
|
+
};
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
v2fCustom vert(appdata_t IN)
|
392
|
+
|
393
|
+
{
|
394
|
+
|
395
|
+
v2fCustom OUT;
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
UNITY_SETUP_INSTANCE_ID (IN);
|
400
|
+
|
401
|
+
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(OUT);
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
OUT.vertex = UnityFlipSprite(IN.vertex, _Flip);
|
406
|
+
|
407
|
+
OUT.vertex = UnityObjectToClipPos(OUT.vertex);
|
408
|
+
|
409
|
+
OUT.texcoord = IN.texcoord;
|
410
|
+
|
411
|
+
OUT.color = IN.color * _Color * _RendererColor;
|
412
|
+
|
413
|
+
OUT.position = IN.vertex.xy * 2;
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
#ifdef PIXELSNAP_ON
|
418
|
+
|
419
|
+
OUT.vertex = UnityPixelSnap (OUT.vertex);
|
420
|
+
|
421
|
+
#endif
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
return OUT;
|
426
|
+
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
fixed4 frag(v2fCustom IN) : SV_Target
|
432
|
+
|
433
|
+
{
|
434
|
+
|
435
|
+
fixed4 c = SampleSpriteTexture (IN.texcoord) * IN.color;
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
float alpha = saturate(dot(float4(
|
440
|
+
|
441
|
+
pow(saturate(_GradientEdgeTop * IN.position.y), _GradientExponent),
|
442
|
+
|
443
|
+
pow(saturate(_GradientEdgeBottom * -IN.position.y), _GradientExponent),
|
444
|
+
|
445
|
+
pow(saturate(_GradientEdgeLeft * -IN.position.x), _GradientExponent),
|
446
|
+
|
447
|
+
pow(saturate(_GradientEdgeRight * IN.position.x), _GradientExponent)), 1));
|
448
|
+
|
449
|
+
c.a *= saturate(lerp(_GradientAlpha1, _GradientAlpha2, alpha));
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
c.rgb *= c.a;
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
return c;
|
458
|
+
|
459
|
+
}
|
460
|
+
|
461
|
+
ENDCG
|
462
|
+
|
463
|
+
}
|
464
|
+
|
465
|
+
}
|
466
|
+
|
467
|
+
}
|
468
|
+
|
469
|
+
```
|
470
|
+
|
471
|
+
|
472
|
+
|
473
|
+
インスペクタ上で各チェックボックスを切り替えると、その方向のエッジ表示が切り替わります。
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
![結果](cd51bb17730bee8893e7315f94879fbf.gif)
|