1
\$\begingroup\$

I am using projectors for shadows...When I use particles for bike speed up i.e., nitro speed the particles get cutout by those shadows....

Here is screenshot of it,

enter image description here

Here is my shader code of projectors ,

Shader "Projector/Projector Multiply Black"
{
    Properties
    {
        _ShadowTex("Cookie", 2D) = "gray" { TexGen ObjectLinear }
    _ShadowStrength("Strength",float) = 1
    }

        Subshader
    {
        Tags{ "RenderType" = "Transparent"  "Queue" = "Transparent+100" }
        Pass
    {
        ZWrite Off

        //Fog { Mode Off }

        Blend DstColor Zero

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


        struct v2f
    {
        float4 pos : SV_POSITION;
        float2 uv_Main     : TEXCOORD0;
    };

    sampler2D _ShadowTex;
    float4x4 unity_Projector;
    float _ShadowStrength;

    v2f vert(appdata_tan v)
    {
        v2f o;


        o.pos = mul(UNITY_MATRIX_MVP, v.vertex);

        o.uv_Main = mul(unity_Projector, v.vertex).xy;


        return o;
    }

    half4 frag(v2f i) : COLOR
    {
        half4 tex = tex2D(_ShadowTex, i.uv_Main);
        half strength = (1 - tex.a*_ShadowStrength);
        tex = (strength,strength,strength,strength);
        return tex;
    }
        ENDCG

    }
    }
}

Here is my particle code,

// Simple additive particle shader.

Shader "Custom/Particle additive"
{
Properties
{
    _MainTexture ("Particle Texture (Alpha8)", 2D) = "white" {}
}

Category
{
    Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    Blend SrcAlpha One
    Cull Off Lighting Off ZWrite Off Fog {Color (0,0,0,0)}

    BindChannels
    {
        Bind "Color", color
        Bind "Vertex", vertex
        Bind "TexCoord", texcoord
    }

    SubShader
    {
        Pass
        {
            SetTexture [_MainTexture]
            {
                combine primary, texture * primary
            }
        }
    }
}
}
\$\endgroup\$
6
  • 1
    \$\begingroup\$ I'm not very proficient in shaders, but it looks like it's enough to fix the relative order of this two shaders. In other words, why not set "Queue"="Transparent+110" in your particle shader? \$\endgroup\$ Sep 15, 2016 at 11:47
  • \$\begingroup\$ Tried that upto +2000 but still same occurring.... \$\endgroup\$
    – idurvesh
    Sep 15, 2016 at 12:38
  • \$\begingroup\$ While waiting for a better specialist to answer, can you make a playground project with these shaders and this issue? It'll be easier to check if a potential answer is correct, or even stumble onto one. \$\endgroup\$ Sep 15, 2016 at 13:40
  • \$\begingroup\$ Sure, check this out bit.ly/2csN85L \$\endgroup\$
    – idurvesh
    Sep 16, 2016 at 6:52
  • 2
    \$\begingroup\$ There seems to be a bug in some recent versions of Unity that disregards the order information in the shader and overrides it. You can use the debug inspector as described in this answer to check for & fix this problem. \$\endgroup\$
    – DMGregory
    Sep 20, 2016 at 3:16

1 Answer 1

0
\$\begingroup\$

Seems like the problem is that your shader does multiply blend, not additive blend, contrary to its name. The shadow shader configured to produce fully black color and when you multiply it by particle color, it's still, expectedly, completely black.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ The layering of the particle over the tire/road sure doesn't look like a multiply blend mode... \$\endgroup\$
    – DMGregory
    Sep 20, 2016 at 3:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .