Search Unity

Clipsafe shader for unity 5? (pink)

Discussion in 'Shaders' started by Nirvan, Aug 13, 2016.

  1. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That's an old shader using some variables that have been deprecated (because they're old and unnecessary). You could look at your log window and try to fix it from the error message it has about the shader, but there's probably more there than you want to deal with.

    However the built in Unity particle shaders are a few lines of code from being able to do what you want.
    Code (CSharp):
    1. Shader "Particles/Alpha Blended Near Fade" {
    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.     _FadeDistance ("Fade Start Distance", float) = 0.5
    7. }
    8.  
    9. Category {
    10.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" "PreviewType"="Plane" }
    11.     Blend SrcAlpha OneMinusSrcAlpha
    12.     ColorMask RGB
    13.     Cull Back Lighting Off ZWrite Off
    14.  
    15.     SubShader {
    16.         Pass {
    17.        
    18.             CGPROGRAM
    19.             #pragma vertex vert
    20.             #pragma fragment frag
    21.             #pragma target 2.0
    22.             #pragma multi_compile_particles
    23.             #pragma multi_compile_fog
    24.            
    25.             #include "UnityCG.cginc"
    26.  
    27.             sampler2D _MainTex;
    28.             fixed4 _TintColor;
    29.            
    30.             struct appdata_t {
    31.                 float4 vertex : POSITION;
    32.                 fixed4 color : COLOR;
    33.                 float2 texcoord : TEXCOORD0;
    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.             };
    45.            
    46.             float4 _MainTex_ST;
    47.  
    48.             v2f vert (appdata_t v)
    49.             {
    50.                 v2f o;
    51.                 o.vertex = UnityObjectToClipPos(v.vertex);
    52.                 // #ifdef SOFTPARTICLES_ON
    53.                 o.projPos = ComputeScreenPos (o.vertex);
    54.                 COMPUTE_EYEDEPTH(o.projPos.z);
    55.                 // #endif
    56.                 o.color = v.color;
    57.                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
    58.                 UNITY_TRANSFER_FOG(o,o.vertex);
    59.                 return o;
    60.             }
    61.  
    62.             sampler2D_float _CameraDepthTexture;
    63.             float _InvFade;
    64.             float _FadeDistance;
    65.            
    66.             fixed4 frag (v2f i) : SV_Target
    67.             {
    68.                 #ifdef SOFTPARTICLES_ON
    69.                 float sceneZ = LinearEyeDepth (SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos)));
    70.                 float partZ = i.projPos.z;
    71.                 float fade = saturate (_InvFade * (sceneZ-partZ));
    72.                 i.color.a *= fade;
    73.                 #endif
    74.  
    75.                 // near fade
    76.                 i.color.a = saturate((i.projPos.z - _ProjectionParams.y) / _FadeDistance);
    77.  
    78.                
    79.                 fixed4 col = 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
    80.                 UNITY_APPLY_FOG(i.fogCoord, col);
    81.                 return col;
    82.             }
    83.             ENDCG
    84.         }
    85.     }  
    86. }
    87. }
    88.