mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-20 03:43:52 +00:00
Fix dark color rendering in G-code preview by using additive specular lighting
This commit is contained in:
@@ -40,11 +40,13 @@ static const char* Segments_Vertex_Shader =
|
|||||||
" float f = 1.0 / 255.0f;\n"
|
" float f = 1.0 / 255.0f;\n"
|
||||||
" return f * vec3(r, g, b);\n"
|
" return f * vec3(r, g, b);\n"
|
||||||
"}\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 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 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 + emission;\n"
|
||||||
" return ambient + top_diffuse + front_diffuse + top_specular + 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"
|
"}\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" int id_a = int(texelFetch(segment_index_tex, gl_InstanceID).r);\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_position = (view_matrix * vec4(pos, 1.0)).xyz;\n"
|
||||||
" vec3 eye_normal = (view_matrix * vec4(normalize(pos - endpoint_pos), 0.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"
|
" 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"
|
" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
@@ -177,11 +179,13 @@ static const char* Options_Vertex_Shader =
|
|||||||
" float f = 1.0 / 255.0f;\n"
|
" float f = 1.0 / 255.0f;\n"
|
||||||
" return f * vec3(r, g, b);\n"
|
" return f * vec3(r, g, b);\n"
|
||||||
"}\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 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 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 + emission;\n"
|
||||||
" return ambient + top_diffuse + front_diffuse + top_specular + 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"
|
"}\n"
|
||||||
"void main() {\n"
|
"void main() {\n"
|
||||||
" int id = int(texelFetch(segment_index_tex, gl_InstanceID).r);\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_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 eye_normal = (view_matrix * vec4(in_normal, 0.0)).xyz;\n"
|
||||||
" vec3 color_base = decode_color(texelFetch(color_tex, id).r);\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"
|
" gl_Position = projection_matrix * vec4(eye_position, 1.0);\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user