unity 温度云图
image.pngimage.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; public List<Transform> pointsList = new List<Transform>(); 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.TransformDirection(Vector3.up); if (Physics.Linecast(pointsList.position+ down*5, pointsList.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.TransformDirection(Vector3.up); Gizmos.DrawLine(pointsList.position + down * 5, pointsList.position - down * 5); } }
页:
[1]