106 lines
2.2 KiB
Plaintext
106 lines
2.2 KiB
Plaintext
global uniform float beat;
|
|
global uniform float bar;
|
|
global uniform float song_time;
|
|
global uniform float total_song_time;
|
|
global uniform float user_offset_ms;
|
|
|
|
uniform float phase_offset = 0.0;
|
|
uniform float phase_multiplier = 1.0;
|
|
|
|
instance uniform float instance_phase_offset = 0.0;
|
|
instance uniform float instance_phase_multiplier = 1.0;
|
|
|
|
|
|
float get_beat_with_offset() {
|
|
return (beat * phase_multiplier * instance_phase_multiplier) + phase_offset + instance_phase_offset;// + (user_offset_ms / 1000.0);
|
|
}
|
|
|
|
|
|
float get_bar_with_offset() {
|
|
return (bar * phase_multiplier * instance_phase_multiplier) + phase_offset + instance_phase_offset;// + (user_offset_ms / 1000.0);
|
|
}
|
|
|
|
|
|
float get_beat_phase() {
|
|
float beat_offset = get_beat_with_offset();
|
|
return beat_offset - floor(beat_offset);
|
|
}
|
|
|
|
|
|
float get_bar_phase() {
|
|
float bar_offset = get_bar_with_offset();
|
|
return bar_offset - floor(bar_offset);
|
|
}
|
|
|
|
float get_song_time_ratio() {
|
|
return song_time / max(total_song_time, 0.001);
|
|
}
|
|
|
|
float ease(float x, float c) {
|
|
// Godot's source code converted via ChatGPT to GLSL-style
|
|
//branchless:
|
|
//x = clamp(x, 0.0, 1.0);
|
|
//float pos = mix(
|
|
//1.0 - pow(1.0 - x, 1.0 / c),
|
|
//pow(x, c),
|
|
//step(1.0, c)
|
|
//);
|
|
//
|
|
//float k = -c;
|
|
//float x2 = x * 2.0;
|
|
//float inout_v = mix(
|
|
//pow(x2, k) * 0.5,
|
|
//(1.0 - pow(2.0 - x2, k)) * 0.5 + 0.5,
|
|
//step(0.5, x)
|
|
//);
|
|
//
|
|
//float isPos = step(0.0, c);
|
|
//float isNeg = step(c, 0.0);
|
|
//
|
|
//return pos * isPos + inout_v * isNeg;
|
|
|
|
// a few branches:
|
|
x = clamp(x, 0.0, 1.0);
|
|
|
|
float pos = mix(
|
|
1.0 - pow(1.0 - x, 1.0 / c), // 0 < c < 1
|
|
pow(x, c), // c >= 1
|
|
step(1.0, c)
|
|
);
|
|
|
|
float k = -c;
|
|
float x2 = x * 2.0;
|
|
float inout_v = mix(
|
|
pow(x2, k) * 0.5,
|
|
(1.0 - pow(2.0 - x2, k)) * 0.5 + 0.5,
|
|
step(0.5, x)
|
|
);
|
|
|
|
return (c > 0.0) ? pos :
|
|
(c < 0.0) ? inout_v :
|
|
0.0;
|
|
|
|
// From godot's source code:
|
|
//if (x < 0.0) {
|
|
//x = 0.0;
|
|
//} else if (x > 1.0) {
|
|
//x = 1.0;
|
|
//}
|
|
//if (c > 0.0) {
|
|
//if (c < 1.0) {
|
|
//return 1.0 - pow(1.0 - x, 1.0 / c);
|
|
//} else {
|
|
//return pow(x, c);
|
|
//}
|
|
//} else if (c < 0.0) {
|
|
////inout ease
|
|
//
|
|
//if (x < 0.5) {
|
|
//return pow(x * 2.0, -c) * 0.5;
|
|
//} else {
|
|
//return (1.0 - pow(1.0 - (x - 0.5) * 2.0, -c)) * 0.5 + 0.5;
|
|
//}
|
|
//} else {
|
|
//return 0.0; // no ease (raw)
|
|
//}
|
|
} |