Thursday, October 2, 2014

Lit Particle Shaders Demo

I've been working on some custom shaders for Shuriken particle effects in Unity. The main idea is to fill gaps that currently exist in the available alpha blended material.


Crucially, the default alpha blended material does not receive light from the scene -- not ambient or direct illumination. I originally wanted to also support point lights, but with the current limits on what data you can know about particle positions and normals, it ends up being a fairly complicated and performance-prohibitive feature.

That's why my shader supports lighting from directional sources and ambient sources. I did manage to get vertical hemispherical lighting working, so particles can receive disparate lighting from the top and bottom (either directional on top or on bottom).

There's also not good default way of modelling emissivity in particles. You have to either have two particle systems with two different materials one alpha and the other additive, or take what you can fudge from the alpha blended. I found myself always making "glow" particle effects to play alongside other effects, so I just wrote a shader that supports that kind of effect by using multiple passes and materials. Unfortunately, Shuriken can only pass one float4 value through the vertex color input of a CG program, so the "color" values in the Shuriken system only refer to the glow color and the general alpha of the particle. The "background" color of the particle can only be adjusted per-material. This turns out to not be much of a problem in practice, though, and it's an unambiguous step up from the default workaround for this effect.

Anyway, I hope to make it available for purchace on the asset store shortly.

3 comments:

  1. Hi, I'm really interested in this, as I just found out that Unity doesn't seem to support lit particles out of the box, and no tutorials/info available how to implement them.

    Does your solution work in Unity 5? With the real deferred? (Obviously particles need to use forward lighting but still).

    If you need beta testers, give me a msg and I'll test it for you :D

    ReplyDelete
  2. Hello, I didn't find this in the Asset Store yet... any news, or other suggestions for a lit particle shader?

    Thanks.

    ReplyDelete
  3. I'm super interested in this as well! Would definitely buy it if you put it up on the asset store. Keep up the great work!

    ReplyDelete