Unity - Standard Emission 自发光测试

记录测试,添加了对烘焙后的Lightmap实时更新颜色,查看下面Code了解
对烘焙后的静态材质的Lightmap,可更新它的Lightmap
先设置Renderer.Material.SetXXX(“xxx”, xxx);
再Renderer.UpdateGIMaterials();

Code

using UnityEngine;

public enum UpdateType
{
    Color2HSV,
    HSV2Color
}

[ExecuteAlways]
public class UpdateGi2 : MonoBehaviour
{
    public Color emissionColor = Color.white;
    [Range(0, 5)]
    public float emissionScale = 2;

    public bool updateColor = true;
    public UpdateType updateType = UpdateType.Color2HSV;

    private Renderer r;
    private Light l;

    public float hv = 0.005f;
    [Range(0,1)]
    public float h = 0;
    [Range(0,1)]
    public float s = 1;
    [Range(0,1)]
    public float v = 1;
    // Start is called before the first frame update
    void Start()
    {
        r = this.gameObject.GetComponent<Renderer>();
        l = this.gameObject.GetComponentInChildren<Light>();
    }

    // Update is called once per frame
    void Update()
    {
        if (updateType == UpdateType.Color2HSV)
        {
            Color.RGBToHSV(emissionColor, out h, out float s, out float v);
        }
        else
        {
            emissionColor = Color.HSVToRGB(h, s, v);
        }
        if (updateColor)
        {
            h = (h + hv) % 1.0f;
            emissionColor = Color.HSVToRGB(h, s, v);
        }
        r.sharedMaterial.SetColor("_EmissionColor", emissionColor);
        r.UpdateGIMaterials();

        if (l)
        {
            l.color = emissionColor;
            l.intensity = emissionScale;
            l.range = emissionScale * 10;
        }
    }
}

Runtime

在这里插入图片描述

Project

链接: https://pan.baidu.com/s/137Q--srldFrWJDk2B_7HYA 提取码: sjbr 复制这段内容后打开百度网盘手机App,操作更方便哦

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值