当前位置:网站首页>Method of establishing unity thermodynamic diagram
Method of establishing unity thermodynamic diagram
2022-06-24 14:09:00 【Xiaosheng yunmu】
Unity Method of establishing thermodynamic diagram
Realization effect
The basic idea
The method of generating thermal maps by assigning colors to mesh vertices has been written before . There is one big drawback , Requires a large number of grid points to support , Improved GPU Rendering pressure . So I changed my mind , Directly create and modify the color of picture pixels , In this way, a mesh with only four vertices can be used to generate thermal maps .
Before calculation fbs→97.5

After calculation fbs→96.5

Basically unaffected .
Problems and Solutions
Conversion of world coordinates and pixel coordinates ;
Initialization of pixels and weighted values of pixels ;
Configuration of the relationship between the color of the color block and the influence range ;
Adjustment of resolution and performance .
Conversion of world coordinates and pixel coordinates
Here are two points of attention , The first is the pivot point of the grid , Two is uv The axis of coordinates . The origin of the grid is specified by the model art , But when the world coordinates are converted to pixel coordinates , The origin needs to correspond to , So I want to change the origin of the mesh . There are two ways to change the origin ,1. Let the art modify , Change the origin of the mesh to uv Origin of coordinate system ;2. Add a parent object to the mesh , The position of the parent object is in the uv Coordinate origin . As shown in the figure below


After the origin is aligned , It is only necessary to ask for a proportion .
Vector3 modelSize = gameObject.GetComponent<Collider>().bounds.size;
float MapRatio = heatMapBase.Resolution / modelSize.x;
//heatMapBase.Resolution Is the defined picture pixel resolution .
//MapRatio Is the scale of the transformation between picture coordinates and world coordinates
Initialization of pixels and weighted values of pixels
Before running, the weight of all pixels should be reset to zero . The weighted reference points will affect the surrounding pixels , The scope of influence is related to its own weight , You can also introduce a variable here DisRatio, Used to change the influence range of the weight . When the pixel is weighted , Only values can override small values .
// Each pixel is initialized
List<Vector2> my_Pixels = new List<Vector2>();
List<float> my_Values = new List<float>();
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
Vector2 pixel = new Vector2(x, y);
my_Pixels.Add(pixel);
my_Values.Add(0);
}
}
int allLength = my_Pixels.Count;// So the number of pixels
int pointLength = heatMapInfos.Count;// Number of points of interest in the heat map
int colorLength = heatMapBase.HeatMapInfos.Count;// Color block grade
// Weighted value per pixel
for (int p = 0; p < pointLength; p++)
{
for (int a = 0; a < allLength; a++)
{
float my_Distance = Vector2.Distance(heatMapInfos[p].Pixel* MapRatio, my_Pixels[a]);
float my_MaxDis = heatMapBase.DisRatio * heatMapInfos[p].Amount;
if (my_Distance < my_MaxDis)
{
float value = (1 - (Mathf.Pow(my_Distance, 2) / Mathf.Pow(my_MaxDis, 2))) * heatMapInfos[p].Amount;
if (value > my_Values[a])
{
my_Values[a] = value;
}
}
}
}
Configuration of the relationship between the color of the color block and the influence range
Color selection of color block , A weight , The image resolution and influence range can be dynamically configured . A template is added here to control . For the convenience of pixel color assignment , Specify the weight from large to small .

public class HeatMapBase : ScriptableObject
{
public float DisRatio;// Distance ratio
public float Resolution;// The resolution of the
public List<HeatMapInfo> HeatMapInfos;
[Serializable]
public class HeatMapInfo
{
public float MaxAmount;// Maximum weight
public Color Color;// Color
}
}
Adjustment of resolution and performance
At the beginning of writing , Consider dynamically changing the resolution , The larger the mesh, the greater the resolution . But this undoubtedly increases the consumption of performance . So consider writing the resolution into the configuration table . Instead, a wide range of jagged images appear, as shown in the following figure . I've introduced color Interpolation operation of , Solve the problem perfectly .
No interpolation

Additive interpolation

// Each pixel is assigned a color
for (int i = 0; i < allLength; i++)
{
for (int j = 0; j < colorLength; j++)
{
float my_CurMaxAmount = heatMapBase.HeatMapInfos[j].MaxAmount;
if (my_Values[i] >= my_CurMaxAmount)
{
// The color of the current block
Color my_CurColor = heatMapBase.HeatMapInfos[j].Color;
if (j != 0)
{
float my_UpDiffValue = heatMapBase.HeatMapInfos[j - 1].MaxAmount - my_CurMaxAmount;
Color my_UpColor = heatMapBase.HeatMapInfos[j - 1].Color;
float t = (my_Values[i] - my_CurMaxAmount) / my_UpDiffValue;
texture.SetPixel((int)my_Pixels[i].x, (int)my_Pixels[i].y, Color.Lerp(my_CurColor, my_UpColor, t));
break;
}
else
{
texture.SetPixel((int)my_Pixels[i].x, (int)my_Pixels[i].y, my_CurColor);
break;
}
}
}
}
边栏推荐
- 融云通信“三板斧”,“砍”到了银行的心坎上
- Daily question 8-515 Find the maximum value in each tree row
- Three efficient programming skills of go language
- Docker installation redis
- MySQL复合索引探究
- 如何在物联网低代码平台中进行任务管理?
- Getting to know cloud native security for the first time: the best guarantee in the cloud Era
- Jerry has opened a variety of decoding formats, and the waiting time from card insertion to playback is long [chapter]
- 2022煤矿瓦斯抽采操作证考试题及模拟考试
- Research on MySQL composite index
猜你喜欢

Gatling performance test

The research on the report "market insight into China's database security capabilities, 2022" was officially launched

Tupu software is the digital twin of offshore wind power, striving to be the first

百度地图API绘制点及提示信息

龙蜥开发者说:首次触电,原来你是这样的龙蜥社区? | 第 8 期

Unity 热力图建立方法

【无标题】

The first open source MySQL HTAP database in China will be released soon, and the three highlights will be notified in advance

MIT-6.824-lab4A-2022(万字讲解-代码构建)

Autorf: learn the radiation field of 3D objects from single view (CVPR 2022)
随机推荐
Halcon draw area into picture
Rongyun communication has "hacked" into the heart of the bank
Jerry added an input capture channel [chapter]
Zhiyuan community weekly 86: Gary Marcus talks about three linguistic factors that can be used for reference in large model research; Google puts forward the Wensheng graph model parti which is compar
位于相同的分布式端口组但不同主机上的虚拟机无法互相通信
Three efficient programming skills of go language
杰理之无缝循环播放【篇】
Defoaming
2022 Quality Officer - Equipment direction - post skills (Quality Officer) recurrent training question bank and online simulation examination
2022年煤炭生产经营单位(安全生产管理人员)考试题模拟考试平台操作
[sdx62] wcn685x IPA failure analysis and solution
Jerrys timer0 uses the default pa13 to detect the pulse width [chapter]
PM也要学会每天反省
Research on MySQL composite index
pip uninstall all packages except builtin package
AntD checkbox,限制选中数量
Grendao usage problems
智源社区周刊#86:Gary Marcus谈大模型研究可借鉴的三个语言学因素;谷歌提出媲美Imgen的文生图模型Parti;OpenAI提出视频预训练模型VPT,可玩MC游戏
【从零开始学zabbix】一丶Zabbix的介绍与部署Zabbix
二叉树中最大路径和[处理好任意一颗子树,就处理好了整个树]
