Hello, I have a scene where the player has to fly through a tunnel of particles. The particles use the Mobile/Particles/Additive shader and everything was okay until today when tested the scene. The scene has fog and the particles are supposed to fade in the distance. However since today they don’t seem to be affected by the fog correctly. They are additive and they should fade away as the fog gets denser in the distance. However, only the texture fades away and the particle mesh is still visible. Infact, they seem to add the fog color to their surface somehow and start to look even brighter.
I switched to Particles/Additive (not mobile) and the issue was gone but I want to know why does this happen with the mobile shader. I know it worked yesterday so what could I have done to change that ?
Below I’m attaching an image of the scene with the mobile additive shader and then with the standard particle additive shader.
Additive shaders should have a black fog color, which the normal additive particles handle properly. The mobile particle shaders dont handle fog accurately as an optimization.
Hm, you’re right. I made a new project with a simple scene with fog and a particle system which uses a mobile additive shader and I got the same result. I must have used a different shader by mistake before I posted the thread and then switched to mobile for real.
I guess I’ll have to find an alternative that’s the golden middle between the performance of the mobile shader and the fog handling on the default one.
The way the mobile additive particle shader is handling fog I think is just straight up broken in 5, and not significantly more expensive than the normal shader.
edit: Yep, it’s broken. The artifacts you’re seeing shouldn’t be happening, even with the mobile shader. However it wouldn’t be hard to make a version of the shader that’s identical in performance (and works).
Shader "Particles/Additive Cheap" {
Properties {
_MainTex ("Particle Texture", 2D) = "white" {}
}
Category {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha One
Cull Off Lighting Off ZWrite Off
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fog
#include "UnityCG.cginc"
sampler2D _MainTex;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
UNITY_FOG_COORDS(1)
};
float4 _MainTex_ST;
v2f vert (appdata_t v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
fixed4 frag (v2f i) : SV_Target
{
fixed4 col = i.color * tex2D(_MainTex, i.texcoord);
UNITY_APPLY_FOG_COLOR(i.fogCoord, col, fixed4(0,0,0,0)); // fog towards black due to our blend mode
return col;
}
ENDCG
}
}
}
}
That compiles down to almost exactly the same as the mobile particle shader, but should apply fog correctly.
Mobile Particle Add stats:
New Particle Add Cheap:
Funny enough this cheap shader is actually a little faster than the mobile (on d3d9), but is just the expected expansion of the fixed function shader.
Thanks, bgolus! That’s really helpful. I used a similar solution already but I have yet to test it on different mobile devices. My shader works on Galaxy S4. I’ll try your solution too!