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);
}

上一篇:C#中常用的公式总结


下一篇:python实现最小二乘拟合/平方逼近问题