Updated compute shader particle system with point sprites and gradient coloring

This commit is contained in:
saschawillems 2016-05-14 23:09:17 +02:00
parent 72af27a49a
commit 3ae4f26901
9 changed files with 131 additions and 77 deletions

View file

@ -7,6 +7,7 @@ struct Particle
{
vec2 pos;
vec2 vel;
vec4 gradientPos;
};
// Binding 0 : Position storage buffer
@ -71,5 +72,8 @@ void main()
// Write back
particles[index].vel.xy = vVel;
particles[index].gradientPos.x += 0.02 * ubo.deltaT;
if (particles[index].gradientPos.x > 1.0)
particles[index].gradientPos.x -= 1.0;
}

View file

@ -3,11 +3,16 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
layout (binding = 0) uniform sampler2D samplerColorMap;
layout (binding = 1) uniform sampler2D samplerGradientRamp;
layout (location = 0) in vec4 inColor;
layout (location = 1) in float inGradientPos;
layout (location = 0) out vec4 outFragColor;
void main ()
{
outFragColor = inColor;
vec3 color = texture(samplerGradientRamp, vec2(inGradientPos, 0.0)).rgb;
outFragColor.rgb = texture(samplerColorMap, gl_PointCoord).rgb * color;
}

View file

@ -4,12 +4,21 @@
#extension GL_ARB_shading_language_420pack : enable
layout (location = 0) in vec2 inPos;
layout (location = 1) in vec4 inGradientPos;
layout (location = 0) out vec4 outColor;
layout (location = 1) out float outGradientPos;
out gl_PerVertex
{
vec4 gl_Position;
float gl_PointSize;
};
void main ()
{
gl_PointSize = 1.0;
gl_PointSize = 8.0;
outColor = vec4(0.035);
outGradientPos = inGradientPos.x;
gl_Position = vec4(inPos.xy, 1.0, 1.0);
}