Author Topic: Shuriken particles with 2.7  (Read 17662 times)

pahe

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
    • View Profile
Shuriken particles with 2.7
« on: September 19, 2013, 01:12:05 AM »
Hey.

I've updated my project to 2.7 and enabled the depth sorting of the UIPanels. Works very nice and I'm glad that the system changed so we have more control over the sorting. But now I have the problem the problem that all my particle systems are not shown anymore. I changed the shaders of them to NGUI shaders, but it didn't work. I don't have the depth value setting, so I'm not sure how to bring them into the background again. Haven't found a new script which would solve the problem.

Anyone a hint what I can do?

Thanks for help.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Shuriken particles with 2.7
« Reply #1 on: September 19, 2013, 03:30:02 PM »
Change the shader used by the particles. NGUI uses Render queue 3000 for depth of 0, and then each draw call with the widget of highest depth (in 2.7) will add its depth to the render queue. So for example if your highest widget had a depth of 10, it would be drawn with the render queue of 3010.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Shuriken particles with 2.7
« Reply #2 on: September 19, 2013, 03:50:11 PM »
Change the shader used by the particles. NGUI uses Render queue 3000 for depth of 0, and then each draw call with the widget of highest depth (in 2.7) will add its depth to the render queue. So for example if your highest widget had a depth of 10, it would be drawn with the render queue of 3010.

