【Unity Shaders】三维 热力图 免费下载

18 篇文章 1 订阅

今天更新一个大众功能的 shader 热力图,相信很多小伙伴会有这个需求,先来个效果图

包含了二维热力图和三维热力图,背景图片混合,热力透明度等。

微信号:ITComputerGraph

更多精彩内容,关注公众号《IT木子李

 

热力图的思路:先获取热力点,然后有热点的影响半径,根据半径可算出周围象素的热图情况

v2f vert(a2v input)
{
	v2f		o;
    half3	worldPos	= mul(unity_ObjectToWorld,input.pos).xyz;
    half	heat		= 0;
	for( int i = 0 ; i < _FactorCount;i++ )
	{
		half	dis			=	distance(worldPos, _Factors[i].xyz);
		float	radius		=	_FactorsProperties.x;
		float	intensity	=	_FactorsProperties.y;
		half	ratio		=	1 - saturate(dis / radius);
				heat		+=	intensity * ratio;
	}	
	o.pos		=	UnityObjectToClipPos(input.pos + half3(0,heat*_Height,0));
	o.worldPos	=	mul(unity_ObjectToWorld,input.pos).xyz;
	o.uv		=	input.uv * _MainTex_ST.xy + _MainTex_ST.zw;
	return	o;
}
fixed4 frag(v2f input):COLOR
{
	half heat = 0;
	for( int i = 0 ; i < _FactorCount;i++ )
	{
		half	dis			=	distance(input.worldPos, _Factors[i].xyz);
		float	radius		=	_FactorsProperties.x;
		float	intensity	=	_FactorsProperties.y;
		half	ratio		=	1 - saturate(dis / radius);
				heat		+=	intensity * ratio;
				heat		=	clamp(heat, 0.05, 0.95);
	}
	half4	color	=	tex2D(_HeatMapTex, fixed2(heat, 0.5));
	half	aplha	=	(heat - 0.05) / 0.9;
			color.a =	pow( aplha * _Alpha, _AlphaStep);
	half4	tex		=	tex2D(_MainTex, input.uv);
	if (_TexVisible == 0)
	{
		return	color;
	}
	else
	{
		return	fixed4(color.rgb * color.a + tex.rgb * (1 - color.a), tex.a);
	}
	
}

 以上是顶点着色器和片元着色器代码。

 

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linda012518

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值