Avoid switch statement in glsl files to workaround shader compiler crash on macOS devices

This commit is contained in:
clayjohn 2024-05-01 19:23:51 -07:00
parent b9f01dcf87
commit b5660604e4

View File

@ -57,45 +57,40 @@ void main() {
txform = transpose(mat4(xform_1, xform_2, vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0))); txform = transpose(mat4(xform_1, xform_2, vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0)));
#endif #endif
switch (align_mode) { // Use if/else here as switch statements cause crashes on certain low-end hardware.
case TRANSFORM_ALIGN_DISABLED: { if (align_mode == TRANSFORM_ALIGN_DISABLED) {
} break; //nothing // nothing
case TRANSFORM_ALIGN_Z_BILLBOARD: { } else if (align_mode == TRANSFORM_ALIGN_Z_BILLBOARD) {
mat3 local = mat3(normalize(cross(align_up, sort_direction)), align_up, sort_direction); mat3 local = mat3(normalize(cross(align_up, sort_direction)), align_up, sort_direction);
local = local * mat3(txform); local = local * mat3(txform);
txform[0].xyz = local[0]; txform[0].xyz = local[0];
txform[1].xyz = local[1]; txform[1].xyz = local[1];
txform[2].xyz = local[2]; txform[2].xyz = local[2];
} else if (align_mode == TRANSFORM_ALIGN_Y_TO_VELOCITY) {
vec3 v = velocity_flags.xyz;
float s = (length(txform[0]) + length(txform[1]) + length(txform[2])) / 3.0;
if (length(v) > 0.0) {
txform[1].xyz = normalize(v);
} else {
txform[1].xyz = normalize(txform[1].xyz);
}
} break; txform[0].xyz = normalize(cross(txform[1].xyz, txform[2].xyz));
case TRANSFORM_ALIGN_Y_TO_VELOCITY: { txform[2].xyz = vec3(0.0, 0.0, 1.0) * s;
vec3 v = velocity_flags.xyz; txform[0].xyz *= s;
float s = (length(txform[0]) + length(txform[1]) + length(txform[2])) / 3.0; txform[1].xyz *= s;
if (length(v) > 0.0) { } else if (align_mode == TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY) {
txform[1].xyz = normalize(v); vec3 sv = velocity_flags.xyz - sort_direction * dot(sort_direction, velocity_flags.xyz); //screen velocity
} else {
txform[1].xyz = normalize(txform[1].xyz);
}
txform[0].xyz = normalize(cross(txform[1].xyz, txform[2].xyz)); if (length(sv) == 0.0) {
txform[2].xyz = vec3(0.0, 0.0, 1.0) * s; sv = align_up;
txform[0].xyz *= s; }
txform[1].xyz *= s;
} break;
case TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY: {
vec3 sv = velocity_flags.xyz - sort_direction * dot(sort_direction, velocity_flags.xyz); //screen velocity
if (length(sv) == 0.0) { sv = normalize(sv);
sv = align_up;
}
sv = normalize(sv); txform[0].xyz = normalize(cross(sv, sort_direction)) * length(txform[0]);
txform[1].xyz = sv * length(txform[1]);
txform[0].xyz = normalize(cross(sv, sort_direction)) * length(txform[0]); txform[2].xyz = sort_direction * length(txform[2]);
txform[1].xyz = sv * length(txform[1]);
txform[2].xyz = sort_direction * length(txform[2]);
} break;
} }
txform[3].xyz += velocity_flags.xyz * frame_remainder; txform[3].xyz += velocity_flags.xyz * frame_remainder;