NokiMo
pucklovesgames
pucklovesgames

patreon


Fake Billboard Lights - FILES

I've been wanting to make this one for a while - instead of using point lights, this shader fakes it with a billboard quad and calculates all the lighting manually using the Normals and Depth information in the _CameraDepthNormalsTexture render texture. You'll need to make sure your camera is rendering this DepthNormals texture if it's not already. There's a script included to force it.

Some of the benefits of this is what you can have a thousand lights shining in forward rendering, and also that you can use a stylised lighting style (toon, or a gradient, or a custom lighting falloff) and it will work regardless of the material being "lit" (in the above gif, the ground is just using the Standard Shader).

It doesn't do specular or take into consideration any material properties on the underlying geometry, so this is probably best for non-photorealistic rendering, or perhaps for small point light decorations on armour, lights on a christmas tree, hanging lanterns etc, that are small enough to not use real lights, but you still want them to illuminate things very close by.

I imagine the shader might also be useful for a point-light Level of Detail thing - where up close you use real point lights, then off in the distance you can replace them with these faking lighting quads - and then even further away with just glowy sprites.

I'm not sure how heavy this effect is to be honest - There could be a potential overdraw performance issues if you want to stack a bunch of lights up close, although I didn't notice any problems with over a thousand particle lights going on my PC.

One of the potential issues with the effect is that the fake light won't "cast light" on the scene if it's behind the camera, because then the quad won't be rendered - if you move the camera into the quad, you'll see the lighting suddenly disappear as the quad is culled. If this is a problem, it might be a good idea to fade the light out as you get too close. Another potential fix is to push the vertices of the quad back by the light-radius distance when near the camera so that you can always see the illumination. I'll have to give that a try in the future.

For the particle system version of the shader, you have to pass in the particle Center position and Size in order for the effect to work properly.

You can do this in the Custom Vertex Streams section of the Particle System, and then match that output in your shader (in this case, the W,T of UV1 and U of UV1 for Center position, and the V of UV2 for Size).

I've included a few extras in the shader, such as a flare-like glow and 'light bulb' blob in the middle of the quad, but I'm sure most people won't need that so feel free to strip it out.

Let me know if you have any questions or suggestions! Thank you for all the support.

-Ed


UPDATE:

Thanks to some really helpful info on twitter (from Chris_Does_Code and James Margaris), I've been educated on the use of Inverted Icosahedrons (low res poly-spheres with frontface culling instead of backface), which fix some of the problems with the billboard version - specifically it should now work even when the "light source" is behind the camera.

I've also added in a Negative version of the light, which might come in handy to darken some spaces (I believe they use a similar approach in the game Inside), and these lights should also support non-uniform scaling, although I haven't tested that much. I think with some tweaks I should even be able to make other primitive area light shapes with it, such as cubes and tubes.

Grab the latest FakeLight_02_Icosahedrons_Unity2019.1.1f1 zip file, as it contains all the old billboard light variations and also the new icosahedron ones.

Cheers,

-Ed


UPDATE 2 - BUG FIX!

Thanks to Andrey Eliseev for pointing out a bug in the normals calculation for these fake lights. The normal texture wasn't properly being transformed into world space. I've fixed the issue and uploaded a combined unity package which contains all the billboard, icosahedron and also the texture projection versions of the mesh lights.

Please download FakeLight_textureProjection_03_FIX_Unity2019.3.0f3.unitypackage for the latest files that include the fix.

If you have already brought these lights into your project and want to apply the fix manually, you'll have to change the View Matrix multiplication and swap it for a Transform Direction (view to world) in the World Normals section of the shaders.

Sorry about the mistake, and thanks again to Andrey Eliseev for helping me figure out what was going wrong.

-Ed

Fake Billboard Lights - FILES

Comments

it not works for URP?

Vito Gusmano

Amazing effect! Seems that no works with orthographic camera.

mossman


Related Creators