当前位置:网站首页>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;
}
}
}
}
边栏推荐
- SAP Marketing Cloud 功能概述(三)
- OpenHarmony 1
- 项目经理的晋级之路
- Operation of simulated test question bank and simulated test platform for safety production management personnel of fireworks and firecrackers production units in 2022
- The project manager needs to look at six characteristics to build a team
- English writing of Mathematics -- Basic Chinese and English vocabulary (common vocabulary of geometry and trigonometry)
- 杰理之增加一个输入捕捉通道【篇】
- HarmonyOS-3
- Second, the examinee must see | consolidate the preferred question bank to help the examinee make the final dash
- Jericho may have some chips with fast music playing speed [chapter]
猜你喜欢
unity 等高线创建方法
HarmonyOS-3
如何在物联网低代码平台中进行任务管理?
HarmonyOS.2
Home office should be more efficient - automated office perfectly improves fishing time | community essay solicitation
P2pdb white paper
数商云:加强供应商管理,助推航空运输企业与供应商高效协同
OpenHarmony 1
Télétravail: Camping à la maison gadgets de bureau | rédaction communautaire
One click to generate University, major and even admission probability. Is it so magical for AI to fill in volunteer cards?
随机推荐
杰理之在所有模式下打开喊话增加 mic 自动 mute【篇】
Rasa 3. X learning series - it is a great honor to be a source code contributor of Rasa contributors, and to build and share the rasa community with rasa source code contributors all over the world!
Grendao usage problems
Operation of simulated test question bank and simulated test platform for safety production management personnel of fireworks and firecrackers production units in 2022
AntD checkbox,限制选中数量
记录一次Mongotemplate的And和Or的各种套
OpenHarmony 1
Halcon 绘制区域 到图片中
如何解决 Iterative 半监督训练 在 ASR 训练中难以落地的问题丨RTC Dev Meetup
PM should also learn to reflect every day
项目经理的晋级之路
In the era of knowledge economy, it will teach you to do well in knowledge management
杰理之TIMER0 用默认的 PA13 来检测脉宽【篇】
Kotlin asynchronous flow
数学之英文写作——基本中英文词汇(几何与三角的常用词汇)
Three efficient programming skills of go language
2022 Quality Officer - Equipment direction - post skills (Quality Officer) recurrent training question bank and online simulation examination
真正的项目经理强者,都是闭环高手!
HarmonyOS. two
项目经理搭建团队,需要看6个特征