line shader cleanup
This commit is contained in:
parent
867d0be356
commit
5b44ad125c
|
@ -3,6 +3,7 @@ render_mode blend_premul_alpha;
|
|||
|
||||
const float TAU = 6.283185307;
|
||||
const float PI = 3.1415926536;
|
||||
const float EPS = 0.00001;
|
||||
|
||||
uniform vec4 line_color : hint_color = vec4(0.8, 0.8, 1.0, 0.8);
|
||||
uniform vec4 line_color_double : hint_color = vec4(1.0, 1.0, 0.6, 0.9);
|
||||
|
@ -12,12 +13,11 @@ uniform float line_thickness = 0.012;
|
|||
uniform float line_thickness_min = 0.0;
|
||||
uniform float dot_thickness = 0.033;
|
||||
uniform float dot_fullbright_thickness = 0.013;
|
||||
uniform float max_angle = 1.0708; //3.14159*0.5; //radians(90.0);
|
||||
uniform float max_angle = 1.5708; //1.0708; //3.14159*0.5; //radians(90.0);
|
||||
uniform float max_dist = 1.25;
|
||||
|
||||
// GLES2 clamps our color values that we send as makeshift arrays, so we need to divide them in code and multiply them in our shader
|
||||
uniform vec3 array_postmul = vec3(2.0, 8.0, 6.283185307);
|
||||
uniform float cols_div2 = 3.999; // Used to determine opposed notes
|
||||
|
||||
//void vertex() {
|
||||
//}
|
||||
|
@ -56,6 +56,10 @@ vec3 array_get(sampler2D tex, int index) {
|
|||
return texture(tex, vec2(x, y), -100.0).xyz * array_postmul;
|
||||
}
|
||||
|
||||
float get_fringe_alpha(float radial_dist, float angular_dist) { // Branchless edition :)
|
||||
float thickness = mix(line_thickness, line_thickness_min, angular_dist/max_angle) * float(angular_dist < max_angle);
|
||||
return max(thickness-radial_dist, 0.0)/line_thickness;
|
||||
}
|
||||
|
||||
void fragment() {
|
||||
float dist = distance(UV, vec2(0.0));
|
||||
|
@ -66,15 +70,15 @@ void fragment() {
|
|||
|
||||
// Iterate over all the notes and check distance to them
|
||||
bool last_double = false;
|
||||
for (int i=0; i<238; i++){
|
||||
// x, y, z = distance, column, column_radians
|
||||
int i_end = array_size - array_sidelen - 2;
|
||||
for (int i=0; i<i_end; i++){
|
||||
// x, y, z = radial distance, column, column_radians
|
||||
vec3 sample = array_get(TEXTURE, i).xyz;
|
||||
if (sample == vec3(0.0)) break;
|
||||
float diff = abs(dist - sample.x);
|
||||
// Short-circuit out if our radial difference is too high to matter in any case.
|
||||
// We need the diff value calculated anyway so shouldn't add any overhead
|
||||
// Assume dot_thickness is thickest uniform
|
||||
if (diff > dot_thickness) continue;
|
||||
float radial_dist = abs(dist - sample.x);
|
||||
if (radial_dist > dot_thickness) continue;
|
||||
|
||||
// Check for dot distance
|
||||
vec2 uv = sample.x * vec2(cos(sample.z), -sin(sample.z));
|
||||
|
@ -96,49 +100,24 @@ void fragment() {
|
|||
if (sample.x == sample2.x){
|
||||
// This note is a double!
|
||||
last_double = true;
|
||||
// Check for special case: directly opposite columns - full-thickness line 360°
|
||||
// if (sample.y == mod(sample2.y+4.0, 8.0)){
|
||||
if (abs(sample.y-sample2.y) >= cols_div2){
|
||||
if (diff < line_thickness){
|
||||
line_double_alpha += (line_thickness-diff)/line_thickness;
|
||||
}
|
||||
} else {
|
||||
// Find the smallest arc between them, make it fully thick
|
||||
float diff_a2 = angle_diff(angle, sample2.z);
|
||||
if ((diff_a+diff_a2-0.0001) <= angle_diff(sample.z, sample2.z)){
|
||||
if (diff < line_thickness){
|
||||
line_double_alpha += (line_thickness-diff)/line_thickness;
|
||||
}
|
||||
} else {
|
||||
// Fringe
|
||||
float diff_amin = min(diff_a, diff_a2);
|
||||
if (diff_amin < max_angle){
|
||||
float thickness = mix(line_thickness, line_thickness_min, diff_amin/max_angle);
|
||||
if (diff < thickness){
|
||||
line_double_alpha += (thickness-diff)/line_thickness;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (diff_a < max_angle){
|
||||
float thickness = mix(line_thickness, line_thickness_min, diff_a/max_angle);
|
||||
if (diff < thickness){
|
||||
line_alpha += (thickness-diff)/line_thickness;
|
||||
}
|
||||
}
|
||||
float double_diff = angle_diff(sample.z, sample2.z);
|
||||
// Find the smallest arc between them, make it fully thick. If they are directly opposite, this will go 360°
|
||||
float diff_a2 = angle_diff(angle, sample2.z);
|
||||
bool fullthick = (diff_a+diff_a2-EPS) <= min(double_diff, PI-EPS); // Branchless logic
|
||||
line_double_alpha += ((line_thickness-radial_dist)/line_thickness) * float(radial_dist < line_thickness) * float(fullthick);
|
||||
line_double_alpha += get_fringe_alpha(radial_dist, min(diff_a, diff_a2)) * float(!fullthick);
|
||||
} else { // Just a regular single, fringing line only
|
||||
line_alpha += get_fringe_alpha(radial_dist, diff_a);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw release dots
|
||||
int i_start = array_size - array_sidelen;
|
||||
for (int i=i_start; i<array_size; i++){
|
||||
for (int i=array_size - array_sidelen; i<array_size; i++){
|
||||
vec3 sample = array_get(TEXTURE, i).xyz;
|
||||
if (sample == vec3(0.0)) break;
|
||||
vec2 uv = sample.x * vec2(cos(sample.z), -sin(sample.z));
|
||||
float dist2 = distance(UV, uv);
|
||||
if (dist2 < dot_thickness){
|
||||
//dot_alpha += (dot_thickness-dist2)/dot_thickness;
|
||||
float w = dot_thickness - dot_fullbright_thickness;
|
||||
dot_alpha += (w-max(dist2-dot_fullbright_thickness, 0.0))/w;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue