Forum rules - please read before posting.

brightness option

edited January 2018 in Technical Q&A
Hello community, hope everyone is having a nice warm day  :)

is it possible to make a built in brightness option using adventure creator menu system? just like the "speech and music" slider elements in the option menu that automatically save when adjusted? 

Comments

  •  I'm also interested in this! I think it has something to do with the new "post process" and activating the gamma and the brightness there.
  • Welcome to the community, @Akinoba.

    Further options are certainly possible, though as there's no end to what users would need AC takes the approach of allowing users to add their own with simple scripting.  A tutorial on creating a "screen resolution" option can be found here.
  • Hm,I have something but I can't make it work ... there's no error in the console however ..The idea is that, It should change ambient color in unity from AC float variable and fake brightness but only in realtime. When I moving the slider, nothing happens! Maybe someone has a suggestion, an idea?

    the code:

  • Requires a login - posting code is best done on e.g. http://pasteall.org/
  • edited January 2018
    Oh, sorry.. I didn't see! I accidentally put it, privately  ... I didn't know about this site, very good thing ...
  • You have the "RenderSettings.ambientSkyColor" method call inside unnecessary brackets.  Try removing them so that it's immediately after the rgbValue declaration.
  • Like this!

    It seems to work but it doesn't work! When I move the slider to the end, it  only switch to white (rgbValue), but not the other way round (black color). What I want is a gradual increase and decrease(from black to white and reverse) . Hm, I missing something... by the way, thank's Chris

  • Well, you're not actually using the "Brightness" variable you've declared, so it'll set the same colour each time.

    If you want the Action to run over time, you'll have to set the Action's "isRunning" bool to True, and return "defaultPauseTime" instead of zero.  This will cause the Action to re-run the next frame, and will only cease once you set "isRunning" back to False and return zero.  See the original ActionTemplate file for more.  Once you have the Action running over multiple frames, you can change the brightness gradually instead of instantly.

    Alternatively, you can move this all to a separate script and rely on a regular "Update" function.  The Action just needs to be able to pass the intended brightness to it, which can be done without running over time.
  • I overlooked some things. Although, I've got it  :) Thank's Chris
  • Hell guys,
    After some research I found a really nice way to create a Brightness/gamma menu. Here's what I did and then the questions to link it to AC.
    First: we are using URP. We didn't download the Post Processing Package. We didn't mess around with any camera.
    After we put all the lights, I've created an empty object and added the "Volume" script (I think it comes with URP).
    Then I added the following options (after creating a profile):

    • Color Adjustments (clicked them all on except color filter)
    • White Balance.

    Then the script: The script is easy enough. I will post here just the part I did: the post exposure. Basically each option should be one other float/int and one more "linking" in the update().

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;

    public class BrightnessOptions : MonoBehaviour
    {
    public Volume volume;
    public ColorAdjustments CA;
    [Range(-2, 2)] public VolumeParameter postExposureOut = new VolumeParameter();
    [Range(-2, 2)] public float postExposureValue = 0;

    void Start()
    {
        volume.profile.TryGet<ColorAdjustments>(out CA);
        if (CA == null)
            Debug.LogError("No ColorAdjustments found on profile");
    }
    void Update()
    {
        if (CA == null)
        {
            return;
        }
    
        postExposureOut.value = postExposureValue;
        CA.postExposure.SetValue(postExposureOut);
    }
    
    public void PostExposure()
    {
        postExposureOut.value = postExposureValue;
        CA.postExposure.SetValue(postExposureOut);
    }
    

    }

    Now the questions:

    1) I would like to cycle it like a Music/SFX/Speech. I found that after creating the variable (which originally was a "float", It couldn't find the variable because it wasn't an int. Any way to do it with floats?
    2) The script works at runtime but I'm finding it hard to link it through the Action List. I mean, each number of the int should be the Global Variable value. This is var17, it's Global, int (want to be float actually).
    I'm finding it hard to do that linking between numbers.

    Any help on the above will be great. Yes, I've read the screen resolution tutorial but I think that one is even harder than this.

    Thanks a lot! I think many people will make use of this, so when I'm finished I will post here the final script but so far, we are on the right track!
    AC 1.75.4
    Unity 2020.3.27f1
    Universal Renderer Pipeline needed!

  • For question 1)
    I just found "Cycle" is not the actual option I should use, rather "Slider". Now I can use floats :)

    Now the question regarding this is: any chance negative values are also taken in consideration when "filling" the bars? As of now, I can only move forward even though I set it at -20 and +20. Maybe go 0 to right and 0 to left. Because as far as I can see it now, it starts at -20 and then goes all the way to 20.

    And for the second part regarding question 1): the number of steps for the following scenario, what does it mean for floats?

    Thanks a lot!

  • edited June 2022

    You'll need to rely on an AC Global Variable so that you can sync its value with Options Data - see the Manual's "Options data" chapter for details.

    Variables can be read through script - see the Manual's "Variable scripting" chapter for details. If the variable was named "Brightness", your script could be adapted to something like:

    using UnityEngine;
    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;
    using AC;
    
    public class BrightnessOptions : MonoBehaviour
    {
    
        public Volume volume;
        public ColorAdjustments CA;
        [Range(-2, 2)] public VolumeParameter postExposureOut = new VolumeParameter();
        private GVar optionsVariable;
    
        void Start ()
        {
            volume.profile.TryGet<ColorAdjustments>(out CA);
            if (CA == null)
                Debug.LogError("No ColorAdjustments found on profile");
        }
    
        void Update ()
        {
            if (optionsVariable == null)
            {
                optionsVariable = GlobalVariables.GetVariable ("Brightness");
            }
    
            if (CA == null || optionsVariable == null)
            {
                return;
            }
    
            PostExposure ();
        }
    
        public void PostExposure ()
        {
            postExposureOut.value = optionsVariable.FloatValue;;
            CA.postExposure.SetValue(postExposureOut);
        }
    
    }
    

    any chance negative values are also taken in consideration when "filling" the bars?

    Slider elements of the type "Float Variable" can be given minimum and maximum values in the Menu Manager. Alternatively, you can keep its range (and that of the AC variable) to 0 -> 1, and convert it before applying to postExposureOut:

    float variableValue = optionsVariable.FloatValue;
    postExposureOut.value = (variableValue * 40f) - 20f;
    
  • I made it work. Let me explain what I did, and then the questions:
    I made a custom "Options" menu with a button which will bring me to the video part where I have labels, sliders and buttons. The Labels are the Gamma, etc etc etc. The Sliders are the, well, sliders. Each one has a minimum value and a maximum which should be replicated in the script (below) and the AC menus. So all three have to have the same min and max. Then the button is just an action list which will give me the default button (0 in all cases). I didn't need to do anything crazy and works.
    Also, this same menu has a prefab which has to be consistent in all scenes and basically tweaks the values. This is the prefab which has this script and is in the Menu and the scene. Any change on the scene (options menu or video options menu) will affect the prefab hence the scene. If you don't have the prefab of the video in the scene, when the menu turns off, the changes are discarded. Simply prefabing this object with the script and the "Volume" script is enough. Pictures below.


    1) But, Chris, I found a problem: the buttons activate a simple action list which just sets the Variable to Zero, but everytime I click, I can see the player behind the menu moving one frame. Every click is one click moving. I noticed that even when transitioning between Pause and Options (Options is inside Pause), it also moves the player one frame inbetween. I can't make it "freeze" even though the Pause menu has the "pause gameplay".

    In the screenshot I'm showing below, you can check how the character slowly moves everytime I press on a button. All "default buttons" do the same for different variables. If I go back to the menu, again moves a bit.

    2) For some reason this only works on gameplay lights, not menus. I may have to research harder because UI elements just like our inventory (wallet) and the menus are not affected :/

    https://imgur.com/a/P7ynwvh


    using UnityEngine;
    using UnityEngine.Rendering;
    using UnityEngine.Rendering.Universal;
    using AC;

    public class BrightnessOptions : MonoBehaviour
    {
    public Volume volume;
    public ColorAdjustments CA;
    public WhiteBalance BA;
    public LiftGammaGain LGG;

    [Range(-4, 4)] public VolumeParameter<float> postExposure = new VolumeParameter<float>();
    [Range(0, 100)] public VolumeParameter<float> constrast = new VolumeParameter<float>();
    [Range(-180, 180)] public VolumeParameter<float> hueShift = new VolumeParameter<float>();
    [Range(-100, 100)] public VolumeParameter<float> saturation = new VolumeParameter<float>();
    [Range(-100, 100)] public VolumeParameter<float> whiteTemperature = new VolumeParameter<float>();
    [Range(-100, 100)] public VolumeParameter<float> whiteTint = new VolumeParameter<float>();
    [Range(-2, 2)] public VolumeParameter<float> gamma = new VolumeParameter<float>();
    
    private GVar postExposureOptionsVariable;
    private GVar contrastOptionsVariable;
    private GVar hueShiftOptionsVariable;
    private GVar saturationOptionsVariable;
    private GVar whiteTemperatureOptionsVariable;
    private GVar whiteTintOptionsVariable;
    private GVar gammaOptionsVariable;
    
    void Start()
    {
        volume = GetComponent<Volume>();
        postExposureOptionsVariable = GlobalVariables.GetVariable(14); //Variable 14: Post Exposure
        contrastOptionsVariable = GlobalVariables.GetVariable(17); //Variable 17: Contrast
        hueShiftOptionsVariable = GlobalVariables.GetVariable(18); //Variable 18: Hue Shift
        saturationOptionsVariable = GlobalVariables.GetVariable(19); //Variable 19: Saturation
        whiteTemperatureOptionsVariable = GlobalVariables.GetVariable(20); //Variable 20: White Temperature
        whiteTintOptionsVariable = GlobalVariables.GetVariable(21); //Variable 21: White Tint
        gammaOptionsVariable = GlobalVariables.GetVariable(22); //Variable 22: Gamma
    
        volume.profile.TryGet<ColorAdjustments>(out CA);
        if (CA == null)
            Debug.LogError("No ColorAdjustments found on profile");
        volume.profile.TryGet<WhiteBalance>(out BA);
        if (CA == null)
            Debug.LogError("No WhiteBalance found on profile");
        volume.profile.TryGet<LiftGammaGain>(out LGG);
        if (LGG == null)
            Debug.LogError("No LiftGammaGain found on profile");
    }
    
    void Update()
    {
        if (CA == null || postExposureOptionsVariable == null || contrastOptionsVariable == null || hueShift == null || saturationOptionsVariable == null || whiteTemperatureOptionsVariable == null || whiteTintOptionsVariable == null || gammaOptionsVariable == null)
        {
            return;
        }
    
        PostExposure();
        Contrast();
        HueShift();
        Saturation();
        WhiteTemperature();
        WhiteTint();
        Gamma();
    }
    
    public void PostExposure() //Variable 14: Post Exposure
    {
        postExposure.value = postExposureOptionsVariable.FloatValue;
        CA.postExposure.SetValue(postExposure);
    }
    
    public void Contrast() //Variable 17: Contrast
    {
        constrast.value = contrastOptionsVariable.FloatValue;
        CA.contrast.SetValue(constrast);
    }
    
    public void HueShift() //Variable 18: Hue Shift
    {
        hueShift.value = hueShiftOptionsVariable.FloatValue;
        CA.hueShift.SetValue(hueShift);
    }
    
    public void Saturation() //Variable 19: Saturation
    {
        saturation.value = saturationOptionsVariable.FloatValue;
        CA.saturation.SetValue(saturation);
    }
    public void WhiteTemperature() //Variable 20: White Temperature
    {
        whiteTemperature.value = whiteTemperatureOptionsVariable.FloatValue;
        BA.temperature.SetValue(whiteTemperature);
    }
    public void WhiteTint() //Variable 21: White Tint
    {
        whiteTint.value = whiteTintOptionsVariable.FloatValue;
        BA.tint.SetValue(whiteTint);
    }
    public void Gamma() //Variable 22: Gamma
    {
        gamma.value = gammaOptionsVariable.FloatValue;
        //LGG.gamma.SetValue(gamma);
        LGG.gamma.Override(new Vector4(0,0,0,gamma.value));
    }
    

    }

  • I can't make it "freeze" even though the Pause menu has the "pause gameplay".

    Uncheck Unfreezes 'Pause' menus? in the properties of your ActionLists.

    For some reason this only works on gameplay lights, not menus.

    This isn't AC-related, but a Canvas's Render Mode needs to be set to Screen Space Camera for it to react to post-processing.

  • I can't believe I've never saw this ever!. Man thanks!!!
    https://imgur.com/a/7IG6ktD
    As for question 2, yes I knew it wasn't AC related in advance, but your words were the trigger I needed to at least look in the right direction. I also knew from following the forum the brightness is not AC related, yet someone can now find a good working method and everything they could need to make it work. Thank you both for helping me add a nice feature to the game.
    Have a good day!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.