From 2a65bc90607c1b5e9b1beb460bc81a448b011427 Mon Sep 17 00:00:00 2001 From: tome9111991 <57866234+tome9111991@users.noreply.github.com> Date: Sat, 10 Jan 2026 19:33:34 +0100 Subject: [PATCH] Fix dark color rendering in G-code preview by using additive specular lighting --- src/libvgcode/src/Shaders.hpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/libvgcode/src/Shaders.hpp b/src/libvgcode/src/Shaders.hpp index 826f9a4805..2d9b293724 100644 --- a/src/libvgcode/src/Shaders.hpp +++ b/src/libvgcode/src/Shaders.hpp @@ -40,11 +40,13 @@ static const char* Segments_Vertex_Shader = " float f = 1.0 / 255.0f;\n" " return f * vec3(r, g, b);\n" "}\n" -"float lighting(vec3 eye_position, vec3 eye_normal) {\n" +"float get_diffuse(vec3 eye_normal) {\n" " float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);\n" " float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);\n" -" float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" -" return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" +" return ambient + top_diffuse + front_diffuse + emission;\n" +"}\n" +"float get_specular(vec3 eye_position, vec3 eye_normal) {\n" +" return light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" "}\n" "void main() {\n" " int id_a = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n" @@ -133,7 +135,7 @@ static const char* Segments_Vertex_Shader = " vec3 eye_position = (view_matrix * vec4(pos, 1.0)).xyz;\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" +" color = color_base * get_diffuse(eye_normal) + vec3(get_specular(eye_position, eye_normal));\n" " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" "}\n"; @@ -177,11 +179,13 @@ static const char* Options_Vertex_Shader = " float f = 1.0 / 255.0f;\n" " return f * vec3(r, g, b);\n" "}\n" -"float lighting(vec3 eye_position, vec3 eye_normal) {\n" +"float get_diffuse(vec3 eye_normal) {\n" " float top_diffuse = light_top_diffuse * max(dot(eye_normal, light_top_dir), 0.0);\n" " float front_diffuse = light_front_diffuse * max(dot(eye_normal, light_front_dir), 0.0);\n" -" float top_specular = light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" -" return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" +" return ambient + top_diffuse + front_diffuse + emission;\n" +"}\n" +"float get_specular(vec3 eye_position, vec3 eye_normal) {\n" +" return light_top_specular * pow(max(dot(-normalize(eye_position), reflect(-light_top_dir, eye_normal)), 0.0), light_top_shininess);\n" "}\n" "void main() {\n" " int id = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n" @@ -195,7 +199,7 @@ static const char* Options_Vertex_Shader = " vec3 eye_position = (view_matrix * vec4(scale_matrix * in_position + offset, 1.0)).xyz;\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" +" color = color_base * get_diffuse(eye_normal) + vec3(get_specular(eye_position, eye_normal));\n" " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" "}\n";