-
Notifications
You must be signed in to change notification settings - Fork 11
/
Particles.shader
77 lines (60 loc) · 2.05 KB
/
Particles.shader
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
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Subway/Particles"
{
Properties
{
_ColorLow("Color Slow Speed", Color) = (0, 0, 0.5, 1)
_ColorHigh("Color High Speed", Color) = (1, 0, 0, 1)
_HighSpeedValue("High speed Value", Range(0, 50)) = 25
}
SubShader
{
Pass
{
Blend SrcAlpha one
CGPROGRAM
#pragma target 5.0
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
// Particle's data
struct Particle
{
float2 position;
float2 velocity;
};
// Pixel shader input
struct PS_INPUT
{
float4 position : SV_POSITION;
float4 color : COLOR;
};
// Particle's data, shared with the compute shader
StructuredBuffer<Particle> Particles;
// Properties variables
uniform float4 _ColorLow;
uniform float4 _ColorHigh;
uniform float _HighSpeedValue;
// Vertex shader
PS_INPUT vert(uint vertex_id : SV_VertexID, uint instance_id : SV_InstanceID)
{
PS_INPUT o = (PS_INPUT)0;
// Color
float speed = length(Particles[instance_id].velocity);
float lerpValue = clamp(speed / _HighSpeedValue, 0.0f, 1.0f);
o.color = lerp(_ColorLow, _ColorHigh, lerpValue);
// Position
o.position = UnityObjectToClipPos(float4(Particles[instance_id].position, 0.0f, 1.0f));
return o;
}
// Pixel shader
float4 frag(PS_INPUT i) : COLOR
{
return i.color;
}
ENDCG
}
}
Fallback Off
}