Search Unity

Material SetFloat issues with HDRP/Lit

Discussion in 'High Definition Render Pipeline' started by KHam256, Jan 12, 2022.

  1. KHam256

    KHam256

    Joined:
    Sep 17, 2016
    Posts:
    19
    For context, I'm randomizing these 3 HDRP/Lit shader values

    Code (CSharp):
    1. _glassMaterial.SetFloat("_Smoothness",
    2.             Mathf.Lerp(0.75f, 0.95f, (float)_rnd.NextDouble()));
    3.  
    4.         _glassMaterial.SetFloat("_Ior",
    5.             Mathf.Lerp(1.01f, 1.05f, (float)_rnd.NextDouble()));
    6.  
    7.         _glassMaterial.SetFloat("_NormalScale",
    8.             Mathf.Lerp(0f, 3f, (float)_rnd.NextDouble()));
    I tested this code in Update() and got some strange results.
    NormalScale seems to be setting close to within my set range, hitting 3.3s at highest.
    Smoothness is changing but its setting to anything between 0 and 1. Mostly they're set to 0.
    Ior has never resulted a value other than 0.

    What am I missing?
     
    Last edited: Jan 12, 2022
  2. Bambelle

    Bambelle

    Joined:
    Mar 3, 2016
    Posts:
    2
    have you tried printing the values before setting them on the material ? Maybe the issue comes from the random number generator