找回密码
 立即注册
查看: 505|回复: 0

unity 温度云图

[复制链接]
发表于 2021-4-1 07:48 | 显示全部楼层 |阅读模式
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);        }    }

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-20 20:30 , Processed in 0.090879 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表