2017-10-13 12:19:59 -04:00
|
|
|
uniform int flips;
|
2022-10-16 21:33:51 -04:00
|
|
|
uniform int sky;
|
|
|
|
uniform vec3 view_position;
|
2017-10-15 07:14:07 -04:00
|
|
|
uniform float billboard;
|
2017-10-13 12:19:59 -04:00
|
|
|
|
|
|
|
#ifdef Explicit_Attrib_Location_Usable
|
|
|
|
|
|
|
|
layout(location = 0) in vec3 Position;
|
2017-10-15 01:57:01 -04:00
|
|
|
layout(location = 1) in vec4 color_lifetime;
|
|
|
|
layout(location = 2) in vec2 size;
|
2017-10-13 12:19:59 -04:00
|
|
|
|
|
|
|
layout(location = 3) in vec2 Texcoord;
|
|
|
|
layout(location = 4) in vec2 quadcorner;
|
|
|
|
|
|
|
|
layout(location = 6) in float anglespeed;
|
|
|
|
#else
|
|
|
|
|
|
|
|
in vec3 Position;
|
2017-10-15 01:57:01 -04:00
|
|
|
in vec4 color_lifetime;
|
|
|
|
in vec2 size;
|
2017-10-13 12:19:59 -04:00
|
|
|
|
|
|
|
in vec2 Texcoord;
|
|
|
|
in vec2 quadcorner;
|
|
|
|
|
2017-10-14 02:42:24 -04:00
|
|
|
in float anglespeed;
|
2017-10-13 12:19:59 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
out vec2 tc;
|
|
|
|
out vec4 pc;
|
|
|
|
|
2022-10-16 21:33:51 -04:00
|
|
|
vec4 getQuat(float half_sin, float half_cos)
|
|
|
|
{
|
|
|
|
return normalize(vec4(vec3(0.0, 1.0, 0.0) * half_sin, half_cos));
|
|
|
|
}
|
|
|
|
|
2017-10-13 12:19:59 -04:00
|
|
|
void main(void)
|
|
|
|
{
|
2017-10-15 01:57:01 -04:00
|
|
|
if (size.x == 0.0 && size.y == 0.0)
|
2017-10-13 12:19:59 -04:00
|
|
|
{
|
2017-10-13 21:47:13 -04:00
|
|
|
gl_Position = vec4(0.);
|
2017-10-15 01:57:01 -04:00
|
|
|
pc = vec4(0.0);
|
|
|
|
tc = vec2(0.0);
|
2017-10-13 12:19:59 -04:00
|
|
|
return;
|
|
|
|
}
|
2017-10-15 01:57:01 -04:00
|
|
|
|
2022-09-08 21:41:32 -04:00
|
|
|
float lifetime = size.y;
|
|
|
|
vec2 particle_size = mix(size.xx, size, billboard);
|
2017-10-13 12:19:59 -04:00
|
|
|
tc = Texcoord;
|
2022-09-08 21:41:32 -04:00
|
|
|
pc = color_lifetime.zyxw;
|
2017-10-15 01:57:01 -04:00
|
|
|
|
2017-10-13 12:19:59 -04:00
|
|
|
vec4 viewpos = vec4(0.);
|
2022-10-16 21:33:51 -04:00
|
|
|
if (flips == 1 || sky == 1)
|
2017-10-13 12:19:59 -04:00
|
|
|
{
|
2022-10-16 21:33:51 -04:00
|
|
|
vec4 quat = vec4(0.0);
|
|
|
|
if (flips == 1)
|
|
|
|
{
|
|
|
|
float angle = lifetime * anglespeed;
|
|
|
|
float sin_a = sin(mod(angle / 2.0, 6.283185307179586));
|
|
|
|
float cos_a = cos(mod(angle / 2.0, 6.283185307179586));
|
|
|
|
quat = getQuat(sin_a, cos_a);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vec3 diff = Position - view_position;
|
|
|
|
float angle = atan(diff.x, diff.z);
|
|
|
|
quat = getQuat(sin(angle / -2.0), cos(angle / -2.0));
|
|
|
|
}
|
2022-09-08 21:41:32 -04:00
|
|
|
vec3 newquadcorner = vec3(particle_size * quadcorner, 0.0);
|
2017-10-13 21:47:13 -04:00
|
|
|
newquadcorner = newquadcorner + 2.0 * cross(cross(newquadcorner,
|
|
|
|
quat.xyz) + quat.w * newquadcorner, quat.xyz);
|
2017-12-25 01:00:10 -05:00
|
|
|
viewpos = u_view_matrix * vec4(Position + newquadcorner, 1.0);
|
2017-10-13 12:19:59 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-25 01:00:10 -05:00
|
|
|
viewpos = u_view_matrix * vec4(Position, 1.0);
|
2022-09-08 21:41:32 -04:00
|
|
|
viewpos += vec4(particle_size * quadcorner, 0.0, 0.0);
|
2017-10-13 12:19:59 -04:00
|
|
|
}
|
2017-12-25 01:00:10 -05:00
|
|
|
gl_Position = u_projection_matrix * viewpos;
|
2017-10-13 12:19:59 -04:00
|
|
|
}
|