From 9217141b65a102364e37722f879ea0c928384898 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 26 Feb 2024 15:25:27 +0100 Subject: [PATCH] libvgcode - small refactoring in shaders --- src/libvgcode/src/Shaders.hpp | 44 ++++++++++++++++---------------- src/libvgcode/src/ShadersES.hpp | 44 ++++++++++++++++---------------- src/libvgcode/src/ViewerImpl.cpp | 16 ++++++------ 3 files changed, 52 insertions(+), 52 deletions(-) diff --git a/src/libvgcode/src/Shaders.hpp b/src/libvgcode/src/Shaders.hpp index cb6aac19d3..f37f2da1aa 100644 --- a/src/libvgcode/src/Shaders.hpp +++ b/src/libvgcode/src/Shaders.hpp @@ -26,10 +26,10 @@ static const char* Segments_Vertex_Shader = "uniform mat4 view_matrix;\n" "uniform mat4 projection_matrix;\n" "uniform vec3 camera_position;\n" -"uniform samplerBuffer positionsTex;\n" -"uniform samplerBuffer heightWidthAngleTex;\n" -"uniform samplerBuffer colorsTex;\n" -"uniform isamplerBuffer segmentIndexTex;\n" +"uniform samplerBuffer position_tex;\n" +"uniform samplerBuffer height_width_angle_tex;\n" +"uniform samplerBuffer color_tex;\n" +"uniform usamplerBuffer segment_index_tex;\n" "in int vertex_id;\n" "out vec3 color;\n" "vec3 decode_color(float color) {\n" @@ -47,10 +47,10 @@ static const char* Segments_Vertex_Shader = " return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" "}\n" "void main() {\n" -" int id_a = texelFetch(segmentIndexTex, gl_InstanceID).r;\n" +" int id_a = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n" " int id_b = id_a + 1;\n" -" vec3 pos_a = texelFetch(positionsTex, id_a).xyz;\n" -" vec3 pos_b = texelFetch(positionsTex, id_b).xyz;\n" +" vec3 pos_a = texelFetch(position_tex, id_a).xyz;\n" +" vec3 pos_b = texelFetch(position_tex, id_b).xyz;\n" " vec3 line = pos_b - pos_a;\n" " // directions of the line box in world space\n" " float line_len = length(line);\n" @@ -90,12 +90,12 @@ 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(heightWidthAngleTex, id).xyz;\n" +" vec3 height_width_angle = texelFetch(height_width_angle_tex, id).xyz;\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" " vec3 camera_view_dir = normalize(closer_pos - camera_position);\n" -" vec3 closer_height_width_angle = texelFetch(heightWidthAngleTex, closer_id).xyz;\n" +" vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, closer_id).xyz;\n" " vec3 diagonal_dir_border = normalize(closer_height_width_angle.x * line_up_dir + closer_height_width_angle.y * line_right_dir);\n" "#else\n" " vec3 camera_view_dir = normalize(endpoint_pos - camera_position);\n" @@ -132,7 +132,7 @@ static const char* Segments_Vertex_Shader = " }\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 color_base = decode_color(texelFetch(colorsTex, id).x);\n" +" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n" " color = color_base * lighting(eye_position, eye_normal);\n" " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" "}\n"; @@ -140,9 +140,9 @@ static const char* Segments_Vertex_Shader = static const char* Segments_Fragment_Shader = "#version 150\n" "in vec3 color;\n" -"out vec4 fragmentColor;\n" +"out vec4 fragment_color;\n" "void main() {\n" -" fragmentColor = vec4(color, 1.0);\n" +" fragment_color = vec4(color, 1.0);\n" "}\n"; static const char* Options_Vertex_Shader = @@ -158,10 +158,10 @@ static const char* Options_Vertex_Shader = "const float scaling_factor = 1.5;\n" "uniform mat4 view_matrix;\n" "uniform mat4 projection_matrix;\n" -"uniform samplerBuffer positionsTex;\n" -"uniform samplerBuffer heightWidthAngleTex;\n" -"uniform samplerBuffer colorsTex;\n" -"uniform isamplerBuffer segmentIndexTex;\n" +"uniform samplerBuffer position_tex;\n" +"uniform samplerBuffer height_width_angle_tex;\n" +"uniform samplerBuffer color_tex;\n" +"uniform usamplerBuffer segment_index_tex;\n" "in vec3 in_position;\n" "in vec3 in_normal;\n" "out vec3 color;\n" @@ -180,9 +180,9 @@ static const char* Options_Vertex_Shader = " return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" "}\n" "void main() {\n" -" int id = texelFetch(segmentIndexTex, gl_InstanceID).r;\n" -" vec2 height_width = texelFetch(heightWidthAngleTex, id).xy;\n" -" vec3 offset = texelFetch(positionsTex, id).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n" +" int id = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n" +" vec2 height_width = texelFetch(height_width_angle_tex, id).xy;\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" " height_width.y, 0.0, 0.0,\n" @@ -190,7 +190,7 @@ static const char* Options_Vertex_Shader = " 0.0, 0.0, height_width.x);\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 color_base = decode_color(texelFetch(colorsTex, id).x);\n" +" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n" " color = color_base * lighting(eye_position, eye_normal);\n" " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" "}\n"; @@ -198,9 +198,9 @@ static const char* Options_Vertex_Shader = static const char* Options_Fragment_Shader = "#version 150\n" "in vec3 color;\n" -"out vec4 fragmentColor;\n" +"out vec4 fragment_color;\n" "void main() {\n" -" fragmentColor = vec4(color, 1.0);\n" +" fragment_color = vec4(color, 1.0);\n" "}\n"; #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS diff --git a/src/libvgcode/src/ShadersES.hpp b/src/libvgcode/src/ShadersES.hpp index 37825e2ee1..4ec4838a81 100644 --- a/src/libvgcode/src/ShadersES.hpp +++ b/src/libvgcode/src/ShadersES.hpp @@ -26,10 +26,10 @@ static const char* Segments_Vertex_Shader_ES = "uniform mat4 view_matrix;\n" "uniform mat4 projection_matrix;\n" "uniform vec3 camera_position;\n" -"uniform samplerBuffer positionsTex;\n" -"uniform samplerBuffer heightWidthAngleTex;\n" -"uniform samplerBuffer colorsTex;\n" -"uniform isamplerBuffer segmentIndexTex;\n" +"uniform samplerBuffer position_tex;\n" +"uniform samplerBuffer height_width_angle_tex;\n" +"uniform samplerBuffer color_tex;\n" +"uniform usamplerBuffer segment_index_tex;\n" "in int vertex_id;\n" "out vec3 color;\n" "vec3 decode_color(float color) {\n" @@ -47,10 +47,10 @@ static const char* Segments_Vertex_Shader_ES = " return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" "}\n" "void main() {\n" -" int id_a = texelFetch(segmentIndexTex, gl_InstanceID).r;\n" +" int id_a = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n" " int id_b = id_a + 1;\n" -" vec3 pos_a = texelFetch(positionsTex, id_a).xyz;\n" -" vec3 pos_b = texelFetch(positionsTex, id_b).xyz;\n" +" vec3 pos_a = texelFetch(position_tex, id_a).xyz;\n" +" vec3 pos_b = texelFetch(position_tex, id_b).xyz;\n" " vec3 line = pos_b - pos_a;\n" " // directions of the line box in world space\n" " float line_len = length(line);\n" @@ -90,12 +90,12 @@ static const char* Segments_Vertex_Shader_ES = " );\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(heightWidthAngleTex, id).xyz;\n" +" vec3 height_width_angle = texelFetch(height_width_angle_tex, id).xyz;\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" " vec3 camera_view_dir = normalize(closer_pos - camera_position);\n" -" vec3 closer_height_width_angle = texelFetch(heightWidthAngleTex, closer_id).xyz;\n" +" vec3 closer_height_width_angle = texelFetch(height_width_angle_tex, closer_id).xyz;\n" " vec3 diagonal_dir_border = normalize(closer_height_width_angle.x * line_up_dir + closer_height_width_angle.y * line_right_dir);\n" "#else\n" " vec3 camera_view_dir = normalize(endpoint_pos - camera_position);\n" @@ -132,7 +132,7 @@ static const char* Segments_Vertex_Shader_ES = " }\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 color_base = decode_color(texelFetch(colorsTex, id).x);\n" +" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n" " color = color_base * lighting(eye_position, eye_normal);\n" " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" "}\n"; @@ -141,9 +141,9 @@ static const char* Segments_Fragment_Shader_ES = "#version 300 es\n" "precision highp float;\n" "in vec3 color;\n" -"out vec4 fragmentColor;\n" +"out vec4 fragment_color;\n" "void main() {\n" -" fragmentColor = vec4(color, 1.0);\n" +" fragment_color = vec4(color, 1.0);\n" "}\n"; static const char* Options_Vertex_Shader_ES = @@ -159,10 +159,10 @@ static const char* Options_Vertex_Shader_ES = "const float scaling_factor = 1.5;\n" "uniform mat4 view_matrix;\n" "uniform mat4 projection_matrix;\n" -"uniform samplerBuffer positionsTex;\n" -"uniform samplerBuffer heightWidthAngleTex;\n" -"uniform samplerBuffer colorsTex;\n" -"uniform isamplerBuffer segmentIndexTex;\n" +"uniform samplerBuffer position_tex;\n" +"uniform samplerBuffer height_width_angle_tex;\n" +"uniform samplerBuffer color_tex;\n" +"uniform usamplerBuffer segment_index_tex;\n" "in vec3 in_position;\n" "in vec3 in_normal;\n" "out vec3 color;\n" @@ -181,9 +181,9 @@ static const char* Options_Vertex_Shader_ES = " return ambient + top_diffuse + front_diffuse + top_specular + emission;\n" "}\n" "void main() {\n" -" int id = texelFetch(segmentIndexTex, gl_InstanceID).r;\n" -" vec2 height_width = texelFetch(heightWidthAngleTex, id).xy;\n" -" vec3 offset = texelFetch(positionsTex, id).xyz - vec3(0.0, 0.0, 0.5 * height_width.x);\n" +" int id = int(texelFetch(segment_index_tex, gl_InstanceID).r);\n" +" vec2 height_width = texelFetch(height_width_angle_tex, id).xy;\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" " height_width.y, 0.0, 0.0,\n" @@ -191,7 +191,7 @@ static const char* Options_Vertex_Shader_ES = " 0.0, 0.0, height_width.x);\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 color_base = decode_color(texelFetch(colorsTex, id).x);\n" +" vec3 color_base = decode_color(texelFetch(color_tex, id).x);\n" " color = color_base * lighting(eye_position, eye_normal);\n" " gl_Position = projection_matrix * vec4(eye_position, 1.0);\n" "}\n"; @@ -200,9 +200,9 @@ static const char* Options_Fragment_Shader_ES = "#version 300 es\n" "precision highp float;\n" "in vec3 color;\n" -"out vec4 fragmentColor;\n" +"out vec4 fragment_color;\n" "void main() {\n" -" fragmentColor = vec4(color, 1.0);\n" +" fragment_color = vec4(color, 1.0);\n" "}\n"; #if VGCODE_ENABLE_COG_AND_TOOL_MARKERS diff --git a/src/libvgcode/src/ViewerImpl.cpp b/src/libvgcode/src/ViewerImpl.cpp index 4229ef22db..a57d3dce18 100644 --- a/src/libvgcode/src/ViewerImpl.cpp +++ b/src/libvgcode/src/ViewerImpl.cpp @@ -341,10 +341,10 @@ void ViewerImpl::init(const std::string& opengl_context_version) m_uni_segments_view_matrix_id = glGetUniformLocation(m_segments_shader_id, "view_matrix"); m_uni_segments_projection_matrix_id = glGetUniformLocation(m_segments_shader_id, "projection_matrix"); m_uni_segments_camera_position_id = glGetUniformLocation(m_segments_shader_id, "camera_position"); - m_uni_segments_positions_tex_id = glGetUniformLocation(m_segments_shader_id, "positionsTex"); - m_uni_segments_height_width_angle_tex_id = glGetUniformLocation(m_segments_shader_id, "heightWidthAngleTex"); - m_uni_segments_colors_tex_id = glGetUniformLocation(m_segments_shader_id, "colorsTex"); - m_uni_segments_segment_index_tex_id = glGetUniformLocation(m_segments_shader_id, "segmentIndexTex"); + m_uni_segments_positions_tex_id = glGetUniformLocation(m_segments_shader_id, "position_tex"); + m_uni_segments_height_width_angle_tex_id = glGetUniformLocation(m_segments_shader_id, "height_width_angle_tex"); + m_uni_segments_colors_tex_id = glGetUniformLocation(m_segments_shader_id, "color_tex"); + m_uni_segments_segment_index_tex_id = glGetUniformLocation(m_segments_shader_id, "segment_index_tex"); glcheck(); assert(m_uni_segments_view_matrix_id != -1 && m_uni_segments_projection_matrix_id != -1 && @@ -363,10 +363,10 @@ void ViewerImpl::init(const std::string& opengl_context_version) m_uni_options_view_matrix_id = glGetUniformLocation(m_options_shader_id, "view_matrix"); m_uni_options_projection_matrix_id = glGetUniformLocation(m_options_shader_id, "projection_matrix"); - m_uni_options_positions_tex_id = glGetUniformLocation(m_options_shader_id, "positionsTex"); - m_uni_options_height_width_angle_tex_id = glGetUniformLocation(m_options_shader_id, "heightWidthAngleTex"); - m_uni_options_colors_tex_id = glGetUniformLocation(m_options_shader_id, "colorsTex"); - m_uni_options_segment_index_tex_id = glGetUniformLocation(m_options_shader_id, "segmentIndexTex"); + m_uni_options_positions_tex_id = glGetUniformLocation(m_options_shader_id, "position_tex"); + m_uni_options_height_width_angle_tex_id = glGetUniformLocation(m_options_shader_id, "height_width_angle_tex"); + m_uni_options_colors_tex_id = glGetUniformLocation(m_options_shader_id, "color_tex"); + m_uni_options_segment_index_tex_id = glGetUniformLocation(m_options_shader_id, "segment_index_tex"); glcheck(); assert(m_uni_options_view_matrix_id != -1 && m_uni_options_projection_matrix_id != -1 &&