Search Unity

I can access directional light via script but not volume

Discussion in 'High Definition Render Pipeline' started by Ne0mega, Feb 10, 2021.

  1. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755
    I need a little tip on how to get in to the Volume attribute. I called HDAdditionalLight data and was able to mess around with all sorts of things, but I can;t really figure out how to do the same for the volume component or get into the overrides.
     
  2. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    765
    In the documentation, you can find an examples how to retrieve an override reference.
    From there, you can modify variables easily
     
    Ne0mega likes this.
  3. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755
    I crashed out after a 36 hour coding bender within 5 minutes of posting this question. Thanks. This will be a great way to start my day, and here's to another 36 hour bender, this time, playing with volume settings. Cheers.

    Gotta tell it it's being overridden, first. Can't just waltz in and start changing things.
     
    chap-unity likes this.
  4. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755
    So... ....you said "easily" and it isn't so "easily".

    I want to use update to change both fog color and base height with a ping pong motion. I thought maybe I could change color, nope it doesn't use color, it uses a Rendering.ColorParameter. IN fact, I cant seem to find a way to get to the fog without tryGetting it. And I dont think I want to do a tryGet every frame and update the fog every frame... and I dont want to do a full volume fade

    Can I update variables in the volume component every frame?
     
  5. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    765
    The idea is surely NOT to 'TryGetting' the fog override everyframe, but you can get it in the start function and store it in a variable and then update your parameter in the update function like this :

    Code (CSharp):
    1.  
    2. public class FogUpdate : MonoBehaviour
    3. {
    4.     Fog fog = null;
    5.     // Start is called before the first frame update
    6.     void Start()
    7.     {
    8.         Volume volume = this.GetComponent<Volume>();
    9.         Fog tmp;
    10.         if(volume.profile.TryGet<Fog>( out tmp ))
    11.         {
    12.             fog = tmp;
    13.         }
    14.        
    15.         fog.baseHeight.overrideState = true;
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         fog.baseHeight.value = Mathf.Abs(Mathf.Sin(Time.realtimeSinceStartup));
    22.     }
    23. }
    24.  
     
    Ne0mega likes this.
  6. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    755

    TY. I am not familiar with the (out var tmp) process. I only use it so far to do a raycast. I am guessing it is handy with other physics as well. I'll figure it out now.

    In the meantime, Ive done more HDRP reading, and I had given up on figuring out how to change fog, except I never give up on an idea once it is there. So I learned about frame buffering and being able to call the z buffer to manipulate it and add as post process in the SRP.... frame buffer adding a Blit, and a lot of things started to click on HDRP and the entire SRP goal and endgame, and my fog of war, as it is a janky tile system ATM.

    It sure is messy right now, though.