Search Unity

Question MRTK HoloLens Dashed Line Shader shows as semi transparent on device

Discussion in 'AR' started by sebastianp_big, Jul 9, 2021.

  1. sebastianp_big

    sebastianp_big

    Joined:
    Oct 1, 2015
    Posts:
    6
    Hello!

    I am currently working on a hololens application and for directing the user to certain elements we are using bezier lines that go from a text container to an item in the scene. We are doing a dashed line effect with a shader that moves the uv coordinates so the dashes move from origin to target. This works fine in the editor but on the device the line is no longer dashed but a semi transparent line in the color that was choosen.

    I spent a few hours trying to find out what is goind wrong so the code might be a bit messed up right now, but it still works in the editor.

    Code (CSharp):
    1. Shader "Custom/AnimatedLine"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Texture", 2D) = "white" {}
    6.         _Speed ("AnimationSpeed", float) = 1.0
    7.     }
    8.     SubShader
    9.     {
    10.         Tags{ "Queue" = "Transparent+200" "RenderType" = "Cutout"}
    11.         LOD 100
    12.         Blend SrcAlpha OneMinusSrcAlpha
    13.         BlendOp Add
    14.         Cull Back
    15.  
    16.  
    17.         Pass
    18.         {
    19.             ZWrite Off
    20.             ZTest Always
    21.             CGPROGRAM
    22.             #pragma vertex vert
    23.             #pragma fragment frag
    24.             #pragma multi_compile_instancing
    25.  
    26.             #include "UnityCG.cginc"
    27.  
    28.             struct appdata
    29.             {
    30.                 float4 vertex : POSITION;
    31.                 float2 uv : TEXCOORD0;
    32.                 float4 color : COLOR;
    33.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    34.             };
    35.  
    36.             struct v2f
    37.             {
    38.                 float2 uv : TEXCOORD0;
    39.                 float4 vertex : SV_POSITION;
    40.                 float4 color : COLOR;              
    41.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    42.                 UNITY_VERTEX_OUTPUT_STEREO
    43.             };
    44.  
    45.             float4 _MainTex_ST;
    46.             float _Speed;
    47.             UNITY_DECLARE_SCREENSPACE_TEXTURE(_MainTex);
    48.  
    49.             v2f vert (appdata v)
    50.             {
    51.                 v2f o;
    52.                 UNITY_INITIALIZE_OUTPUT(v2f, o)
    53.                 UNITY_SETUP_INSTANCE_ID(v);
    54.                 UNITY_TRANSFER_INSTANCE_ID(v, o);
    55.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    56.                 o.vertex = UnityObjectToClipPos(v.vertex);
    57.                 o.uv = v.uv;
    58.                 o.color = v.color;
    59.                 return o;
    60.             }
    61.            
    62.  
    63.             fixed4 frag(v2f i) : SV_Target
    64.             {
    65.                 UNITY_SETUP_INSTANCE_ID(i);
    66.                 fixed4 col = UNITY_SAMPLE_SCREENSPACE_TEXTURE(_MainTex, float2((i.uv.x * _MainTex_ST.x) - (_Time.y * _Speed), i.uv.y));
    67.                 col = i.color * col;              
    68.                
    69.                 return col;
    70.             }
    71.             ENDCG
    72.         }
    73.     }
    74. }
    75.  
    Can someone spot the presumably glaring error i have in my code?

    Any help or hint is appreciated! Thanks!