Can you explain this better? I am having the same issue... My particle effects are showing up behind all my sprites :-(

pahe

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
    • View Profile
Re: Shuriken particles with 2.7
« Reply #3 on: September 19, 2013, 03:56:08 PM »
Ok, so we have to write a custom shader for now which takes simply the higher depth value in the render queue, am I right?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Shuriken particles with 2.7
« Reply #4 on: September 19, 2013, 04:02:57 PM »
If you need it to be drawn after the UI -- yes.

So for example if your shader has the following tag:
  1. Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
You'd change it to something like this:
  1. Tags { "Queue"="Transparent+100" "IgnoreProjector"="True" "RenderType"="Transparent" }
Here's the full shader for your convenience.
  1. Shader "Particles/Alpha Blended 100" {
  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+100" "IgnoreProjector"="True" "RenderType"="Transparent" }
  10.         Blend SrcAlpha OneMinusSrcAlpha
  11.         AlphaTest Greater .01
  12.         ColorMask RGB
  13.         Cull Off Lighting Off ZWrite Off
  14.         BindChannels {
  15.                 Bind "Color", color
  16.                 Bind "Vertex", vertex
  17.                 Bind "TexCoord", texcoord
  18.         }
  19.        
  20.         // ---- Fragment program cards
  21.         SubShader {
  22.                 Pass {
  23.                
  24.                         CGPROGRAM
  25.                         #pragma vertex vert
  26.                         #pragma fragment frag
  27.                         #pragma fragmentoption ARB_precision_hint_fastest
  28.                         #pragma multi_compile_particles
  29.                        
  30.                         #include "UnityCG.cginc"
  31.  
  32.                         sampler2D _MainTex;
  33.                         fixed4 _TintColor;
  34.                        
  35.                         struct appdata_t {
  36.                                 float4 vertex : POSITION;
  37.                                 fixed4 color : COLOR;
  38.                                 float2 texcoord : TEXCOORD0;
  39.                         };
  40.  
  41.                         struct v2f {
  42.                                 float4 vertex : POSITION;
  43.                                 fixed4 color : COLOR;
  44.                                 float2 texcoord : TEXCOORD0;
  45.                                 #ifdef SOFTPARTICLES_ON
  46.                                 float4 projPos : TEXCOORD1;
  47.                                 #endif
  48.                         };
  49.                        
  50.                         float4 _MainTex_ST;
  51.  
  52.                         v2f vert (appdata_t v)
  53.                         {
  54.                                 v2f o;
  55.                                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
  56.                                 #ifdef SOFTPARTICLES_ON
  57.                                 o.projPos = ComputeScreenPos (o.vertex);
  58.                                 COMPUTE_EYEDEPTH(o.projPos.z);
  59.                                 #endif
  60.                                 o.color = v.color;
  61.                                 o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
  62.                                 return o;
  63.                         }
  64.  
  65.                         sampler2D _CameraDepthTexture;
  66.                         float _InvFade;
  67.                        
  68.                         fixed4 frag (v2f i) : COLOR
  69.                         {
  70.                                 #ifdef SOFTPARTICLES_ON
  71.                                 float sceneZ = LinearEyeDepth (UNITY_SAMPLE_DEPTH(tex2Dproj(_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.                                 return 2.0f * i.color * _TintColor * tex2D(_MainTex, i.texcoord);
  78.                         }
  79.                         ENDCG
  80.                 }
  81.         }      
  82.        
  83.         // ---- Dual texture cards
  84.         SubShader {
  85.                 Pass {
  86.                         SetTexture [_MainTex] {
  87.                                 constantColor [_TintColor]
  88.                                 combine constant * primary
  89.                         }
  90.                         SetTexture [_MainTex] {
  91.                                 combine texture * previous DOUBLE
  92.                         }
  93.                 }
  94.         }
  95.        
  96.         // ---- Single texture cards (does not do color tint)
  97.         SubShader {
  98.                 Pass {
  99.                         SetTexture [_MainTex] {
  100.                                 combine texture * primary
  101.                         }
  102.                 }
  103.         }
  104. }
  105. }

pahe

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 1
  • Posts: 37
    • View Profile
Re: Shuriken particles with 2.7
« Reply #5 on: September 19, 2013, 04:06:22 PM »
Thanks! That helps very much (for the one who are not that familiar with shader programming like me :) ).

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Shuriken particles with 2.7
« Reply #6 on: September 19, 2013, 04:13:28 PM »
Still no luck, either modifying my shader or using yours.

What should this particle be parented to?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Shuriken particles with 2.7
« Reply #7 on: September 19, 2013, 04:15:12 PM »
Nothing. But you need to set the particle system's Layer so that it's on the same layer as your UI.

NaxIonz

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 70
    • View Profile
Re: Shuriken particles with 2.7
« Reply #8 on: September 19, 2013, 04:17:09 PM »
Okay, fixed it... had to change it to -100, not +

kurayami88

  • Guest
Re: Shuriken particles with 2.7
« Reply #9 on: September 24, 2013, 02:34:21 PM »
I have an alternate solution to modifying any shader script.
--------------


1. create a new sub-camera
( easiest is to clone NGUI's camera - No not the root-2D/3D but the camera object child of it)

2. make use of a new layer ( i used layer8 and called it "anims" )
to know more about layering - http://docs.unity3d.com/Documentation/Components/Layers.html

3. assign the new sub-camera to a higher "depth" value (in the camera inspector properties) than the NGUI camera. (default NGUI camera uses depth-1)

4. assign the new sub-camera "culling mask" to only display your new layer 'x' ( or what ever name you gave it )

5. assign all game object which contains your particle component to be rendered under layer 'x'.

6. sit back and enjoy the fireworks :)

alexlange

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 34
    • View Profile
Re: Shuriken particles with 2.7
« Reply #10 on: November 15, 2013, 02:55:50 AM »
I have an alternate solution to modifying any shader script.
--------------


1. create a new sub-camera
( easiest is to clone NGUI's camera - No not the root-2D/3D but the camera object child of it)

2. make use of a new layer ( i used layer8 and called it "anims" )
to know more about layering - http://docs.unity3d.com/Documentation/Components/Layers.html

3. assign the new sub-camera to a higher "depth" value (in the camera inspector properties) than the NGUI camera. (default NGUI camera uses depth-1)

4. assign the new sub-camera "culling mask" to only display your new layer 'x' ( or what ever name you gave it )

5. assign all game object which contains your particle component to be rendered under layer 'x'.

6. sit back and enjoy the fireworks :)

I like this, very easy way! Thank you dude :)