2020-06-30 14:29:35 +00:00
|
|
|
#version 330 core
|
|
|
|
|
|
|
|
#include <globals.glsl>
|
|
|
|
#include <srgb.glsl>
|
2020-07-31 09:32:13 +00:00
|
|
|
#include <random.glsl>
|
2020-06-30 14:29:35 +00:00
|
|
|
|
|
|
|
in vec3 v_pos;
|
|
|
|
in uint v_col;
|
|
|
|
in uint v_norm_ao;
|
2020-07-19 07:16:06 +00:00
|
|
|
in vec3 inst_pos;
|
2020-07-15 15:45:47 +00:00
|
|
|
in float inst_time;
|
|
|
|
in float inst_entropy;
|
|
|
|
in int inst_mode;
|
2020-06-30 14:29:35 +00:00
|
|
|
|
|
|
|
out vec3 f_pos;
|
|
|
|
flat out vec3 f_norm;
|
|
|
|
out vec3 f_col;
|
|
|
|
out float f_ao;
|
|
|
|
out float f_light;
|
|
|
|
|
|
|
|
const float SCALE = 1.0 / 11.0;
|
|
|
|
|
2020-07-19 07:16:06 +00:00
|
|
|
// Φ = Golden Ratio
|
|
|
|
float PHI = 1.61803398874989484820459;
|
2020-07-15 15:45:47 +00:00
|
|
|
|
|
|
|
float gold_noise(in vec2 xy, in float seed){
|
|
|
|
return fract(tan(distance(xy * PHI, xy) * seed) * xy.x);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Modes
|
|
|
|
const int SMOKE = 0;
|
|
|
|
const int FIRE = 1;
|
2020-07-19 07:16:06 +00:00
|
|
|
const int GUN_POWDER_SPARK = 2;
|
|
|
|
|
|
|
|
// meters per second
|
|
|
|
const float earth_gravity = 9.807;
|
|
|
|
|
|
|
|
mat4 translate(vec3 vec){
|
|
|
|
return mat4(
|
|
|
|
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(vec.x, vec.y, vec.z, 1.0)
|
|
|
|
);
|
|
|
|
}
|
2020-07-15 15:45:47 +00:00
|
|
|
|
2020-07-31 09:32:13 +00:00
|
|
|
struct Attr {
|
|
|
|
vec3 offs;
|
|
|
|
float scale;
|
|
|
|
vec3 col;
|
|
|
|
};
|
|
|
|
|
|
|
|
float lifetime = tick.x - inst_time;
|
|
|
|
|
|
|
|
vec3 linear_motion(vec3 init_offs, vec3 vel) {
|
|
|
|
return init_offs + vel * lifetime;
|
|
|
|
}
|
|
|
|
|
|
|
|
vec3 grav_vel(float grav) {
|
|
|
|
return vec3(0, 0, -grav * lifetime);
|
|
|
|
}
|
|
|
|
|
|
|
|
float exp_scale(float factor) {
|
|
|
|
return 1 / (1 - lifetime * factor);
|
|
|
|
}
|
|
|
|
|
2020-06-30 14:29:35 +00:00
|
|
|
void main() {
|
2020-07-19 07:16:06 +00:00
|
|
|
mat4 inst_mat = translate(inst_pos);
|
2020-06-30 14:29:35 +00:00
|
|
|
|
2020-07-31 09:32:13 +00:00
|
|
|
float rand0 = hash(vec4(inst_entropy + 0));
|
|
|
|
float rand1 = hash(vec4(inst_entropy + 1));
|
|
|
|
float rand2 = hash(vec4(inst_entropy + 2));
|
|
|
|
float rand3 = hash(vec4(inst_entropy + 3));
|
|
|
|
float rand4 = hash(vec4(inst_entropy + 4));
|
|
|
|
float rand5 = hash(vec4(inst_entropy + 5));
|
|
|
|
float rand6 = hash(vec4(inst_entropy + 6));
|
|
|
|
float rand7 = hash(vec4(inst_entropy + 7));
|
2020-07-15 15:45:47 +00:00
|
|
|
|
2020-07-31 09:32:13 +00:00
|
|
|
Attr attr;
|
2020-07-15 15:45:47 +00:00
|
|
|
|
|
|
|
if (inst_mode == SMOKE) {
|
2020-07-31 09:32:13 +00:00
|
|
|
attr = Attr(
|
|
|
|
linear_motion(
|
|
|
|
vec3(rand0 * 0.25, rand1 * 0.25, 1.7 + rand5),
|
|
|
|
vec3(rand2 * 0.2, rand3 * 0.2, 1.0 + rand4 * 0.5)// + vec3(sin(lifetime), sin(lifetime + 1.5), sin(lifetime * 4) * 0.25)
|
|
|
|
),
|
|
|
|
exp_scale(-0.2),
|
|
|
|
vec3(1)
|
|
|
|
);
|
2020-07-15 15:45:47 +00:00
|
|
|
} else if (inst_mode == FIRE) {
|
2020-07-31 09:32:13 +00:00
|
|
|
attr = Attr(
|
|
|
|
linear_motion(
|
|
|
|
vec3(rand0 * 0.25, rand1 * 0.25, 0.3),
|
|
|
|
vec3(rand2 * 0.1, rand3 * 0.1, 2.0 + rand4 * 1.0)
|
|
|
|
),
|
|
|
|
1.0,
|
|
|
|
vec3(2, rand5 + 2, 0)
|
|
|
|
);
|
2020-07-19 07:16:06 +00:00
|
|
|
} else if (inst_mode == GUN_POWDER_SPARK) {
|
2020-07-31 09:32:13 +00:00
|
|
|
attr = Attr(
|
|
|
|
linear_motion(
|
|
|
|
vec3(rand0, rand1, rand3) * 0.3,
|
|
|
|
vec3(rand4, rand5, rand6) * 2.0 + grav_vel(earth_gravity)
|
|
|
|
),
|
|
|
|
1.0,
|
|
|
|
vec3(3.5, 3 + rand7, 0)
|
|
|
|
);
|
2020-07-15 15:45:47 +00:00
|
|
|
} else {
|
2020-07-31 09:32:13 +00:00
|
|
|
attr = Attr(
|
|
|
|
linear_motion(
|
|
|
|
vec3(rand0 * 0.25, rand1 * 0.25, 1.7 + rand5),
|
|
|
|
vec3(rand2 * 0.1, rand3 * 0.1, 1.0 + rand4 * 0.5)
|
|
|
|
),
|
|
|
|
exp_scale(-0.2),
|
|
|
|
vec3(1)
|
|
|
|
);
|
2020-07-15 15:45:47 +00:00
|
|
|
}
|
|
|
|
|
2020-07-31 09:32:13 +00:00
|
|
|
f_pos = (inst_mat * vec4(v_pos * attr.scale * SCALE + attr.offs, 1)).xyz;
|
2020-06-30 14:29:35 +00:00
|
|
|
|
|
|
|
// First 3 normals are negative, next 3 are positive
|
|
|
|
vec3 normals[6] = vec3[](vec3(-1,0,0), vec3(1,0,0), vec3(0,-1,0), vec3(0,1,0), vec3(0,0,-1), vec3(0,0,1));
|
|
|
|
f_norm = (inst_mat * vec4(normals[(v_norm_ao >> 0) & 0x7u], 0)).xyz;
|
|
|
|
|
|
|
|
vec3 col = vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0;
|
2020-07-31 09:32:13 +00:00
|
|
|
f_col = srgb_to_linear(col) * srgb_to_linear(attr.col);
|
2020-06-30 14:29:35 +00:00
|
|
|
f_ao = float((v_norm_ao >> 3) & 0x3u) / 4.0;
|
|
|
|
|
|
|
|
f_light = 1.0;
|
|
|
|
|
|
|
|
gl_Position =
|
|
|
|
all_mat *
|
|
|
|
vec4(f_pos, 1);
|
|
|
|
gl_Position.z = -1000.0 / (gl_Position.z + 10000.0);
|
2020-07-31 17:16:20 +00:00
|
|
|
}
|