forked from przemyslawzaworski/Unity3D-CG-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticleCollision.shader
More file actions
37 lines (33 loc) · 928 Bytes
/
ParticleCollision.shader
File metadata and controls
37 lines (33 loc) · 928 Bytes
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
Shader "Particle Collision"
{
SubShader
{
Pass
{
CGPROGRAM
#pragma vertex SetVertexShader
#pragma fragment SetPixelShader
#pragma target 5.0
uniform StructuredBuffer<float4> buffer;
uniform int resolution;
uniform int amount;
void SetVertexShader (inout float4 vertex:POSITION, inout float2 uv:TEXCOORD0)
{
vertex = UnityObjectToClipPos(vertex);
}
void SetPixelShader (float4 vertex:POSITION, float2 uv:TEXCOORD0, out float4 color:SV_TARGET)
{
float2 texel = float2(round(uv.x*resolution),round(uv.y*resolution));
color = 0..xxxx;
for (int i=0; i<amount; i++)
{
float4 k = buffer[resolution+i];
float s = distance(texel, (buffer[i]*resolution).xy);
float a = 1.0 - saturate(s - k.w * resolution + 0.5);
color = lerp(color, float4(k.rgb, 1.0), a);
}
}
ENDCG
}
}
}