Search Unity

Particles receiving shadows?

Discussion in 'Shaders' started by powdered_swords, May 5, 2013.

  1. powdered_swords

    powdered_swords

    Joined:
    Mar 11, 2013
    Posts:
    28
    Does anyone know if it's possible for vertex lit particles to be affected by shadows generated by geometry? I made a small demo testing the functionality of vertex lit particles



    Unfortunately while I could get the particles to project shadows onto the two surfaces the opposite was not true.
     

    Attached Files:

  2. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Vertex lighting does not support receiving shadows; you need per-pixel lighting for that.
     
  3. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
  4. powdered_swords

    powdered_swords

    Joined:
    Mar 11, 2013
    Posts:
    28
  5. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    It's a bit flakey (which is why it's a secret, rather than public gist). But it should help.
     
  6. reecpj

    reecpj

    Joined:
    Apr 5, 2013
    Posts:
    4
    This looks really interesting Farfarer (sorry it's been so long since you posted) but how could I get it working with multi_compile_fwdadd_fullshadows in the ForwardAdd pass for spotlight shadows?
    It says: "Custom/Lit Particle Additive': Program 'vert', unable to find compatible overloaded function "mul(float4x4[4], float4)" at line 116"
    but still renders ok. That line is TRANSFER_VERTEX_TO_FRAGMENT_PARTICLE(o); which expands to
    #define TRANSFER_VERTEX_TO_FRAGMENT_PARTICLE(a) a._LightCoord = mul(_LightMatrix0, posW); TRANSFER_SHADOW_PARTICLE(a)

    Currently the particles seem to be evaluating the shadow map in camera space or something - I have to zoom out and rotate around for any light to show up - certainly they don't respond as if they are in world space. I'd really appreciate some help, you've done a lot for my shader education already!
     
  7. reecpj

    reecpj

    Joined:
    Apr 5, 2013
    Posts:
    4
    Never mind, I got it working (using my own shadow maps rather than Unity's) - I didn't realise the shuriken particles were in camera space, so you can multiply them by the camera to world matrix to get them in world space. Thanks!