|
image.png
image.png
借鉴:https://blog.csdn.net/x100568/article/details/51219023
https://zhuanlan.zhihu.com/p/158039963
我是个shader新手,门都没入那种,项目需要必须要搞个温度云图。我项目的需求是:我这个是固定点位产生温度变化。
这个shader是通过UV计算的。所以第一步,是需要把世界坐标转换成uv坐标。额,本人对shader一敲不通,只能用一个笨办法。发射射线返回一个uv坐标。
shader的话可以通过上面的地址复制一份,但注意需要自己手动修改一番
C# 代码
public Transform plane; public Material currentMaterial; [Header("热力图点位")] public List<Transform> pointsList = new List<Transform>(); [Header("温度")] public List<float> temperaturesList = new List<float>(); public List<Vector4> pointsVector2List = new List<Vector4>(); private void Start() { currentMaterial = plane.GetComponent<MeshRenderer>().material; for (int i = 0; i < pointsList.Count; i++) { temperaturesList.Add(Random.Range(22,26)); } } private void Update() { if (Input.GetKeyDown(KeyCode.Space)) { SetHeatmap(); } if (Input.GetKeyDown(KeyCode.A)) { pointsVector2List.Clear(); currentMaterial.SetInt("_Points_Length", 0); } } RaycastHit hit; private void SetHeatmap() { pointsVector2List.Clear(); for (int i = 0; i < pointsList.Count; i++) { int index = i; Vector3 down = pointsList[index].TransformDirection(Vector3.up); if (Physics.Linecast(pointsList[index].position+ down*5, pointsList[index].position - down * 5, out hit)) { Vector3 tempPos = hit.textureCoord; pointsVector2List.Add(tempPos); Debug.Log(":" + tempPos); } } currentMaterial.SetFloatArray("_temperatures", temperaturesList); if(pointsVector2List.Count>0) currentMaterial.SetVectorArray("_Points", pointsVector2List.ToArray()); currentMaterial.SetInt("_Points_Length", pointsList.Count); //设置数量 } private void OnDrawGizmos() { Gizmos.color = Color.red; for (int i = 0; i < pointsList.Count; i++) { int index = i; Vector3 down = pointsList[index].TransformDirection(Vector3.up); Gizmos.DrawLine(pointsList[index].position + down * 5, pointsList[index].position - down * 5); } } |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|