Search Unity

Alpha Blended Particle Shader In Lwrp

Discussion in 'Shaders' started by Erfan_SheikhHoseini, Apr 12, 2019.

  1. Erfan_SheikhHoseini

    Erfan_SheikhHoseini

    Joined:
    Feb 7, 2019
    Posts:
    32
    hello, i am trying to create a fog like type of shader and i saw this thread. he is using a alpha blended particle shader but it does not work in lwrp. anyone has any experience?
    here us the code:
    Code (CSharp):
    1. Shader "Legacy Shaders/Particles/Alpha Blended" {
    2. Properties {
    3.     _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
    4.     _MainTex ("Particle Texture", 2D) = "white" {}
    5.     _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
    6. }
    7.  
    8. Category {
    9.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    10.     Blend SrcAlpha OneMinusSrcAlpha
    11.     ColorMask RGB
    12.     Cull Off Lighting Off ZWrite Off
    13.  
    14.     SubShader {
    15.         Pass {
    16.  
    17.             CGPROGRAM
    18.             #pragma vertex vert
    19.             #pragma fragment frag
    20.             //#pragma target 2.0
    21.             #pragma multi_compile_particles
    22.             #pragma multi_compile_fog
    23.  
    24.             #include "UnityCG.cginc"
    25.  
    26.             sampler2D _MainTex;
    27.             fixed4 _TintColor;
    28.  
    29.             struct appdata_t {
    30.                 float4 vertex : POSITION;
    31.                 fixed4 color : COLOR;
    32.                 float2 texcoord : TEXCOORD0;
    33.                 UNITY_VERTEX_INPUT_INSTANCE_ID
    34.             };
    35.  
    36.             struct v2f {
    37.                 float4 vertex : SV_POSITION;
    38.                 fixed4 color : COLOR;
    39.                 float2 texcoord : TEXCOORD0;
    40.                 UNITY_FOG_COORDS(1)
    41.                 #ifdef SOFTPARTICLES_ON
    42.                 float4 projPos : TEXCOORD2;
    43.                 #endif
    44.                 UNITY_VERTEX_OUTPUT_STEREO
    45.             };
    46.  
    47.             float4 _MainTex_ST;
    48.  
    49.             v2f vert (appdata_t v)
    50.             {
    51.                 v2f o;
    52.                 UNITY_SETUP_INSTANCE_ID(v);
    53.                 UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
    54.                 o.vertex = UnityObjectToClipPos(v.vertex);
    55.                 #ifdef SOFTPARTICLES_ON
    56.                 o.projPos = ComputeScreenPos (o.vertex);
    57.                 COMPUTE_EYEDEPTH(o.projPos.z);
    58.                 #endif
    59.                 o.color = v.color * _TintColor;
    60.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    61.                 UNITY_TRANSFER_FOG(o,o.vertex);
    62.                 return o;
    63.             }
    64.  
    65.             UNITY_DECLARE_DEPTH_TEXTURE(_CameraDepthTexture);
    66.             float _InvFade;
    67.  
    68.             fixed4 frag (v2f i) : SV_Target
    69.             {
    70.                 #ifdef SOFTPARTICLES_ON
    71.                 float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    72.                 float partZ = i.projPos.z;
    73.                 float fade = saturate (_InvFade * (sceneZ-partZ));
    74.                 i.color.a *= fade;
    75.                 #endif
    76.  
    77.                 fixed4 col = 2.0f * i.color * tex2D(_MainTex, i.texcoord);
    78.                 col.a = saturate(col.a); // alpha should not have double-brightness applied to it, but we can't fix that legacy behavior without breaking everyone's effects, so instead clamp the output to get sensible HDR behavior (case 967476)
    79.  
    80.                 UNITY_APPLY_FOG(i.fogCoord, col);
    81.                 return col;
    82.             }
    83.             ENDCG
    84.         }
    85.     }
    86. }
    87. }
    88.  
     
  2. Erfan_SheikhHoseini

    Erfan_SheikhHoseini

    Joined:
    Feb 7, 2019
    Posts:
    32
    found out light weight render pipeline in 2019.1 already supports that kind of shader in its built in unlit particle shader