TA-Shader-文件 制作热点效果 Heat maps
发布于
2017-10-25
1605
14
TA资源类型
TA资源类型: 算法思路 
shader资源类型: 其它 
适用引擎: 其它 
资源介绍: -

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

x
Heatmaps in Unity 5.4+
Step1:The shader
Shader "Example/Heatmap" {
    Properties {
        _HeatTex ("Texture", 2D) = "white" {}
    }
    SubShader {
        Tags {"Queue"="Transparent"}
        Blend SrcAlpha OneMinusSrcAlpha // Alpha blend

        Pass {
            CGPROGRAM
            #pragma vertex vert            
            #pragma fragment frag

            struct vertInput {
                float4 pos : POSITION;
            };  

            struct vertOutput {
                float4 pos : POSITION;
                fixed3 worldPos : TEXCOORD1;
            };

            vertOutput vert(vertInput input) {
                vertOutput o;
                o.pos = mul(UNITY_MATRIX_MVP, input.pos);
                o.worldPos = mul(_Object2World, input.pos).xyz;
                return o;
            }

            uniform int _Points_Length = 0;     //Array Length
            uniform float3 _Points [20];        // (x, y, z) = position
            uniform float2 _Properties [20];    // x = radius, y = intensity

            sampler2D _HeatTex;

            half4 frag(vertOutput output) : COLOR {
                // Loops over all the points
                half h = 0;
                for (int i = 0; i < _Points_Length; i ++)
                {
                    // Calculates the contribution of each point
                    half di = distance(output.worldPos, _Points.xyz);

                    half ri = _Properties.x;
                    half hi = 1 - saturate(di / ri);

                    h += hi * _Properties.y;
                }

                // Converts (0-1) according to the heat texture
                h = saturate(h);
                half4 color = tex2D(_HeatTex, fixed2(h, 0.5));
                return color;
            }
            ENDCG
        }
    }
    Fallback "Diffuse"
}

Setp2: The C# code
using UnityEngine;
using System.Collections;

public class Heatmap1 : MonoBehaviour
{
    public Vector4[] positions;
    public Vector4[] properties;

    public Material material;

    public int count = 50;

    void Start ()
    {
        positions = new Vector4[count];
        properties = new Vector4[count];

        for (int i = 0; i < positions.Length; i++)
        {
            positions = new Vector4(Random.Range(-0.4f, +0.4f), Random.Range(-0.4f, +0.4f), 0, 0);
            properties = new Vector4(Random.Range(0f, 0.25f), Random.Range(-0.25f, 1f), 0, 0);
        }
    }

    void Update()
    {
        //
        for (int i = 0; i < positions.Length; i++)
            positions += new Vector4(Random.Range(-0.1f,+0.1f), Random.Range(-0.1f, +0.1f), 0, 0) * Time.deltaTime;

        //[Propagates value to the shader]
        material.SetInt("_Points_Length", count);
        material.SetVectorArray("_Points", positions);
        material.SetVectorArray("_Properties", properties);
    }
}

Setp3: The Assets
The “_HeatTex” you can use like the following texture:
718885ad485cc236cd.png

[/sell]

制作热点效果 Heat maps:
242635ad4860d9a40d.png
参与人数 4 元素币 +10 活跃度 +26
还没有设置签名!您可以在此展示你的链接,或者个人主页!

使用道具 举报 登录

回复 <
张前进  发表于 2018-10-18 10:10:56  
2#
想要成大触,天天上元素!
回复 收起回复
使用道具
An.w  发表于 2018-10-18 10:30:28  
3#
感谢分享
回复 收起回复
使用道具
星舰与太阳  发表于 2018-11-12 09:41:44  
4#
回复 收起回复
使用道具
浪荡丶  发表于 2018-11-12 09:46:42  
5#
首发必需微元素,荣耀加身装备酷!
回复 收起回复
使用道具
wolfram  发表于 2018-11-12 11:47:22  
6#

楼主技术大神啊
回复 收起回复
使用道具
qq_叫我小明_LUo  发表于 2018-11-18 16:22:00  
7#
666666666666
回复 收起回复
使用道具
LJHhahaha  发表于 2018-11-19 16:29:23  
8#
好想买。没钱
回复 收起回复
使用道具
dsglxq  发表于 2018-11-20 14:45:16  
9#
666666
回复 收起回复
使用道具
光舞  发表于 2018-11-21 09:15:17  
10#
元素帖子强,满满正能量!
回复 收起回复
使用道具
不会变的奇居子  发表于 2018-11-21 10:23:54  
11#
谢谢分享!
回复 收起回复
使用道具
Shiva希瓦  发表于 2018-11-22 08:54:47  
12#
回复 收起回复
使用道具
玩嘢啊  发表于 2018-11-22 09:56:17  
13#
非常好 大爱!!!
回复 收起回复
使用道具
1991072687  发表于 2018-11-22 10:11:51  
14#
谢谢老大分享
回复 收起回复
使用道具
wuming  发表于 2019-1-30 08:37:26  
15#
回复 收起回复
使用道具

快来发表你宝贵的意见吧!

Taffy 实名

通过了实名认证的内容创造者

  

主题
2
精华
0
超神
0
扩散
0
微金
838
智慧
0
余额
1
在线时间
273 小时

短杖 学徒法袍 长枪 火元素

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