Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Shuriken particle system shader with two textures

Discussion in 'Shaders' started by Allesster, Mar 26, 2014.

?

I saw this thread...

Poll closed Jan 8, 2017.
  1. but I do not understand what the problem

    0 vote(s)
    0.0%
  2. but I do not know how to solve it

    100.0%
  3. but I do not want to help

    0 vote(s)
    0.0%
  4. other

    0 vote(s)
    0.0%
Multiple votes are allowed.
  1. Allesster

    Allesster

    Joined:
    Aug 1, 2013
    Posts:
    13
    Hello!
    I'm trying to make a shader for Shuriken particle system, which can multiply two textures but it is not working properly (material works properly on the plane). If set _Pan2.x = 1, _Pan2.y = 1 then begin to flicker particles and can be seen only the first texture.
    Please help me, I do not understand what the problem.

    Code (csharp):
    1. Shader "Test/Particle/FX Duo Tst" {
    2. Properties {
    3.     _MainColor("Main Color(RGB), Alpha(A)", Color) = (1,1,1,1)
    4.    
    5.     _Emi1("Texture(RGB) Alpha(A) <1>", 2D) = "white" {}
    6.     _Pan1("Pan <1> (Speed(XY))", Vector) = (0,0,0,0)
    7.    
    8.     _Emi2("Texture(RGB) Alpha(A) <2>", 2D) = "white" {}
    9.     _Pan2("Pan <2> (Speed(XY))", Vector) = (0,0,0,0)
    10. }
    11.  
    12. Category {
    13.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    14.     Blend SrcAlpha OneMinusSrcAlpha
    15.     ColorMask RGB
    16.     Cull Off Lighting Off ZWrite Off Fog { Mode Off }
    17.  
    18.     SubShader {
    19.         Pass {
    20.        
    21.             CGPROGRAM
    22.             #pragma vertex vert
    23.             #pragma fragment frag
    24.             #pragma multi_compile_particles
    25.             #pragma target 3.0
    26.             #include "UnityCG.cginc"
    27.        
    28.             float4 _MainColor;
    29.            
    30.             sampler2D _Emi1;
    31.             float4 _Emi1_ST;
    32.             float4 _Pan1;
    33.            
    34.             sampler2D _Emi2;
    35.             float4 _Emi2_ST;
    36.             float4 _Pan2;
    37.                    
    38.             struct appdata_t {
    39.                 float4 vertex : POSITION;
    40.                 fixed4 color : COLOR;
    41.                
    42.                 float2 uv_Emi1 : TEXCOORD0;
    43.                 float2 uv_Emi2 : TEXCOORD1;
    44.             };
    45.  
    46.             struct v2f {
    47.                 float4 vertex : POSITION;
    48.                 fixed4 color : COLOR;
    49.                            
    50.                 float2 uv_Emi1 : TEXCOORD0;
    51.                 float2 uv_Emi2 : TEXCOORD1;
    52.             };
    53.                        
    54.             v2f vert (appdata_t v)
    55.             {
    56.                 v2f o;
    57.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    58.                
    59.                 o.color = v.color;
    60.                 o.uv_Emi1 = TRANSFORM_TEX(v.uv_Emi1,_Emi1);
    61.                 o.uv_Emi2 = TRANSFORM_TEX(v.uv_Emi2,_Emi2);
    62.                 return o;
    63.             }
    64.                        
    65.             fixed4 frag (v2f IN) : COLOR
    66.             {              
    67.                 float2 UV_Pan1 = float2( IN.uv_Emi1 + _Time.y * _Pan1.xy);
    68.                 float4 c = tex2D(_Emi1,UV_Pan1);
    69.                        
    70.            
    71.                 float2 UV_Pan2 = float2( IN.uv_Emi2 + _Time.y * _Pan2.xy);
    72.                 float4 d = tex2D(_Emi2,UV_Pan2);
    73.            
    74.                 return IN.color  * c * d * _MainColor;
    75.                                                                                                                                                        
    76.             }
    77.             ENDCG
    78.         }
    79.     }
    80. }
    81. }
    82.  
     
  2. Allesster

    Allesster

    Joined:
    Aug 1, 2013
    Posts:
    13
    somebody help :confused:
     
  3. Allesster

    Allesster

    Joined:
    Aug 1, 2013
    Posts:
    13
    I tried everything but it does not want to work :-(
     
  4. Allesster

    Allesster

    Joined:
    Aug 1, 2013
    Posts:
    13
    though somebody had seen this thread?
     
  5. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    Have you tried just using the provided UV coordinates instead of adding time * pan to it?
    Does it work if you only display 1 of the textures (in both cases)?
    Are your textures set to Clamp or Repeat?

    Try testing if individual color properties work
     
  6. Phantomx

    Phantomx

    Joined:
    Oct 30, 2012
    Posts:
    202
    Shuriken does not support 2 UV Channels, that's why it was working with a plane but not on particles.

    This is how I would do it:

    Code (csharp):
    1.  
    2.     Shader "Test/Particle/FX Duo Tst" {
    3.     Properties {
    4.         _MainColor("Main Color(RGB), Alpha(A)", Color) = (1,1,1,1)
    5.        
    6.         _Emi1("Texture(RGB) Alpha(A) <1>", 2D) = "white" {}
    7.         _Emi2("Texture(RGB) Alpha(A) <2>", 2D) = "white" {}
    8.         _Pan1("Pan XY (Tex1) | ZW (Tex2)", Vector) = (0,0,0,0)
    9.  
    10.     }
    11.  
    12.     SubShader {
    13.  
    14.             Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    15.             Blend SrcAlpha OneMinusSrcAlpha
    16.             ColorMask RGB
    17.             Cull Off Lighting Off ZWrite Off Fog { Mode Off }
    18.  
    19.         Pass {
    20.        
    21.             CGPROGRAM
    22.             #pragma vertex vert
    23.             #pragma fragment frag
    24.             #pragma multi_compile_particles
    25.             #pragma target 3.0
    26.             #include "UnityCG.cginc"
    27.        
    28.             float4 _MainColor;
    29.            
    30.             sampler2D _Emi1;
    31.             float4 _Emi1_ST;
    32.             float4 _Pan1;
    33.            
    34.             sampler2D _Emi2;
    35.             float4 _Emi2_ST;
    36.  
    37.                    
    38.             struct appdata_t {
    39.                 float4 vertex : POSITION;
    40.                 fixed4 color : COLOR;
    41.                 float2 uv_Emi1 : TEXCOORD0;
    42.             };
    43.  
    44.             struct v2f {
    45.                 float4 vertex : POSITION;
    46.                 fixed4 color : COLOR;          
    47.                 float2 uv_Emi1 : TEXCOORD0;
    48.                 float2 uv_Emi2 : TEXCOORD1;
    49.             };
    50.                        
    51.             v2f vert (appdata_t v)
    52.             {
    53.                 v2f o;
    54.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    55.                
    56.                 o.color = v.color;
    57.                 o.uv_Emi1 = TRANSFORM_TEX(v.uv_Emi1,_Emi1);
    58.                 o.uv_Emi1.x += _Time * _Pan1.x;
    59.                 o.uv_Emi1.y += _Time * _Pan1.y;
    60.                
    61.                 o.uv_Emi2 = TRANSFORM_TEX(v.uv_Emi1,_Emi2);
    62.                 o.uv_Emi2.x += _Time * _Pan1.z;
    63.                 o.uv_Emi2.y += _Time * _Pan1.w;
    64.                
    65.                 return o;
    66.             }
    67.                        
    68.             fixed4 frag (v2f IN) : COLOR
    69.             {              
    70.                 float4 c = tex2D(_Emi1,IN.uv_Emi1);
    71.                 float4 d = tex2D(_Emi2,IN.uv_Emi2);
    72.  
    73.                 return IN.color * c * d * _MainColor;
    74.                                                                                                                                                        
    75.             }
    76.             ENDCG
    77.         }
    78.     }
    79. }
    80.