您当前的位置: 首页 >  ar

Jave.Lin

暂无认证

  • 6浏览

    0关注

    704博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity - Standard Emission 自发光测试

Jave.Lin 发布时间:2019-06-17 23:36:10 ,浏览量:6

记录测试,添加了对烘焙后的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();
        l = this.gameObject.GetComponentInChildren();
    }

    // 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,操作更方便哦

关注
打赏
1664331872
查看更多评论
立即登录/注册

微信扫码登录

0.3716s