Search Unity

Resolved this shader works but shows tons of errors in the console - why? fix?

Discussion in 'General Graphics' started by laurentlavigne, Oct 18, 2020.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    upload_2020-10-18_0-20-14.png

    Code (CSharp):
    1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
    2.  
    3. // Simplified Additive Particle shader. Differences from regular Additive Particle one:
    4. // - no Tint color
    5. // - no Smooth particle support
    6. // - no AlphaTest
    7. // - no ColorMask
    8.  
    9. Shader "SG/Mobile/Particles/Premult - UVScroll"
    10. {
    11.     Properties
    12.     {
    13.         _MainTex ("Particle Texture", 2D) = "white" {}
    14.         _XSpeed ("X Texture Speed", float) = 0
    15.         _YSpeed ("Y Texture Speed", float) = 0
    16.     }
    17.  
    18.     Category
    19.     {
    20.         Tags
    21.         {
    22.             "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"
    23.         }
    24.         //    Blend SrcAlpha OneMinusSrcAlpha
    25.         //    Blend One OneMinusSrcAlpha
    26.         Blend SrcAlpha One
    27.         Cull Off Lighting Off ZWrite Off
    28.  
    29.         BindChannels
    30.         {
    31.             Bind "Color", color
    32.             Bind "Vertex", vertex
    33.             Bind "TexCoord", texcoord
    34.         }
    35.  
    36.         SubShader
    37.         {
    38.             Pass
    39.             {
    40.  
    41.                 CGPROGRAM
    42.                 // Upgrade NOTE: excluded shader from Xbox360; has structs without semantics (struct v2f members worldPos)
    43.                 #pragma vertex vert
    44.                 #pragma fragment frag
    45.                 #pragma fragmentoption ARB_precision_hint_fastest
    46.                 #pragma multi_compile_particles
    47.                 #pragma multi_compile_fog
    48.                 #include "UnityCG.cginc"
    49.  
    50.                 sampler2D _MainTex;
    51.                 uniform half _XSpeed;
    52.                 uniform half _YSpeed;
    53.                 float4 _MainTex_ST;
    54.  
    55.                 struct appdata_t
    56.                 {
    57.                     float4 vertex : POSITION;
    58.                     fixed4 color : COLOR;
    59.                     float2 texcoord : TEXCOORD0;
    60.                 };
    61.  
    62.                 struct v2f
    63.                 {
    64.                     float4 vertex : POSITION;
    65.                     fixed4 color : COLOR;
    66.                     float2 texcoord : TEXCOORD0;
    67.                     UNITY_FOG_COORDS(1)
    68.                 };
    69.  
    70.                 v2f vert(appdata_t v)
    71.                 {
    72.                     v2f o;
    73.                     o.color = v.color;
    74.                     o.vertex = UnityObjectToClipPos(v.vertex);
    75.                     o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex) + float2(
    76.                         fmod(_XSpeed * _Time[1], 1), fmod(_YSpeed * _Time[1], 1));
    77.                     UNITY_TRANSFER_FOG(o, o.vertex);
    78.                     return o;
    79.                 }
    80.  
    81.                 sampler2D _CameraDepthTexture;
    82.                 float _InvFade;
    83.  
    84.                 fixed4 frag(v2f i) : COLOR
    85.                 {
    86.                     fixed4 c = 2 * i.color * tex2D(_MainTex, i.texcoord) * i.color.a;
    87.                     UNITY_APPLY_FOG_COLOR(i.fogCoord, c, fixed4(0,0,0,0));
    88.                     return c;
    89.                 }
    90.                 ENDCG
    91.  
    92.             }
    93.         }
    94.     }
    95. }
     
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,022
    Hi!
    Can you try removing the BindChannels block?
    Also, which Unity version are you on?
     
  3. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    Thanks Aleksandr, it seems to work now. Care to share why?
    It's using 2020.1.9 + urp 8.2 + nxaddon
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,022
    BindChannels is back from the days of fixed function shaders. You already have the
    appdata_t
    struct in there, which defines all this. I suppose there was some conflict between those two :)
     
    laurentlavigne likes this.
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    oh ok I'll try to remember that when excavating artifacts from the past :)
     
    aleksandrk likes this.
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,022
    And I'll put something like "Add a warning when using old construct with programmable shaders" to our backlog ;)
     
    laurentlavigne likes this.