其他分享
首页 > 其他分享> > unity HDRcolor面板的intensity 获取和设置

unity HDRcolor面板的intensity 获取和设置

作者:互联网

获取


 
    private void Start()
    {
        Color32 color32;
        float exp;
        DecomposeHdrColor(color, out color32, out exp);
        Debug.Log(exp);
    }
 
    private const byte k_MaxByteForOverexposedColor = 191;
    public static void DecomposeHdrColor(Color linearColorHdr, out Color32 baseLinearColor, out float exposure)
    {
        baseLinearColor = linearColorHdr;
        var maxColorComponent = linearColorHdr.maxColorComponent;
        // replicate Photoshops's decomposition behaviour
        if (maxColorComponent == 0f || maxColorComponent <= 1f && maxColorComponent >= 1 / 255f)
        {
            exposure = 0f;
            baseLinearColor.r = (byte)Mathf.RoundToInt(linearColorHdr.r * 255f);
            baseLinearColor.g = (byte)Mathf.RoundToInt(linearColorHdr.g * 255f);
            baseLinearColor.b = (byte)Mathf.RoundToInt(linearColorHdr.b * 255f);
        }
        else
        {
            // calibrate exposure to the max float color component
            var scaleFactor = k_MaxByteForOverexposedColor / maxColorComponent;
            exposure = Mathf.Log(255f / scaleFactor) / Mathf.Log(2f);
            // maintain maximal integrity of byte values to prevent off-by-one errors when scaling up a color one component at a time
            baseLinearColor.r = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * linearColorHdr.r));
            baseLinearColor.g = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * linearColorHdr.g));
            baseLinearColor.b = Math.Min(k_MaxByteForOverexposedColor, (byte)Mathf.CeilToInt(scaleFactor * linearColorHdr.b));
        }
    }

设置 

  public string property;
    public MeshRenderer meshRenderer;
    private Material material;
 
    [Range(0f,10f)]
    public float intensity;
    private Color c;
    private void Start()
    {
             material = meshRenderer.material;
        c= material.GetColor(property);
    }
    void Update()
    {
        float factor = Mathf.Pow(2, intensity);
        Color color = new Color(c.r* factor, c.g* factor, c.b* factor);
        material.SetColor(property, color);
}

标签:baseLinearColor,linearColorHdr,color,float,Mathf,unity,intensity,byte,HDRcolor
来源: https://blog.csdn.net/qq_38655924/article/details/121516468