Skip to content

Instantly share code, notes, and snippets.

@ufna
Created January 21, 2020 12:36
Show Gist options
  • Save ufna/1529f4acf47f8c2358ef1fa8590b0f22 to your computer and use it in GitHub Desktop.
Save ufna/1529f4acf47f8c2358ef1fa8590b0f22 to your computer and use it in GitHub Desktop.
Plexus Particles for Unreal Engine 4 (based on work of eclmist)
struct Functions
{
float distLine(float2 p, float2 a, float2 b) {
float2 ap = p - a;
float2 ab = b - a;
float aDotB = clamp(dot(ap, ab) / dot(ab, ab), 0.0, 1.0);
return length(ap - ab * aDotB);
}
float drawLine(float2 uv, float2 a, float2 b) {
float lineF = smoothstep(0.014, 0.01, distLine(uv, a, b));
float dist = length(b-a);
return lineF * (smoothstep(1.3, 0.8, dist) * 0.5 + smoothstep(0.04, 0.03, abs(dist - 0.75)));
}
float n21(float2 i) {
i += frac(i * float2(223.64, 823.12));
i += dot(i, i + 23.14);
return frac(i.x * i.y);
}
float2 n22(float2 i) {
float x = n21(i);
return float2(x, n21(i+x));
}
float2 getPoint(float2 id, float2 offset, float iTime) {
return offset + sin(n22(id + offset) * iTime * 1.0) * 0.4;
}
float layer(float2 uv, float iTime) {
float m = 0.0;
float t = iTime * 2.0;
float2 gv = frac(uv) - 0.5;
float2 id = floor(uv) - 0.5;
float2 p[9];
int i = 0;
for (float y = -1.0; y <= 1.0; y++) {
for (float x = -1.0; x <= 1.0; x++) {
p[i++] = getPoint(id, float2(x,y), iTime);
}
}
for (int j = 0; j < 9; j++) {
m += drawLine(gv, p[4], p[j]);
float sparkle = 1.0 / pow(length(gv - p[j]), 1.5) * 0.005;
m += sparkle * (sin(t + frac(p[j].x) * 12.23) * 0.4 + 0.6);
}
m += drawLine(gv, p[1], p[3]);
m += drawLine(gv, p[1], p[5]);
m += drawLine(gv, p[7], p[3]);
m += drawLine(gv, p[7], p[5]);
return m;
}
};
Functions f;
float2 uv = fragCoord - float2(0.5, 0.5) * iScale;
float3 c = sin(iTime * 2.0 * float3(.234, .324,.768)) * 0.4 + 0.6;
float3 col = float3(0.0,0.0,0.0);
c.x += (uv.x + 0.5);
col += pow(-uv.y + 0.5, 5.0) * c;
float m = 0.0;
float x = sin(iTime * 0.1);
float y = cos(iTime * 0.2);
float2x2 rotMat = float2x2(x, y, -y, x);
uv = mul(rotMat, uv);
for (float i = 0.0; i <= 1.0; i+= 1.0/4.0) {
float z = frac(i + iTime * 0.05);
float size = lerp(15.0, .1, z) * 1.50;
float fade = smoothstep(0.0, 1.0, z) * smoothstep(1.0, 0.9, z);
m += f.layer((size * uv) + i * 10.0, iTime) * fade;
}
col += m * c;
return float4(col,1.0);
@ufna
Copy link
Author

ufna commented Jan 21, 2020

image

@AlePax
Copy link

AlePax commented Apr 11, 2022

Great work! :O I'm a total noob when it comes to HLSL, I tried to modify a bit, but failed miserably! ;)
I need to control the number of initial "spawned" points, get a simple "black and white" version on black background and play with standard shaders + Blueprints from there... could you give me some hints? :) Thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment