记录测试,添加了对烘焙后的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,操作更方便哦