2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-12-30 12:35:54 +01:00
|
|
|
[vertex]
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
#if defined(IS_UBERSHADER)
|
2022-06-19 20:16:27 +02:00
|
|
|
uniform highp int ubershader_flags;
|
2021-09-26 21:31:17 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 0) in highp vec4 color;
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2018-08-24 13:42:18 +02:00
|
|
|
layout(location = 1) in highp vec4 velocity_active;
|
|
|
|
layout(location = 2) in highp vec4 custom;
|
|
|
|
layout(location = 3) in highp vec4 xform_1;
|
|
|
|
layout(location = 4) in highp vec4 xform_2;
|
|
|
|
layout(location = 5) in highp vec4 xform_3;
|
2016-12-30 12:35:54 +01:00
|
|
|
|
|
|
|
struct Attractor {
|
|
|
|
vec3 pos;
|
|
|
|
vec3 dir;
|
|
|
|
float radius;
|
|
|
|
float eat_radius;
|
|
|
|
float strength;
|
|
|
|
float attenuation;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_ATTRACTORS 64
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
uniform bool emitting;
|
2016-12-30 12:35:54 +01:00
|
|
|
uniform float system_phase;
|
|
|
|
uniform float prev_system_phase;
|
2017-04-07 04:36:37 +02:00
|
|
|
uniform int total_particles;
|
2016-12-30 12:35:54 +01:00
|
|
|
uniform float explosiveness;
|
2017-04-07 04:36:37 +02:00
|
|
|
uniform float randomness;
|
2017-06-16 13:29:43 +02:00
|
|
|
uniform float time;
|
2016-12-30 12:35:54 +01:00
|
|
|
uniform float delta;
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2016-12-30 12:35:54 +01:00
|
|
|
uniform int attractor_count;
|
|
|
|
uniform Attractor attractors[MAX_ATTRACTORS];
|
2017-04-07 04:36:37 +02:00
|
|
|
uniform bool clear;
|
|
|
|
uniform uint cycle;
|
|
|
|
uniform float lifetime;
|
|
|
|
uniform mat4 emission_transform;
|
2017-06-23 19:31:21 +02:00
|
|
|
uniform uint random_seed;
|
2016-12-30 12:35:54 +01:00
|
|
|
|
|
|
|
out highp vec4 out_color; //tfb:
|
2017-01-02 02:16:52 +01:00
|
|
|
out highp vec4 out_velocity_active; //tfb:
|
|
|
|
out highp vec4 out_custom; //tfb:
|
|
|
|
out highp vec4 out_xform_1; //tfb:
|
|
|
|
out highp vec4 out_xform_2; //tfb:
|
|
|
|
out highp vec4 out_xform_3; //tfb:
|
|
|
|
|
|
|
|
#if defined(USE_MATERIAL)
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2017-01-02 02:16:52 +01:00
|
|
|
layout(std140) uniform UniformData { //ubo:0
|
|
|
|
|
|
|
|
MATERIAL_UNIFORMS
|
|
|
|
|
|
|
|
};
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
2017-01-02 02:16:52 +01:00
|
|
|
|
|
|
|
#endif
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2017-06-27 03:58:03 +02:00
|
|
|
VERTEX_SHADER_GLOBALS
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
uint hash(uint x) {
|
|
|
|
x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b);
|
|
|
|
x = ((x >> uint(16)) ^ x) * uint(0x45d9f3b);
|
|
|
|
x = (x >> uint(16)) ^ x;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2016-12-30 12:35:54 +01:00
|
|
|
void main() {
|
2018-08-24 13:42:18 +02:00
|
|
|
bool apply_forces = true;
|
|
|
|
bool apply_velocity = true;
|
|
|
|
float local_delta = delta;
|
2016-12-30 12:35:54 +01:00
|
|
|
|
|
|
|
float mass = 1.0;
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
float restart_phase = float(gl_VertexID) / float(total_particles);
|
2017-04-07 04:36:37 +02:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
if (randomness > 0.0) {
|
2017-04-07 04:36:37 +02:00
|
|
|
uint seed = cycle;
|
|
|
|
if (restart_phase >= system_phase) {
|
2018-08-24 13:42:18 +02:00
|
|
|
seed -= uint(1);
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
2018-08-24 13:42:18 +02:00
|
|
|
seed *= uint(total_particles);
|
|
|
|
seed += uint(gl_VertexID);
|
2017-04-07 04:36:37 +02:00
|
|
|
float random = float(hash(seed) % uint(65536)) / 65536.0;
|
2018-08-24 13:42:18 +02:00
|
|
|
restart_phase += randomness * random * 1.0 / float(total_particles);
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
restart_phase *= (1.0 - explosiveness);
|
|
|
|
bool restart = false;
|
2017-04-13 16:46:16 +02:00
|
|
|
bool shader_active = velocity_active.a > 0.5;
|
2016-12-30 12:35:54 +01:00
|
|
|
|
|
|
|
if (system_phase > prev_system_phase) {
|
2017-06-23 19:31:21 +02:00
|
|
|
// restart_phase >= prev_system_phase is used so particles emit in the first frame they are processed
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
if (restart_phase >= prev_system_phase && restart_phase < system_phase) {
|
|
|
|
restart = true;
|
2021-09-26 21:31:17 +02:00
|
|
|
#ifdef USE_FRACTIONAL_DELTA //ubershader-runtime
|
2017-04-07 04:36:37 +02:00
|
|
|
local_delta = (system_phase - restart_phase) * lifetime;
|
2021-09-26 21:31:17 +02:00
|
|
|
#endif //ubershader-runtime
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
} else if (delta > 0.0) {
|
2017-06-23 19:31:21 +02:00
|
|
|
if (restart_phase >= prev_system_phase) {
|
2018-08-24 13:42:18 +02:00
|
|
|
restart = true;
|
2021-09-26 21:31:17 +02:00
|
|
|
#ifdef USE_FRACTIONAL_DELTA //ubershader-runtime
|
2017-04-07 04:36:37 +02:00
|
|
|
local_delta = (1.0 - restart_phase + system_phase) * lifetime;
|
2021-09-26 21:31:17 +02:00
|
|
|
#endif //ubershader-runtime
|
2018-08-24 13:42:18 +02:00
|
|
|
} else if (restart_phase < system_phase) {
|
|
|
|
restart = true;
|
2021-09-26 21:31:17 +02:00
|
|
|
#ifdef USE_FRACTIONAL_DELTA //ubershader-runtime
|
2017-04-07 04:36:37 +02:00
|
|
|
local_delta = (system_phase - restart_phase) * lifetime;
|
2021-09-26 21:31:17 +02:00
|
|
|
#endif //ubershader-runtime
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
uint current_cycle = cycle;
|
|
|
|
|
|
|
|
if (system_phase < restart_phase) {
|
2018-08-24 13:42:18 +02:00
|
|
|
current_cycle -= uint(1);
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
uint particle_number = current_cycle * uint(total_particles) + uint(gl_VertexID);
|
2017-05-19 17:43:25 +02:00
|
|
|
int index = int(gl_VertexID);
|
2017-01-02 02:16:52 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
if (restart) {
|
2018-08-24 13:42:18 +02:00
|
|
|
shader_active = emitting;
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
2017-01-02 02:16:52 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
mat4 xform;
|
2017-01-02 02:16:52 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
#if defined(ENABLE_KEEP_DATA)
|
|
|
|
if (clear) {
|
|
|
|
#else
|
|
|
|
if (clear || restart) {
|
|
|
|
#endif
|
2018-08-24 13:42:18 +02:00
|
|
|
out_color = vec4(1.0);
|
|
|
|
out_velocity_active = vec4(0.0);
|
|
|
|
out_custom = vec4(0.0);
|
2017-04-07 04:36:37 +02:00
|
|
|
if (!restart)
|
2018-08-24 13:42:18 +02:00
|
|
|
shader_active = false;
|
2017-04-07 04:36:37 +02:00
|
|
|
|
|
|
|
xform = mat4(
|
2018-08-24 13:42:18 +02:00
|
|
|
vec4(1.0, 0.0, 0.0, 0.0),
|
|
|
|
vec4(0.0, 1.0, 0.0, 0.0),
|
|
|
|
vec4(0.0, 0.0, 1.0, 0.0),
|
|
|
|
vec4(0.0, 0.0, 0.0, 1.0));
|
2017-04-07 04:36:37 +02:00
|
|
|
} else {
|
2018-08-24 13:42:18 +02:00
|
|
|
out_color = color;
|
|
|
|
out_velocity_active = velocity_active;
|
|
|
|
out_custom = custom;
|
|
|
|
xform = transpose(mat4(xform_1, xform_2, xform_3, vec4(vec3(0.0), 1.0)));
|
2017-04-07 04:36:37 +02:00
|
|
|
}
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-04-13 16:46:16 +02:00
|
|
|
if (shader_active) {
|
2016-12-30 12:35:54 +01:00
|
|
|
//execute shader
|
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
{
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
VERTEX_SHADER_CODE
|
2018-08-27 07:31:48 +02:00
|
|
|
|
|
|
|
/* clang-format on */
|
2017-01-02 02:16:52 +01:00
|
|
|
}
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
#if !defined(DISABLE_FORCE)
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-07-22 19:07:38 +02:00
|
|
|
if (false) {
|
2017-04-09 03:38:11 +02:00
|
|
|
vec3 force = vec3(0.0);
|
2018-08-24 13:42:18 +02:00
|
|
|
for (int i = 0; i < attractor_count; i++) {
|
2017-04-07 04:36:37 +02:00
|
|
|
vec3 rel_vec = xform[3].xyz - attractors[i].pos;
|
2017-04-13 16:46:16 +02:00
|
|
|
float dist = length(rel_vec);
|
2017-01-02 02:16:52 +01:00
|
|
|
if (attractors[i].radius < dist)
|
|
|
|
continue;
|
2018-08-24 13:42:18 +02:00
|
|
|
if (attractors[i].eat_radius > 0.0 && attractors[i].eat_radius > dist) {
|
|
|
|
out_velocity_active.a = 0.0;
|
2017-01-02 02:16:52 +01:00
|
|
|
}
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
rel_vec = normalize(rel_vec);
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
float attenuation = pow(dist / attractors[i].radius, attractors[i].attenuation);
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
if (attractors[i].dir == vec3(0.0)) {
|
2017-01-02 02:16:52 +01:00
|
|
|
//towards center
|
2018-08-24 13:42:18 +02:00
|
|
|
force += attractors[i].strength * rel_vec * attenuation * mass;
|
2017-01-02 02:16:52 +01:00
|
|
|
} else {
|
2018-08-24 13:42:18 +02:00
|
|
|
force += attractors[i].strength * attractors[i].dir * attenuation * mass;
|
2017-01-02 02:16:52 +01:00
|
|
|
}
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
2017-01-02 02:16:52 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
out_velocity_active.xyz += force * local_delta;
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
2017-01-02 02:16:52 +01:00
|
|
|
#endif
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
#if !defined(DISABLE_VELOCITY)
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
if (true) {
|
|
|
|
xform[3].xyz += out_velocity_active.xyz * local_delta;
|
2017-01-02 02:16:52 +01:00
|
|
|
}
|
|
|
|
#endif
|
2017-04-07 04:36:37 +02:00
|
|
|
} else {
|
2018-08-24 13:42:18 +02:00
|
|
|
xform = mat4(0.0);
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
xform = transpose(xform);
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
out_velocity_active.a = mix(0.0, 1.0, shader_active);
|
2017-01-02 02:16:52 +01:00
|
|
|
|
|
|
|
out_xform_1 = xform[0];
|
|
|
|
out_xform_2 = xform[1];
|
|
|
|
out_xform_3 = xform[2];
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
|
|
|
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format off */
|
2016-12-30 12:35:54 +01:00
|
|
|
[fragment]
|
|
|
|
|
2021-09-26 21:31:17 +02:00
|
|
|
#if defined(IS_UBERSHADER)
|
2022-06-19 20:16:27 +02:00
|
|
|
uniform highp int ubershader_flags;
|
2021-09-26 21:31:17 +02:00
|
|
|
#endif
|
|
|
|
|
2018-08-24 13:42:18 +02:00
|
|
|
// any code here is never executed, stuff is filled just so it works
|
2017-01-02 02:16:52 +01:00
|
|
|
|
|
|
|
#if defined(USE_MATERIAL)
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
layout(std140) uniform UniformData {
|
2016-12-30 12:35:54 +01:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
MATERIAL_UNIFORMS
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-06-27 03:58:03 +02:00
|
|
|
FRAGMENT_SHADER_GLOBALS
|
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
void main() {
|
|
|
|
|
2017-06-01 23:55:24 +02:00
|
|
|
{
|
2018-08-27 07:31:48 +02:00
|
|
|
|
2017-06-01 23:55:24 +02:00
|
|
|
LIGHT_SHADER_CODE
|
2018-08-27 07:31:48 +02:00
|
|
|
|
2017-06-01 23:55:24 +02:00
|
|
|
}
|
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
{
|
2018-08-27 07:31:48 +02:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
FRAGMENT_SHADER_CODE
|
2018-08-27 07:31:48 +02:00
|
|
|
|
2017-01-02 02:16:52 +01:00
|
|
|
}
|
2016-12-30 12:35:54 +01:00
|
|
|
}
|
2018-08-27 07:31:48 +02:00
|
|
|
/* clang-format on */
|