How to override ambient light with a VolumeComponent?
Asked Answered
C

0

1

Hi, I’m looking for some advice on how to manage lighting override volumes using URP.

We are using a fairly standard URP setup for game rendering and lighting:

  • Lighting is realtime only, using Forward+ rendering.
  • Ambient light is defined in a scene’s Lighting>Environment settings, as a color.
  • There is a standard post-processing stack that handles both built-in and custom post-processing.

What I’m now trying to do is set up a system for override volumes, so that parts of a scene can have different post-processing and lighting conditions.

For the most part, this has worked pretty well. I can set up a volume under GameObject > Volume > Box Volume and position it as needed. Selecting the volume object, I can then add any override as needed, as is standard for URP. This works great!

The issue I’m having is that I want to also override the level’s ambient color using the same volume setup - in other words, the color set per-scene under Lighting > Environment > Environment Lighting > Ambient Color. My intended behavior is for this to work as a VolumeComponent so that it benefits from all the advantages of using the URP volume system.

Somewhat surprisingly to me, there does not seem to be any kind of built in way to do this. So I attempted it myself by making my own VolumeComponent script, defining an override color as such:

[VolumeComponentMenu("Lighting/" + nameof(EnvironmentLightingOverride))]
public class EnvironmentLightingOverride : VolumeComponent, IPostProcessComponent
{
    //Color to override
    public ColorParameter ambientColor = new ColorParameter(Color.black, false, false, false);
}

And then adding it as an override to my volume. This shows up as expected and lets me pick a color as expected.

However, I’m now at a loss on how to actually apply this color as the new ambient color. I’m not sure where, how and when I’d actually call this - normally I’d just change the ambient color as such:
RenderSettings.ambientSkyColor = ambientColor.value;

But there’s no obvious place to call this and I get the impression that this is not how a VolumeComponent is supposed to be integrated. Is there something I’m missing here? How would I actually set this up so that the ambient color blends, both at runtime and edit mode, between the chosen override and the default color based on whether you are within the volume or not? In other words, for the behavior to work exactly like the already included overrides.

Would be grateful for any advice or direction here! Thanks!

Calhoun answered 15/3, 2024 at 19:33 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.