Created
May 3, 2017 20:37
-
-
Save Chlumsky/65d5cc8bf95614281027446ac1b99768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <billboard> | |
#include <perlin> | |
#include <hsv> | |
param float OPACITY = 0.25; | |
glsl struct ParticleData { | |
vec2 position; | |
float phase; | |
float speed; | |
float hue; | |
float blur; | |
}; | |
glsl struct FragmentData { | |
vec2 coord; | |
vec3 color; | |
float blur; | |
}; | |
glsl float pseudorandom(int a, int b) { | |
return fract(131.0*perlinNoise(vec2(13.7*float(a), -2.9*float(b)))); | |
} | |
glsl void initParticle(out ParticleData pd, int index) { | |
pd.position.x = mix(-4.0, 4.0, pseudorandom(index, 0)); | |
pd.position.y = mix(-1.0, 0.25, pow(pseudorandom(index, 1), 2.0)); | |
pd.phase = pseudorandom(index, 2); | |
pd.speed = mix(0.1, 0.5, pseudorandom(index, 3)); | |
pd.hue = pseudorandom(index, 4); | |
pd.blur = pseudorandom(index, 5); | |
} | |
glsl void updateParticle(inout ParticleData pd, float deltaTime) { | |
pd.position.x += pd.speed*deltaTime; | |
pd.position.y += sin(6.28*(pd.phase + pd.speed*shadron_Time))*deltaTime/8.0; | |
if (pd.position.x > 1.5) | |
pd.position.x -= 3.0; | |
} | |
glsl vec4 particleVertex(out FragmentData fd, in ParticleData pd, int index) { | |
fd.coord = billboardCoord(index).xy; | |
fd.color = hsv(pd.hue, 0.5, 1.0); | |
fd.blur = pd.blur; | |
float size = mix(0.03, 0.2, fd.blur); | |
return vec4(pd.position + size*fd.coord*vec2(1.0, shadron_Aspect), 0.0, 1.0); | |
} | |
glsl vec4 particleFragment(in FragmentData fd) { | |
float a = OPACITY*smoothstep(1.0, 0.9-fd.blur, length(fd.coord)); | |
return vec4(a*fd.color, 1.0); | |
} | |
particle_system Particles : | |
count(256), | |
particle_data(ParticleData), | |
fragment_data(FragmentData), | |
vertex(particleVertex, BILLBOARD_PRIMITIVES, BILLBOARD_VERTEX_COUNT), | |
fragment(particleFragment), | |
initialize(initParticle), | |
update(updateParticle), | |
blend(additive); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment