Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct here to familiarize yourself with the rules and how to post constructively.

  2. Unity 2022.1 is now available as the latest Tech release.
    Dismiss Notice
  3. Improve your project's performance with our new guide on profiling in Unity.
    Dismiss Notice

HDRP Can't find aperture through scripting

Discussion in 'Graphics Experimental Previews' started by Admiral-Skye, Jul 5, 2019.

  1. Admiral-Skye

    Admiral-Skye

    Joined:
    Feb 10, 2013
    Posts:
    32
    I am trying to modify a camera's aperture settings through scripting but it doesn't seem like they are available. I can find all the other camera physical settings like Focal Length, Shutter Speed, etc. but none of the aperture ones. Are those just not available for scripting for some reason?
     
  2. jwheeler_unity

    jwheeler_unity

    Unity Technologies

    Joined:
    Nov 2, 2018
    Posts:
    6
    Took me a while too. Get the HDAdditionalCameraData component from the camera and you'll find it there.

    camera.GetComponent<HDAdditionalCameraData>().physicalParameters.aperture = myVal;
     
    BradyIrv likes this.
  3. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    155
    @jwheeler_unity How about accessing Shutter speed and ISO? would you know where to find these parameters and what they are called? Thanks.

    @Admiral-Skye Could you let me know where to find and what the shutter speed and ISO parameters are called?
    As a non coder, i'm finding it extremely hard to create a simple canvas/UI and sliders to manipulate these values as they arent exposed in the Camera block dynamic floats.

    After finding this thread by you, I was able to ask the author of the OSCsimpl plugin to help me set aperture ( https://forum.unity.com/threads/released-osc-simpl.382244/page-2#post-5753917)
     
  4. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,487
    @Dirrogate you first access the HDAdditionalCameraData, then get the physical cam parameters, and change that HDPhysicalCamera object's parameters.
     
    Dirrogate likes this.
  5. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    155
    Ok, I Found it
    for some reason I had to change float to Int for ISO (i'm no coder so had to google the error that came up initially and then add (int) at the end to value)

    HDAdditionalCameraData data = GetComponent<HDAdditionalCameraData>();
    _oscIn.MapFloat(_isoAddress, (float value) => data.physicalParameters.iso = (int)value);

    although, it lists ISO as a Float here:
    https://docs.unity3d.com/Packages/c...dering.HDPipeline.HDAdditionalCameraData.html

    found shutterSpeed too.

    Now If only there's a way to access DOF in the post processing Volume.
    Really, the team that designed the Unity Physical Camera, should have had a cinematographer as part of advisory
     
  6. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    155
    Thanks Olmi. I just did. I think we typed at the same time :)

    Would you know about how to access the DoF focus distance in the Volume Override settings?
    Regards.
     
  7. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,487
    Well for DOF you would have to access the post processing volume? Then adjust those settings there.
     
    Dirrogate likes this.
  8. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    155
    I'll try! (zero coding knowledge here)
     
  9. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,487
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.HighDefinition;
    4.  
    5. public class AccessVolumeOverrideDof : MonoBehaviour
    6. {
    7.     DepthOfField depthOfField;
    8.  
    9.     void Start()
    10.     {
    11.         Volume volume = GetComponent<Volume>();
    12.         DepthOfField tempDof;
    13.  
    14.         if (volume.profile.TryGet<DepthOfField>(out tempDof))
    15.         {
    16.             depthOfField = tempDof;
    17.         }
    18.  
    19.         depthOfField.focusDistance.value = 42f;
    20.     }
    21. }
    EDIT: so, you just get first the Volume component, then that Depth of Field Volume override, and there you have those parameters that you can adjust. This has already been posted a few times here on the forums but those replies are not always easy to find.

    P.S. If I remember correctly, there was something weird going on with those DoF's but I've managed to change all settings via code as I use that in one of my prototypes... Yeah I'm not that much of coder either but this is more of a documentation and API issue... Majority of HDRP docs are just a printout of the api features, a bit like saying a cat is a cat, x is x, but not much explanation and even less instructions how to use them correctly etc.
     
    Last edited: Apr 27, 2020
    Dirrogate likes this.
  10. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    155
    Thanks so much!
    I'll report back in this thread later this evening if all works.
    I'm having an uphill task trying to build from scratch a Vcam (virtual cinematography) based on Unity.
     
  11. Dirrogate

    Dirrogate

    Joined:
    Feb 18, 2014
    Posts:
    155
    @Olmi Wow. It worked.
    Just tried my hand at modifying the script u sent, to work with OSCsimpl (from the asset store) that maps TouchOsc (an app for android/ios) and it worked.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Rendering;
    3. using UnityEngine.Rendering.HighDefinition;
    4.  
    5. public class VolumeOverrideDof : MonoBehaviour
    6. {
    7.     DepthOfField depthOfField;
    8.  
    9.     [SerializeField] OscIn _oscIn = null;
    10.     [SerializeField] string _dofAddress = "/oscControl/dof";
    11.  
    12.     void Awake()
    13.     {
    14.         Volume volume = GetComponent<Volume>();
    15.         DepthOfField tempDof;
    16.  
    17.         if (volume.profile.TryGet<DepthOfField>(out tempDof))
    18.         {
    19.             depthOfField = tempDof;
    20.         }
    21.         _oscIn.MapFloat(_dofAddress, (float value) => depthOfField.focusDistance.value = value);
    22.     }
    23. }
    24.  
    Thanks so much!
     
    Olmi likes this.
unityunity