How is unity3d rendering system works for particles?

Hi all,

I know that for transparent object, unity render them from back to front. That make sense, but why I am getting these effect when the explosion is happened behind the smoke?

I use alpha blend for both of them, and it seems that the explosion has completely overwrite the smoke in terms of rendering.

Can it be due to that the explosion is happened after the smoke is poped, In that case, maybe the alpha blend shader of explosion may override the smoke one?

Any ideas if that is the case?

I can’t see your picture (broken link icon) but I’ll take a guess.

Particles can sort per-system or per-particle. I’m not sure if per-system sorting is based on the pivot point or the center, but I suggest that’s probably the culprit here.

Alternatively, I think you can turn on per-particle sorting, but keep in mind that it’s significantly more expensive. Unless you want the systems to be on top of one another or need sorting within a system it’s better to get things working with the per-system sorting. Basically, you want to sort on as broad a level as possible.

3 Likes

Thank you very much for replying! I will give the per-particle sorting a try. Here is my question on unity answers, I got my picture link over there if you are interested in the problem
http://answers.unity3d.com/questions/963245/question-about-alpha-blend-shader-and-other-partic.html

Basically I am implementing a smoke bomb effect that emits thick smokes, but the smoke will get overrides by the other particle that suppose to be happened behind the smoke from the camera point of view.

If I want to keep the per-system sorting, do I need to make sure my particle system is scaled large enough? Normally how is a smoke bomb effect should be implemented?

Here attach the picture again just in case.

2110025--138396--46098-q1.png

That picture isn’t actually very helpful to me. It’s not clear that the flame is overriding the smoke. It’s clear that both are clipping with the ground. Can you remove the ground plane and show just the particles?

Sorry for the picture, I just noticed that is not very self explanatory! So here attach the side view, basically what happen is when my tank pop out a smoke screen, if explosion or any other particle effect happens behind that smoke, smoke particle will get overridden.

If you see through the smoke form the front, you will see the effect on my previous picture. Here attached the unity cloud build if you want to try out

https://build.cloud.unity3d.com/distro/install?id=Z1JMLPKjye

2110057--138400--sideview.png

Right, what materials and shaders are on those things? All you’ve said is “alpha blend”, but that on its own isn’t the whole story.

Thanks for trying to help!

Here is the shader I used for the smoke

Shader "Scroll/Alpha Blended"
{
    Properties
    {
        _MainTex ("Looped Texture + Alpha Mask", 2D) = "white" {}
        _InvFade ("Soft Particles Factor", Range(0.01,3.0)) = 3.0
       
        _ScrollSpeed ("Scroll Speed", Float) = 2.0
    }
   
    Category
    {
        Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
        //Fog {Mode Global Density 255}
        //Blend DstColor SrcColor
        Blend SrcAlpha OneMinusSrcAlpha
        ColorMask RGB
        Cull Off Lighting Off ZWrite Off
        BindChannels
        {
            Bind "Color", color
            Bind "Vertex", vertex
            Bind "TexCoord", texcoord
        }
       
        // ---- 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;
               
                struct appdata_t
                {
                    float4 vertex : POSITION;
                    fixed4 color : COLOR;
                    float2 texcoord : TEXCOORD0;
                };
   
                struct v2f
                {
                    float4 vertex : POSITION;
                    fixed4 color : COLOR;
                    float2 texcoord : TEXCOORD0;
                    #ifdef SOFTPARTICLES_ON
                    float4 projPos : TEXCOORD1;
                    #endif
                };
   
                float4 _MainTex_ST;
               
                v2f vert (appdata_t v)
                {
                    v2f o;
                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                    #ifdef SOFTPARTICLES_ON
                    o.projPos = ComputeScreenPos (o.vertex);
                    COMPUTE_EYEDEPTH(o.projPos.z);
                    #endif
                    o.color = v.color;
                    o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
                    return o;
                }
   
                sampler2D _CameraDepthTexture;
                float _InvFade;
                float _ScrollSpeed;
               
                fixed4 frag (v2f i) : COLOR
                {
                    #ifdef SOFTPARTICLES_ON
                    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;
                    #endif
                   
                    fixed4 prev = i.color.a * tex2D(_MainTex, i.texcoord).a;
                    i.texcoord.y -= fmod(_Time*_ScrollSpeed,1);
                    prev.rgb = i.color.rgb * tex2D(_MainTex, i.texcoord).rgb;
//                    prev.rgb = 1-prev.rgb;
                    return prev;
                }
                ENDCG
            }
        }
    }
}

Material for smoke Dropbox - Error - Simplify your life

Texture for smoke Dropbox - Error - Simplify your life
(Sorry .mat and .tga file is not uploadable in forum)

The explosion is came from the Detonator Explosion Framework, I am not entirely sure how that works but I think the problem is causing by my smoke, I tried to change the explosion to other particle it produce the same effect, also other particles beside the explosion in the scene can “break through” my smoke as well.

Alright, first of all look into ZTest. You haven’t specified it and I’m not sure of the default, and that’s all about what can draw on top of what.

Secondly, I’d suggest trying the default (built-in) alpha-blended particle material, see if that suffers the same thing.

Thank you very much! I will have a read and try on that!

Well after another wave of searching and trying, I still could not solve this problem nicely. I decide to change the render queue of all my particles dynamically by scripting as one of the answer suggested:

It seems to be working so far, but I am just wonder if there is any other elegant way of doing this… I am sure there should be one cause this problem suppose to be simple in my point of view.

Layering of transparent stuff is unfortunately never “simple” in this style of rendering.

Yeah I now agreed with that after looking over this thread,

I am appreciated that I have a solution to my scenario.:wink: Thank you again for continuous helping angrypenguin!

1 Like