FeatheredPlaneShader.shader 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. Shader "Unlit/FeatheredPlaneShader"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. _TexTintColor("Texture Tint Color", Color) = (1,1,1,1)
  7. _PlaneColor("Plane Color", Color) = (1,1,1,1)
  8. }
  9. SubShader
  10. {
  11. Tags { "RenderType"="Transparent" "Queue"="Transparent" }
  12. LOD 100
  13. Blend SrcAlpha OneMinusSrcAlpha
  14. ZWrite Off
  15. Pass
  16. {
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. #include "UnityCG.cginc"
  21. struct appdata
  22. {
  23. float4 vertex : POSITION;
  24. float2 uv : TEXCOORD0;
  25. float3 uv2 : TEXCOORD1;
  26. UNITY_VERTEX_INPUT_INSTANCE_ID
  27. };
  28. struct v2f
  29. {
  30. float4 vertex : SV_POSITION;
  31. float2 uv : TEXCOORD0;
  32. float3 uv2 : TEXCOORD1;
  33. UNITY_VERTEX_OUTPUT_STEREO
  34. };
  35. sampler2D _MainTex;
  36. float4 _MainTex_ST;
  37. fixed4 _TexTintColor;
  38. fixed4 _PlaneColor;
  39. float _ShortestUVMapping;
  40. v2f vert (appdata v)
  41. {
  42. v2f o;
  43. UNITY_SETUP_INSTANCE_ID(v);
  44. UNITY_INITIALIZE_OUTPUT(v2f, o);
  45. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  46. o.vertex = UnityObjectToClipPos(v.vertex);
  47. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  48. o.uv2 = v.uv2;
  49. return o;
  50. }
  51. fixed4 frag (v2f i) : SV_Target
  52. {
  53. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  54. fixed4 col = tex2D(_MainTex, i.uv) * _TexTintColor;
  55. col = lerp( _PlaneColor, col, col.a);
  56. // Fade out from as we pass the edge.
  57. // uv2.x stores a mapped UV that will be "1" at the beginning of the feathering.
  58. // We fade until we reach at the edge of the shortest UV mapping.
  59. // This is the remmaped UV value at the vertex.
  60. // We choose the shorted one so that ll edges will fade out completely.
  61. // See ARFeatheredPlaneMeshVisualizer.cs for more details.
  62. col.a *= 1-smoothstep(1, _ShortestUVMapping, i.uv2.x);
  63. return col;
  64. }
  65. ENDCG
  66. }
  67. }
  68. }