2024年3月15日发(作者:)
希望对大家有所帮助,多谢您的浏览!
基本原理是给定平面上的几个点的位置和该点的温度信息,然后通过距离比的关系来算
出平面上任意点的温度数值,再通过颜色反映出来。
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Shader "Custom/TemperatureField" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_Point1("Temperature1",Range(0,100)) = 50
_Point2("Temperature2",Range(0,100)) = 50
_Point3("Temperature3",Range(0,100)) = 50
_Point4("Temperature4",Range(0,100)) = 50
}
SubShader {
AlphaTest Greater 0.1
pass
{
CGPROGRAM
// Upgrade NOTE: excluded shader from DX11, Xbox360, OpenGL ES 2.0
because it uses unsized arrays
15.
16.
17.
18.
19.
20.
#pragma exclude_renderers d3d11 xbox360 gles
#pragma target 3.0
#pragma vertex vert
#pragma fragment frag
#include ""
希望对大家有所帮助,多谢您的浏览!
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
sampler2D _MainTex;
float4 _MainTex_ST;
float _Point1;
float _Point2;
float _Point3;
float _Point4;
bool computer = false;
struct v2f {
float4 pos:SV_POSITION;
float2 uv:TEXCOORD0;
};
v2f vert(appdata_base v)
{
v2f o;
=mul(UNITY_MATRIX_MVP,);
= TRANSFORM_TEX(rd,_MainTex);
return o;
}
float computerTemperature(float2 uv)
希望对大家有所帮助,多谢您的浏览!
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
{
int plength = 3;
float _midPointX[3] = {0.2,0.8,0.5};
float _midPointY[3] = {0.7,0.9,0.4};
float _midPointT[3] = {10,20,90};
float d1 = sqrt(uv.x*uv.x+uv.y*uv.y);
float d2 = sqrt((1-uv.x)*(1-uv.x)+(1-uv.y)*(1-uv.y));
float d3 = sqrt(uv.x*uv.x+(1-uv.y)*(1-uv.y));
float d4 = sqrt((1-uv.x)*(1-uv.x)+uv.y*uv.y);
float m = 1/d1+1/d2+1/d3+1/d4;
float n = 1/d1*_Point1+1/d2*_Point4+1/d3*_Point3+1/d4*_Point2;
for (int i = 0 ; i < plength ; i++)
{
float dp =
sqrt((uv.x-_midPointX)*(uv.x-_midPointX)+(uv.y-_midPointY)*(uv.y-_midPointY))
;
62.
63.
64.
65.
66.
67.
m = m + 1/dp;
n = n + 1/dp*_midPointT;
}
希望对大家有所帮助,多谢您的浏览!
68.
return n/m;
希望对大家有所帮助,多谢您的浏览!
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
}
float4 frag(v2f i):COLOR
{
float4 outp;
float4 texCol = tex2D(_MainTex,);
float temp = computerTemperature();
//float temp = computeArray();
//图像区域,判定设置为颜色的A > 0.5,输出为材质颜色+光亮值
if(texCol.w>0.5)
{
if(temp >= 60)
outp = float4(1,0,0,1)*(temp-60)/40+float4(1,1,0,1)*(1-(temp-60)/40);
else if(temp >= 30)
outp = float4(1,1,0,1)*(temp-30)/30+float4(0,1,0,1)*(1-(temp-30)/30);
else
outp = float4(0,1,0,1)*(temp)/30+float4(0,0,1,1)*(1-(temp)/30);
}
else
outp = float4(0,0,0,0);
希望对大家有所帮助,多谢您的浏览!
94.
95.
96.
97.
98.
99.
return outp;
}
ENDCG
}
}
100.
FallBack "Diffuse"
101.
}
复制代码
其中_Point1到4是平面4个顶点上的温度值 _midPointX,_midPointY,_midPointT
给出了平面内三个点的位置和温度值,实际应用中可以相应修改和增删
文章来着【狗刨学习网】
希望对大家有所帮助,多谢您的浏览!
希望对大家有所帮助,多谢您的浏览!
(注:可编辑下载,若有不当之处,请指正,谢谢!)


发布评论