以下内容后来又重新制作了,详情请见:
https://blog.csdn.net/qq_34593121/article/details/103111299
看到网上有较多人问毒圈怎么做,于是捣鼓了一下。
先看看最终效果:(下面是动画的截图)
主要功能:毒圈颜色可调、毒圈背景底色可调、动画速度可调、透明度范围可调(可非线性、越高越透明)。
制作步骤:
1、在unity场景中设置一平面、一圆柱体(用3dmax做个没上下底面的最好,不过要注意uv)![](https://img-blog.csdnimg.cn/2018112313433071.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzM0NTkzMTIx,size_16,color_FFFFFF,t_70)
2、给圆柱体新建一个材质,并将下面的shader赋给材质球。
shader代码:
Shader "Mshader/CircleOfPoison" {
Properties{
[HDR]_TintColor("Tint Color", Color) = (0.5,0.5,0.5,1)
_BackColor("Back Color", Color) = (0,1,0,0)//背景底色
_TimeScale("Time Scale", Vector) = (1,1,1,1)
_MainTex("Noise Texture", 2D) = "white" {}
_BorderScale("Border Scale (XY) Offset (Z)", Vector) = (0.5,0.05,1,0)
_ahRang("ahRang",Range(0,4)) = 1.5//毒圈整体高度
_ahValue("ahValue",Range(-1,1)) = 0//毒圈整体透明度
}
Category{
Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
Lighting Off
ZWrite Off
Offset -1, -1
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
sampler2D _MainTex;
float4 _TintColor;
float4 _TimeScale;
float4 _BorderScale;
float4 _BackColor;
struct appdata_t {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float3 normal : NORMAL;
};
struct v2f {
float4 vertex : POSITION;
fixed4 color : COLOR;
float2 texcoord : TEXCOORD0;
float3 normal : NORMAL;
float3 worldPosScaled : TEXCOORD1;
float2 uv : TEXCOORD2;
};
float4 _MainTex_ST;
float _ahRang;
float _ahValue;
v2f vert(appdata_t v)
{
v2f o;
v.vertex.xyz += v.normal / 100 * _BorderScale.z;
o.vertex = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
o.worldPosScaled = v.vertex.xyz * _MainTex_ST.x;
o.normal = abs(v.normal);
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
return o;
}
half2 tex2DTriplanar(sampler2D tex, float2 offset, float3 worldPos, float3 normal)
{
half2 yDiff = tex2D(tex, worldPos.xz + offset);
half2 xDiff = tex2D(tex, worldPos.zy + offset);
half2 zDiff = tex2D(tex, worldPos.xy + offset);
normal = normal / (normal.x + normal.y + normal.z);
return xDiff * normal.x + yDiff * normal.y + zDiff * normal.z;
}
half4 frag(v2f i) : COLOR
{
half2 mask = tex2DTriplanar(_MainTex, _Time.xx * _TimeScale.xy, i.worldPosScaled, i.normal);
half2 tex = tex2DTriplanar(_MainTex, mask + _Time.xx * _TimeScale.zw, i.worldPosScaled, i.normal);
float4 res = 0;
res.r = step(tex.r, _BorderScale.x);
res.r -= step(tex.r, _BorderScale.x - _BorderScale.y);
res.r *= tex.g;
res = i.color * res.r * _TintColor+float4(normalize(_BackColor.rgb),0);//加上底色的混合色
res.a = saturate(res.a + (1 - _ahRang *sqrt(i.uv.y)) + _ahValue);//透明控制
//res.a = saturate(res.a);
return res;
}
ENDCG
}
}
}
}
3、上述shader需要一张噪声图,将下面的图片下载后复制到unity的Assets 随便什么文件夹下,然后拖到shader的控制面板相应位置(如下图)
图片设置(仅参考)
HDR的设置如下
扫描二维码关注公众号,回复:
9963272 查看本文章
![](/qrcode.jpg)