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? 
«13

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!

  • I'm sorry to reopen this old topic, but I am trying to implement the Brightness option into AC Options Menu, and none of the above works for me.

    I am trying to follow the AC Tutorial "Adding a Screen Res Option" combined with this YT Tutorial, the individual steps work but overall I am not having success.

    From the YT tutorial:
    * I am using the Post Processing package.
    * Added Post process layer to Main Camera, selected it as the Trigger, and created and selected a Postprocessing layer.
    * Created empty object Brightness in Postprocessing layer and added Post Processing Volume to it (effect: Global) and created a new Profile where I selected Auto Exposure.
    * I skipped the part where it is made to affect UI as well, for simplicity.
    * Created the Script and added it to the Brightness object.

        using System.Collections;
        using System.Collections.Generic;
        using UnityEngine;
        using UnityEngine.UI;
        using UnityEngine.Rendering.PostProcessing;
    
        public class Brightness : MonoBehaviour
        {
            public Slider brightnessSlider;
    
            public PostProcessProfile brightness;
            public PostProcessLayer layer;
    
            AutoExposure exposure;
            // Start is called before the first frame update
            void Start()
            {
                brightness.TryGetSettings(out exposure);
            }
    
            public void AdjustBrightness(float value)
            {
                if (value != 0)
                {
                    exposure.keyValue.value = value;
                }
                else
                {
                    exposure.keyValue.value = .05f;
                }
            }
        }
    

    The Script gives some public variables to the Brightness object, I managed to add only the Brightness and the Layer, but failed to add the Slider, as I have no idea how to get to its object. I think this might the first issue.
    Didn’t follow the tutorial further after this part.

    From the AC Tutorial
    I have the Brightness Variable (ID: 0). I have my slider in the Options ACMenu ready.

    I skipped the generation of choices (irrelevant for brightness) and the function that sets the correct value of our ScreenResolution integer variable, if it's found to be -1 (so didn't create the SetupOptionsMenu.cs script).

    I then created my own Action from the ActionTemplate.cs, but I am a coding noob, so I assume this is completely wrong:

        using UnityEngine;
        using System.Collections.Generic;
        #if UNITY_EDITOR
        using UnityEditor;
        #endif
    
        namespace AC
        {
    
            [System.Serializable]
            public class ActionBrightnessOption : Action
            {
    
                // Declare properties here
                public override ActionCategory Category { get { return ActionCategory.Engine; }}
                public override string Title { get { return "Brightness"; }}
                public override string Description { get { return "Change Brightness by Martin"; }}
    
    
                // Declare variables here
    
    
                override public float Run()
                {
                    float chosenIndex = GlobalVariables.GetFloatValue(0); // Replace '0' with your own variable's ID number
                    if (chosenIndex >= 0)
                    {
                        KickStarter.playerMenus.RecalculateAll();
                    }
                    return 0f;
                }
    
    
                public override void Skip ()
                {
                    Run ();
                }
    
    
                #if UNITY_EDITOR
    
                public override void ShowGUI ()
                {
                    // Action-specific Inspector GUI code here
                }
    
    
                public override string SetLabel ()
                {
                    // (Optional) Return a string used to describe the specific action's job.
    
                    return string.Empty;
                }
    
                #endif
    
            }
    
        }
    

    In the end I created the action using custom action script (Engine: Brightness) that I added to the Slider element in my Options menu (see the image above).

    In the Editor, the exposure changes nicely when I move slider within the Post Procees Volume component in the Brightness object. And when I move my Brightness slider in the AC Options menu, the global Brightness variable responds accordingly.

    But overall, it is not working, and I am lost.
    I assume something should be done with the public variable in the script from the YT tutorial while the Custom Action Script is lacking some code.
    Please help.

  • The brightnessSlider variable in your script is not referenced in the rest of the code - assigning it will make no difference.

    There's also no need for a custom Action - an updated tutorial that simplifies the coding process can be found here.

    Firstly, go to your BrigtnessSlider element and set its Slider affects to Float Variable. Have it link to a Float variable named e.g. Brightness, and make sure that the variable's Link to property is set to Options Data.

    Next, use this for your Brighness script:

    using UnityEngine;
    using UnityEngine.Rendering.PostProcessing;
    
    public class Brightness : MonoBehaviour
    {
    
        public PostProcessProfile brightness;
        public PostProcessLayer layer;
        public string variableName = "Brightness";
    
        AutoExposure exposure;
    
        void Start()
        {
            brightness.TryGetSettings(out exposure);
        }
    
        public void AdjustBrightness()
        {
            float value = AC.GlobalVariables.GetVariable (variableName).FloatValue;
            if (value != 0)
            {
                exposure.keyValue.value = value;
            }
            else
            {
                exposure.keyValue.value = .05f;
            }
        }
    }
    

    Make this a prefab, attach a Constant ID component, and then check Retain in prefab?, so that its ID is the same each time you place the prefab in a scene.

    It should then just be a case of calling this script's AdjustBrightness function at the following times:

    1. When the game begins - through your Settings Manager's ActionList on begin game asset
    2. After the Slider is changed - through the element's ActionList on change asset

    Each time, run an Object: Send message Action that sends the custom message AdjustBrightness to the Brightness object in the scene. The unique ConstantID number should be recorded and displayed, so that it gets found again when re-opening a scene.

  • Thank you, it works!

    I just have one more question. I would like the brightness to influence UI as well. Specifically, I have a Unity UI prefab-based "menu" whose only purpose is to act as a background to the main menu. it is called MainBackground.

    I followed the YT video and created a duplicate for the NavCam called NavCamUI. I added the post-processing Layer, set depth to 1, and culling mask for UI only (for the original NavCam, I selected everything but UI). I removed of all components except Camera (the basic unity one), Constant ID, and the Postprocessing Layer.

    I moved my MainBackground prefab back to the scene, opened its canvas, set Render Mode - Screen Space Camera, selected the new NavCamUI, and deleted the prefab from the scene again.

    But when I run the game, this menu does not appear at all.

    What am I doing wrong?

  • The prefab's Canvas component will lose the reference to the scene-based NavCamUI object once you remove it from the scene.

    One way around this is to attach a script to the Canvas to assign the NavCamUI at runtime. Something like:

    using UnityEngine;
    
    public class SetNavCamUI : MonoBehaviour
    {
        void OnEnable ()
        {
            GameObject navCamUIOb = GameObject.Find ("NavCamUI");
            GetComponent<Canvas> ().worldCamera = navCamUIOb.GetComponent<Camera> ();
        }
    }
    
  • I added it into the canvas of the menu, but it still does not appear.
    This is how the inspector of the Canvas looks like:


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.