mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-04-06 00:32:05 +02:00
FIX: hidden Line Type Linux (#12364)
Fix(GCodeViewer): Resolve z-fighting for wipe, seam, and retract markers using shader depth bias Co-authored-by: SoftFever <softfeverever@gmail.com>
This commit is contained in:
@@ -90,7 +90,10 @@ static const char* Segments_Vertex_Shader =
|
||||
" );\n"
|
||||
" int id = vertex_id < 4 ? id_a : id_b;\n"
|
||||
" vec3 endpoint_pos = vertex_id < 4 ? pos_a : pos_b;\n"
|
||||
" vec3 height_width_angle = texelFetch(height_width_angle_tex, id).xyz;\n"
|
||||
" vec4 hwa = texelFetch(height_width_angle_tex, id);\n"
|
||||
" vec3 height_width_angle = hwa.xyz;\n"
|
||||
" // ORCA: Extract bias from w component\n"
|
||||
" float bias = hwa.w;\n"
|
||||
"#ifdef FIX_TWISTING\n"
|
||||
" int closer_id = (dot(camera_position - pos_a, camera_position - pos_a) < dot(camera_position - pos_b, camera_position - pos_b)) ? id_a : id_b;\n"
|
||||
" vec3 closer_pos = (closer_id == id_a) ? pos_a : pos_b;\n"
|
||||
@@ -131,6 +134,8 @@ static const char* Segments_Vertex_Shader =
|
||||
" }\n"
|
||||
" }\n"
|
||||
" vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;\n"
|
||||
" // ORCA: Apply bias to z-position to avoid z-fighting\n"
|
||||
" eye_position.z += bias;\n"
|
||||
" vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.0)).xyz;\n"
|
||||
" vec3 color_base = decode_color(texelFetch(color_tex, id).r);\n"
|
||||
" color = color_base * lighting(eye_position, eye_normal);\n"
|
||||
@@ -155,9 +160,11 @@ static const char* Options_Vertex_Shader =
|
||||
"const float light_front_diffuse = 0.6 * 0.3;\n"
|
||||
"const float ambient = 0.3;\n"
|
||||
"const float emission = 0.25;\n"
|
||||
#ifndef _WIN32
|
||||
#ifdef __APPLE__
|
||||
// ORCA: Use smaller scaling factor for macOS
|
||||
"const float scaling_factor = 0.75;\n"
|
||||
#else
|
||||
// ORCA: Increase seam marker size to 1.5 for Windows and Linux
|
||||
"const float scaling_factor = 1.5;\n"
|
||||
#endif
|
||||
"uniform mat4 view_matrix;\n"
|
||||
@@ -185,7 +192,10 @@ static const char* Options_Vertex_Shader =
|
||||
"}\n"
|
||||
"void main() {\n"
|
||||
" int id = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n"
|
||||
" vec2 height_width = texelFetch(height_width_angle_tex, id).xy;\n"
|
||||
" vec4 hwa = texelFetch(height_width_angle_tex, id);\n"
|
||||
" vec2 height_width = hwa.xy;\n"
|
||||
" // ORCA: Extract bias from w component\n"
|
||||
" float bias = hwa.w;\n"
|
||||
" vec3 offset = texelFetch(position_tex, id).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n"
|
||||
" height_width *= scaling_factor;\n"
|
||||
" mat3 scale_matrix = mat3(\n"
|
||||
@@ -193,6 +203,8 @@ static const char* Options_Vertex_Shader =
|
||||
" 0.0, height_width.y, 0.0,\n"
|
||||
" 0.0, 0.0, height_width.x);\n"
|
||||
" vec3 eye_position = (view_matrix * vec4(scale_matrix * in_position + offset, 1.0)).xyz;\n"
|
||||
" // ORCA: Apply bias to z-position to avoid z-fighting\n"
|
||||
" eye_position.z += bias;\n"
|
||||
" vec3 eye_normal = (view_matrix * vec4(in_normal, 0.0)).xyz;\n"
|
||||
" vec3 color_base = decode_color(texelFetch(color_tex, id).r);\n"
|
||||
" color = color_base * lighting(eye_position, eye_normal);\n"
|
||||
|
||||
@@ -966,9 +966,18 @@ static void extract_pos_and_or_hwa(const std::vector<PathVertex>& vertices, floa
|
||||
height = v.height;
|
||||
width = v.width;
|
||||
}
|
||||
|
||||
// ORCA: Set bias for wipes and options to avoid z-fighting
|
||||
float bias = 0.0f;
|
||||
if (v.is_wipe())
|
||||
bias = 0.05f;
|
||||
else if (v.is_option())
|
||||
bias = 0.1f;
|
||||
|
||||
// the last component is a dummy float to comply with GL_RGBA32F format
|
||||
// ORCA: Pass bias to shader
|
||||
heights_widths_angles->push_back({ height, width,
|
||||
std::atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line)), 0.0f });
|
||||
std::atan2(prev_line[0] * this_line[1] - prev_line[1] * this_line[0], dot(prev_line, this_line)), bias });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user