1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
| Shader "Unlit/ParticelsShader" { Properties { _Level("Level",int) = 0 _DispDir("Displacement Direction",Vector) = (0,0,0) _uVelScale("VelScale",float) = 2 _Speed("Speed",Range(0,1)) = 1 _ShaderStartTime("Shader Start Time",float) = 0 _FinalColor("Final Color",color) = (1,1,1,1) _MainTex ("Texture", 2D) = "white" {} _BurnWidth ("_BurnWidth",Float) = 1 [HDR] _BorderColor ("_BorderColor",Color) = (1,1,1,0) _Noise ("Noise",2D) = "white" {} _BuringValue ("_BuringValue",Float) = 1 [HDR]_FrenelsColor("FrenelsColor",Color) = (1,1,1,1) _FrenelsPower("FrenelsPower",Range(0.1,10)) =1 } SubShader { Tags { "RenderType"="Transparent" "Queue" = "Transparent"} LOD 100 Cull Off Pass { Blend SrcAlpha OneMinusSrcAlpha cull off
CGPROGRAM #pragma vertex vert #pragma fragment frag #pragma geometry geom
#include "UnityCG.cginc" uniform int _Level; uniform float3 _DispDir; uniform float _uVelScale; uniform float _Speed; uniform float _ShaderStartTime; uniform fixed4 _FinalColor;
float3 V0,V1,V2; float3 CG; float unityTime;
struct appdata { float4 vertex : POSITION; float2 uv1 : TEXCOORD0; float2 uv2 : TEXCOORD1; float3 normal : NORMAL; };
struct g2f{ float4 vertex : SV_POSITION; fixed4 color: COLOR; };
struct v2g { float4 vertex : SV_POSITION; fixed4 color : COLOR; float3 normal : NORMAL; float2 uv : TEXCOORD1; float4 worldPostion : TEXCOORD2; };
struct geometryOutput { float4 pos : SV_POSITION; float2 uv : TEXCOORD0; float3 normal : NORMAL; fixed4 color : COLOR; float3 localPos : TEXCOORD1; float4 worldPostion : TEXCOORD2; };
sampler2D _MainTex; float4 _MainTex_ST; sampler2D _Noise; float4 _Noise_ST; float _BurnWidth; float4 _BorderColor; float _BuringValue; float4 _FrenelsColor; float _FrenelsPower;
v2g vert (appdata v) { v2g o; o.vertex = v.vertex; o.normal = UnityObjectToWorldNormal(v.normal); o.uv = TRANSFORM_TEX(v.uv2, _MainTex); o.worldPostion = mul(unity_ObjectToWorld, v.vertex); return o; }
float3 randto3D(float3 seed) { float3 f = sin(float3(dot(seed, float3(127.1, 337.1, 256.2)), dot(seed, float3(129.8, 782.3, 535.3)) , dot(seed, float3(269.5, 183.3, 337.1)))); f = -1 + 2 * frac(f * 43785.5453123); return f; }
float rand(float3 seed) { float f = sin(dot(seed, float3(127.1, 337.1, 256.2))); f = -1 + 2 * frac(f * 43785.5453123); return f; }
[maxvertexcount(3)] void geom(triangle v2g IN[3],inout TriangleStream<geometryOutput> OutputStream) { float3 center = (IN[0].vertex + IN[1].vertex + IN[2].vertex) / 3; float offset = center.z * 5; float ss_offset = lerp(0, 1, offset); float3 n0 = IN[0].normal; float3 n1 = IN[1].normal; float3 n2 = IN[2].normal; float disLv = clamp((abs(sin(0.1*_Time.y)+0.1) - ss_offset),0,1); float3 translation = (n0 + n1 + n2) / 3 * disLv *_uVelScale;
for(uint i=0;i<3;i++){ geometryOutput o; UNITY_INITIALIZE_OUTPUT(geometryOutput,o); v2g vet = IN[i]; float3 v = vet.vertex + translation; o.pos = UnityObjectToClipPos(v); o.uv = vet.uv; o.localPos = v; o.color.a = clamp(1 - distance(v,center)*20,0,1); o.worldPostion = vet.worldPostion; o.normal = vet.normal; OutputStream.Append(o); } }
fixed4 frag (geometryOutput i) : SV_Target { fixed4 col = tex2D(_MainTex, i.uv); float height = i.localPos.z + 0.01;
float noise = tex2D(_Noise,i.uv).r; noise += 0.3;
_BuringValue = abs(sin(0.1*_Time.y));
float burn = _BuringValue * noise/3; float width = burn + _BurnWidth/10;
clip(height - burn); float colLv = step(height,burn) + step(height,width);
col = lerp(col,col*_BorderColor,colLv);
float3 viewDirection = normalize(_WorldSpaceCameraPos.xyz - i.worldPostion.xyz); float3 emissive = (_FrenelsColor.rgb*pow(1.0-max(0,dot(i.normal, viewDirection)),_FrenelsPower))+col.rgb; return fixed4(emissive,i.color.w); } ENDCG } } }
|