Adding Soft Particles to a Vertex Lit Particle Shader

Is this possible?

Here’s my existing shader that I would like to add soft particles to:

Shader "Particles/VertexLit Blended2" {
Properties {
	_EmisColor ("Emissive Color", Color) = (.2,.2,.2,0)
	_MainTex ("Particle Texture", 2D) = "white" {}
}

SubShader {
	Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
	Tags { "LightMode" = "Vertex" }
	Fog {Mode Off}
	Cull Off
	Lighting On
	Material { Emission [_EmisColor] }
	ColorMaterial AmbientAndDiffuse
	ZWrite Off
	ColorMask RGB
	Blend SrcAlpha OneMinusSrcAlpha
	AlphaTest Greater .001
	Pass { 
		SetTexture [_MainTex] { combine primary * texture }
	}
}
}

I know very little about shader programming, but the other shaders that already support soft particles do not give me the effect I’m looking for. The blending modes are way too extreme and the vertex shader above gives me exactly what I want (color and blending), except for the fact that all the particles intersect with the scene geometry. If anyone could point me in the right direction I would appreciate it. I’m looking for something similar to this: https://www.youtube.com/watch?v=ES0IY_e5Kd8.

Anyone have any ideas? Still not really sure what to do here.

I doubt you can achieve that with a fixed function shader (why does everyone keep using them anyways?). Move on to a surface shader… or even better, custom vert/frag shader

I still have not found any way to achieve this effect in Unity. I would even be willing to pay someone who could program a shader with vertex lighting and depth blending.

You should write shader for particles.

On vertex shader calculate depth of vertex.
On pixel shader read depth and compare to depth from vertex shader.

And lerp alpha to 0, if difference is smaller that some bias.

Contact me if you want me to write that shader.

The problem is with the lighting, it so hard to make them work with particles

Hm, yeah. Looks like particles shader cannot access _WorldSpaceLightPos0 or something like that…

That’s so strange. So how does the Vertex Lit particle shader get lighting information then? There are particle shaders with depth blending (soft particles) and there are particle shaders with vertex lighting… why can’t you have both?

I just wanted to say, I came across this thread looking for the same thing (a vertex-lit soft particle shader) and I was unable to find one.

However depending on your scene, you might be able to get away with using the soft particle shader and simply modify the color & alpha value to fake a type of “global” lighting intensity. I’ve been using this with a directional sun light that has a basic day/night cycle and it doesn’t look too bad.

I have managed to do exactly as you have suggested. It works well enough to get the desired effect. My biggest issue was wanting to have my soft particles illuminated by a flashlight or other light sources, but oh well.

Try this not perfect tho,there’s still some weird stuff happened

Shader "Rea/Particles/Lit-Alpha Blended " {
Properties {
   _TintColor ("Tint Color", Color) = (0.5,0.5,0.5,0.5)
   _MainTex ("Particle Texture", 2D) = "white" {}
   _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 1.0
}

Category {
   Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"  }
   Blend SrcAlpha OneMinusSrcAlpha
   ColorMask RGB
   Cull Off Lighting On ZWrite Off

   
   // ---- Fragment program cards
   SubShader {
     Pass {

       CGPROGRAM
       #pragma vertex vert
       #pragma fragment frag
       #pragma fragmentoption ARB_precision_hint_fastest
       #pragma multi_compile_particles
       
       #include "UnityCG.cginc"

       sampler2D _MainTex;
       float4 _TintColor;

       struct appdata_t {
         float4 vertex : POSITION;
         fixed4 color : COLOR;
         float2 texcoord : TEXCOORD0;
         float3 normal : NORMAL;
       };

       struct v2f {
         float4 pos : POSITION;
         fixed4 color : COLOR;
         float2 texcoord : TEXCOORD0;
         float2 DisCoord : TEXCOORD1;

         float4 projPos : TEXCOORD2;

         float3 VL : TEXCOORD3;

         float3 normal :TEXCOORD4;
         float3 ViewT : TEXCOORD5;

       };
       
       float4 _MainTex_ST;
       float4 _Dist_ST;

       v2f vert (appdata_t v)
       {
         v2f o;
         o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

         o.projPos = ComputeScreenPos (o.pos);
         COMPUTE_EYEDEPTH(o.projPos.z);

         o.color = v.color;
         o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
         o.DisCoord = TRANSFORM_TEX(v.texcoord,_Dist);
         o.normal = normalize(v.normal);
         o.ViewT = normalize(ObjSpaceViewDir(v.vertex));
         o.VL = ShadeVertexLights(v.vertex, dot(o.normal,o.ViewT));
         return o;
       }

       sampler2D _CameraDepthTexture;
       float _InvFade;
       
       fixed4 frag (v2f i) : COLOR
       {

         float4 tex = tex2D(_MainTex, i.texcoord);

         float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.projPos))));
         float partZ = i.projPos.z;
         float fade = saturate (_InvFade * (sceneZ-partZ));
         i.color.a *= fade;

         float4 VertL = (dot(i.ViewT,i.VL));
         return 2.0f * float4(i.VL,1.0) * i.color  * _TintColor * tex;

       }
       ENDCG
     }
   }    
   
   // ---- Dual texture cards
   SubShader {
     Pass {
       SetTexture [_MainTex] {
         constantColor [_TintColor]
         combine constant * primary
       }
       SetTexture [_MainTex] {
         combine texture * previous DOUBLE
       }
     }
   }
   
   // ---- Single texture cards (does not do color tint)
   SubShader {
     Pass {
       SetTexture [_MainTex] {
         combine texture * primary
       }
     }
   }
}
}
1 Like

not to be the party pooper but you will have problems getting lights to work on particles, mainly because particle are dynamically generated to be just one mesh which will produce errors in the additional lights when particle stack on top of each other, they will get additive, you can still make 4 vertex lights to work or invent your own system to simulate surround lighting, i’m just alerting you with the incoming problems