On GetAdditionalLightsCount() in Post-Processing in URP

by Michael Sacco Published May 6, 2023
The cover for On GetAdditionalLightsCount() in Post-Processing in URP

Today, I revisited some features in Buto’s volumetric lighting system. One feature area that I wanted to extend was our support for additional lights. Although Buto does currently support additional lights, it does not support Additional Light shadows.

My current implementation for additional light support asks users to add a component to preferred Additional Lights that should be injected to the volumetric rendering pass. This component parses some lighting data, records the light in a list of nearby light records, and is shared to the GPU.

Ideally, this would all work seamlessly. You add an Additional Light, it pops into the volumetrics.

However, I observed during initial testing some time ago that the GetAdditionalLightsCount() and GetAdditionalLight() methods behaved oddly. They work normally when tapped on any object shaders. When accessed from a post-process system like Buto, the lights flicker, jump, go missing, re-appear, and so on.

At the time, I found this post on Reddit in which CustomPhase explains that the AdditionalLightsCount() and GetAdditionalLight() methods are set per-object by Unity during rendering. Hence the approach I took for the lights.

Revisiting this today, I re-encountered the same issue and thought I would make a note of it here.

For now, I plan to hold off on extending support for additional light shadows. Apart from the additional code complexity, I think most use cases can be addressed with a little level design. Apart from that, I would really rather avoid the performance cost associated with sampling as many as 8 additional lights per step per pixel per frame.

So, be warned! :) If you are writing a post-process (i.e., not object-based) shader that depends on Additional Light data, you will need to store and pass all relevant additional lighting data yourself.

Free download: Indie Game Marketing Checklist

Download now

Category

technical art

Don't forget to share this post!

Popular assets for Unity

See all assets ->
    Cutting-edge volumetric fog and volumetric lighting with support for transparent materials.
    Volumetric clouds, day night cycles, dynamic skies, global lighting, weather effects, and planets and moons.
    A lightweight procedural skybox ideal for semi-stylized projects.
    Image-based Outlines for 2D and 3D games with variable line weight, color, and displacement options.
    Drag-and-drop ready-to-use ambient, impact, and spell particle effects.
    Per-pixel gaussian blur on your entire screen, part of the UI, or in-scene objects.

Free Indie Game Marketing Checklist

Learn how to make your game successful with this handy checklist.

Download for free