开发者

Change Color Lookup texture during runtime

开发者 https://www.devze.com 2022-12-07 22:34 出处:网络
I\'m trying to change the texture and contribution of the Color Lookup module of the post processing stack in URP.

I'm trying to change the texture and contribution of the Color Lookup module of the post processing stack in URP.

Initially I tried simply modifying the value like this:

private void SetTheme(int index)
{
    if (index > 0 && ThemeColorLookups.Length > index)
    {
        if (_globalVolume.profile.TryGet(out ColorLookup cl))
        {
            cl.texture = new TextureParameter(ThemeColorLookups[index], true);
        }
    }
    else
    {
        if (_globalVolume.profile.TryGet(out ColorLookup cl))
        {
            cl.texture = new TextureParameter(null, true);
        }
    }
}

private void SetThemeIntensity(int value)
{
    if (_globalVolume.profile.TryGet(out ColorLookup cl))
    {
        cl.contribution = new ClampedFloatParameter(value / 100f, 0, 1, true);
    }
}

This did change the values when inspecting the volume in the editor, however no changes where reflected in the game or scene view.

I also attempted completely swapping the Color Lookup instance with a new one, which more or less resulted in the same behavior as the previous approach.

private int _currentThemeIndex;
private float _currentThemeIntensity;

private void SetTheme(int index)
{
    if (index > 0 && ThemeColorLookups.Length > index)
    {
        _globalVolume.profile.Remove<ColorLookup>();

        var cl = _globalVolume.profile.Add<ColorLookup>();
        cl.contribution = new ClampedFloatParameter(_currentThemeIntensity, 0, 1, true);
        cl.texture = new TextureParameter(ThemeColorLookups[index], true);

        _currentThemeIndex = index;
    }
    else
    {
        _currentThemeIndex = 0;
        _globalVolume.profile.Remove<ColorLookup>();
    }
}

private void SetThemeIntensity(int value)
{
    _currentThemeIntensity = value / 100f;

    if (_currentThemeIndex == 0) { return; }

    _globalVolume.profile.Remove<ColorLookup>();

    var cl = _globalVolume.profile.Add<ColorLookup>();
    cl.contribution = new ClampedFloatParameter(value/100f, 0, 1, true);
    cl.texture = new TextureParameter(ThemeColorLookups[_currentThemeIndex], true);
}

Why ar开发者_Python百科e the changes not being reflected during time? If I manually modify the values during runtime the correct texture and contribution are displayed, however doing the "same" with code yields only an editor change.

It's worth noting that after this piece of code has been executed, which happens whenever you drag an UI slider, even if I attempt to modify the values manually through the editor, nothing happens (except obviously inspector update). So it basically gets bricked until I replay the scene. At which point I can again modify the values manually, however this is undesirable in my case. I would like to completely control the 2 exposed properties through code.

Unity version - 2021.2.19f1 using URP

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号