mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
ENABLE_GCODE_VIEWER -> Refactoring of shaders for options
This commit is contained in:
parent
e9d57c932a
commit
dcec684cc7
8 changed files with 67 additions and 72 deletions
|
@ -1,4 +1,4 @@
|
||||||
#version 120
|
#version 110
|
||||||
|
|
||||||
uniform vec3 uniform_color;
|
uniform vec3 uniform_color;
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#version 110
|
#version 110
|
||||||
|
|
||||||
uniform float zoom;
|
uniform float zoom;
|
||||||
// x = min, y = max
|
uniform float point_size;
|
||||||
uniform vec2 point_sizes;
|
uniform float near_plane_height;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_PointSize = clamp(zoom, point_sizes.x, point_sizes.y);
|
gl_Position = ftransform();
|
||||||
gl_Position = ftransform();
|
gl_PointSize = (gl_Position.w == 1.0) ? zoom * near_plane_height * point_size : near_plane_height * point_size / gl_Position.w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,31 +5,31 @@ uniform vec3 uniform_color;
|
||||||
uniform float percent_outline_radius;
|
uniform float percent_outline_radius;
|
||||||
uniform float percent_center_radius;
|
uniform float percent_center_radius;
|
||||||
|
|
||||||
vec4 hardcoded_color(float sq_radius)
|
vec4 hardcoded_color(float sq_radius, vec3 color)
|
||||||
{
|
{
|
||||||
if ((sq_radius < 0.005625) || (sq_radius > 0.180625))
|
if ((sq_radius < 0.005625) || (sq_radius > 0.180625))
|
||||||
return vec4(0.5 * uniform_color, 1.0);
|
return vec4(0.5 * color, 1.0);
|
||||||
else
|
else
|
||||||
return vec4(uniform_color, 1.0);
|
return vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 customizable_color(float sq_radius)
|
vec4 customizable_color(float sq_radius, vec3 color)
|
||||||
{
|
{
|
||||||
float in_radius = 0.5 * percent_center_radius;
|
float in_radius = 0.5 * percent_center_radius;
|
||||||
float out_radius = 0.5 * (1.0 - percent_outline_radius);
|
float out_radius = 0.5 * (1.0 - percent_outline_radius);
|
||||||
if ((sq_radius < in_radius * in_radius) || (sq_radius > out_radius * out_radius))
|
if ((sq_radius < in_radius * in_radius) || (sq_radius > out_radius * out_radius))
|
||||||
return vec4(0.5 * uniform_color, 1.0);
|
return vec4(0.5 * color, 1.0);
|
||||||
else
|
else
|
||||||
return vec4(uniform_color, 1.0);
|
return vec4(color, 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 pos = gl_PointCoord - vec2(0.5, 0.5);
|
vec2 pos = gl_PointCoord - vec2(0.5);
|
||||||
float sq_radius = dot(pos, pos);
|
float sq_radius = dot(pos, pos);
|
||||||
if (sq_radius > 0.25)
|
if (sq_radius > 0.25)
|
||||||
discard;
|
discard;
|
||||||
|
|
||||||
gl_FragColor = customizable_color(sq_radius);
|
gl_FragColor = customizable_color(sq_radius, uniform_color);
|
||||||
// gl_FragColor = hardcoded_color(sq_radius);
|
// gl_FragColor = hardcoded_color(sq_radius, uniform_color);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
uniform float zoom;
|
uniform float zoom;
|
||||||
// x = min, y = max
|
uniform float point_size;
|
||||||
uniform vec2 point_sizes;
|
uniform float near_plane_height;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_PointSize = clamp(zoom, point_sizes.x, point_sizes.y);
|
gl_Position = ftransform();
|
||||||
gl_Position = ftransform();
|
gl_PointSize = (gl_Position.w == 1.0) ? zoom * near_plane_height * point_size : near_plane_height * point_size / gl_Position.w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ float fragment_depth(vec3 eye_pos)
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 pos = gl_PointCoord - vec2(0.5, 0.5);
|
vec2 pos = gl_PointCoord - vec2(0.5);
|
||||||
float sq_radius = dot(pos, pos);
|
float sq_radius = dot(pos, pos);
|
||||||
if (sq_radius > 0.25)
|
if (sq_radius > 0.25)
|
||||||
discard;
|
discard;
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#version 120
|
#version 120
|
||||||
|
|
||||||
uniform float zoom;
|
uniform float zoom;
|
||||||
// x = min, y = max
|
uniform float point_size;
|
||||||
uniform vec2 point_sizes;
|
uniform float near_plane_height;
|
||||||
|
|
||||||
varying vec3 eye_center;
|
varying vec3 eye_center;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_PointSize = clamp(zoom, point_sizes.x, point_sizes.y);
|
|
||||||
eye_center = (gl_ModelViewMatrix * gl_Vertex).xyz;
|
eye_center = (gl_ModelViewMatrix * gl_Vertex).xyz;
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
|
gl_PointSize = (gl_Position.w == 1.0) ? zoom * near_plane_height * point_size : near_plane_height * point_size / gl_Position.w;
|
||||||
}
|
}
|
||||||
|
|
|
@ -756,40 +756,36 @@ void GCodeViewer::refresh_render_paths(bool keep_sequential_current_first, bool
|
||||||
void GCodeViewer::render_toolpaths() const
|
void GCodeViewer::render_toolpaths() const
|
||||||
{
|
{
|
||||||
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||||
bool is_glsl_120 = m_shaders_editor.shader_version >= 1 && wxGetApp().is_glsl_version_greater_or_equal_to(1, 20);
|
float point_size = m_shaders_editor.point_size;
|
||||||
std::array<float, 2> point_sizes;
|
|
||||||
if (m_shaders_editor.size_dependent_on_zoom)
|
|
||||||
point_sizes = { std::min(static_cast<float>(m_shaders_editor.sizes[0]), m_detected_point_sizes[1]), std::min(static_cast<float>(m_shaders_editor.sizes[1]), m_detected_point_sizes[1]) };
|
|
||||||
else
|
|
||||||
point_sizes = { static_cast<float>(m_shaders_editor.fixed_size), static_cast<float>(m_shaders_editor.fixed_size) };
|
|
||||||
#else
|
#else
|
||||||
bool is_glsl_120 = wxGetApp().is_glsl_version_greater_or_equal_to(1, 20);
|
float point_size = 1.0f;
|
||||||
std::array<float, 2> point_sizes = { std::min(8.0f, m_detected_point_sizes[1]), std::min(48.0f, m_detected_point_sizes[1]) };
|
|
||||||
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||||
const Camera& camera = wxGetApp().plater()->get_camera();
|
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||||
double zoom = camera.get_zoom();
|
double zoom = camera.get_zoom();
|
||||||
const std::array<int, 4>& viewport = camera.get_viewport();
|
const std::array<int, 4>& viewport = camera.get_viewport();
|
||||||
std::array<int, 2> viewport_sizes = { viewport[2], viewport[3] };
|
std::array<int, 2> viewport_sizes = { viewport[2], viewport[3] };
|
||||||
|
float near_plane_height = camera.get_type() == Camera::Perspective ? static_cast<float>(viewport[3]) / (2.0f * static_cast<float>(2.0 * std::tan(0.5 * Geometry::deg2rad(camera.get_fov())))) :
|
||||||
|
static_cast<float>(viewport[3]) * 0.0005;
|
||||||
|
|
||||||
Transform3d inv_proj = camera.get_projection_matrix().inverse();
|
Transform3d inv_proj = camera.get_projection_matrix().inverse();
|
||||||
|
|
||||||
auto render_options = [this, is_glsl_120, zoom, viewport, inv_proj, viewport_sizes, point_sizes](const IBuffer& buffer, EOptionsColors colors_id, GLShaderProgram& shader) {
|
auto render_options = [this, zoom, inv_proj, viewport_sizes, point_size, near_plane_height](const IBuffer& buffer, EOptionsColors colors_id, GLShaderProgram& shader) {
|
||||||
shader.set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(colors_id)]);
|
shader.set_uniform("uniform_color", Options_Colors[static_cast<unsigned int>(colors_id)]);
|
||||||
|
shader.set_uniform("zoom", zoom);
|
||||||
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||||
shader.set_uniform("zoom", m_shaders_editor.size_dependent_on_zoom ? zoom : 1.0f);
|
|
||||||
shader.set_uniform("percent_outline_radius", 0.01f * static_cast<float>(m_shaders_editor.percent_outline));
|
shader.set_uniform("percent_outline_radius", 0.01f * static_cast<float>(m_shaders_editor.percent_outline));
|
||||||
shader.set_uniform("percent_center_radius", 0.01f * static_cast<float>(m_shaders_editor.percent_center));
|
shader.set_uniform("percent_center_radius", 0.01f * static_cast<float>(m_shaders_editor.percent_center));
|
||||||
#else
|
#else
|
||||||
shader.set_uniform("zoom", zoom);
|
|
||||||
shader.set_uniform("percent_outline_radius", 0.15f);
|
shader.set_uniform("percent_outline_radius", 0.15f);
|
||||||
shader.set_uniform("percent_center_radius", 0.15f);
|
shader.set_uniform("percent_center_radius", 0.15f);
|
||||||
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||||
shader.set_uniform("viewport_sizes", viewport_sizes);
|
shader.set_uniform("viewport_sizes", viewport_sizes);
|
||||||
shader.set_uniform("inv_proj_matrix", inv_proj);
|
shader.set_uniform("inv_proj_matrix", inv_proj);
|
||||||
shader.set_uniform("point_sizes", point_sizes);
|
shader.set_uniform("point_size", point_size);
|
||||||
|
shader.set_uniform("near_plane_height", near_plane_height);
|
||||||
|
|
||||||
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
|
glsafe(::glEnable(GL_VERTEX_PROGRAM_POINT_SIZE));
|
||||||
if (is_glsl_120)
|
glsafe(::glEnable(GL_POINT_SPRITE));
|
||||||
glsafe(::glEnable(GL_POINT_SPRITE));
|
|
||||||
|
|
||||||
for (const RenderPath& path : buffer.render_paths) {
|
for (const RenderPath& path : buffer.render_paths) {
|
||||||
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
glsafe(::glMultiDrawElements(GL_POINTS, (const GLsizei*)path.sizes.data(), GL_UNSIGNED_INT, (const void* const*)path.offsets.data(), (GLsizei)path.sizes.size()));
|
||||||
|
@ -797,9 +793,8 @@ void GCodeViewer::render_toolpaths() const
|
||||||
++m_statistics.gl_multi_points_calls_count;
|
++m_statistics.gl_multi_points_calls_count;
|
||||||
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
#endif // ENABLE_GCODE_VIEWER_STATISTICS
|
||||||
}
|
}
|
||||||
if (is_glsl_120)
|
|
||||||
glsafe(::glDisable(GL_POINT_SPRITE));
|
glsafe(::glDisable(GL_POINT_SPRITE));
|
||||||
|
|
||||||
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
|
glsafe(::glDisable(GL_VERTEX_PROGRAM_POINT_SIZE));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -964,31 +959,49 @@ void GCodeViewer::render_legend() const
|
||||||
{
|
{
|
||||||
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||||
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size));
|
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size));
|
||||||
draw_list->AddCircle(center, 0.5f * icon_size, ICON_BORDER_COLOR, 16);
|
|
||||||
if (m_shaders_editor.shader_version == 1) {
|
if (m_shaders_editor.shader_version == 1) {
|
||||||
draw_list->AddCircleFilled(center, (0.5f * icon_size) - 2.0f,
|
draw_list->AddCircleFilled(center, 0.5f * icon_size,
|
||||||
ImGui::GetColorU32({ 0.5f * color[0], 0.5f * color[1], 0.5f * color[2], 1.0f }), 16);
|
ImGui::GetColorU32({ 0.5f * color[0], 0.5f * color[1], 0.5f * color[2], 1.0f }), 16);
|
||||||
float radius = ((0.5f * icon_size) - 2.0f) * (1.0f - 0.01f * static_cast<float>(m_shaders_editor.percent_outline));
|
float radius = 0.5f * icon_size * (1.0f - 0.01f * static_cast<float>(m_shaders_editor.percent_outline));
|
||||||
draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||||
if (m_shaders_editor.percent_center > 0) {
|
if (m_shaders_editor.percent_center > 0) {
|
||||||
radius = ((0.5f * icon_size) - 2.0f) * 0.01f * static_cast<float>(m_shaders_editor.percent_center);
|
radius = 0.5f * icon_size * 0.01f * static_cast<float>(m_shaders_editor.percent_center);
|
||||||
draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32({ 0.5f * color[0], 0.5f * color[1], 0.5f * color[2], 1.0f }), 16);
|
draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32({ 0.5f * color[0], 0.5f * color[1], 0.5f * color[2], 1.0f }), 16);
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
draw_list->AddCircleFilled(center, (0.5f * icon_size) - 2.0f, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
else
|
||||||
|
draw_list->AddCircleFilled(center, 0.5f * icon_size, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||||
|
|
||||||
|
// ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size));
|
||||||
|
// draw_list->AddCircle(center, 0.5f * icon_size, ICON_BORDER_COLOR, 16);
|
||||||
|
// if (m_shaders_editor.shader_version == 1) {
|
||||||
|
// draw_list->AddCircleFilled(center, (0.5f * icon_size) - 2.0f,
|
||||||
|
// ImGui::GetColorU32({ 0.5f * color[0], 0.5f * color[1], 0.5f * color[2], 1.0f }), 16);
|
||||||
|
// float radius = ((0.5f * icon_size) - 2.0f) * (1.0f - 0.01f * static_cast<float>(m_shaders_editor.percent_outline));
|
||||||
|
// draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||||
|
// if (m_shaders_editor.percent_center > 0) {
|
||||||
|
// radius = ((0.5f * icon_size) - 2.0f) * 0.01f * static_cast<float>(m_shaders_editor.percent_center);
|
||||||
|
// draw_list->AddCircleFilled(center, radius, ImGui::GetColorU32({ 0.5f * color[0], 0.5f * color[1], 0.5f * color[2], 1.0f }), 16);
|
||||||
|
// }
|
||||||
|
// } else
|
||||||
|
// draw_list->AddCircleFilled(center, (0.5f * icon_size) - 2.0f, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||||
#else
|
#else
|
||||||
draw_list->AddCircle({ 0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size) }, 0.5f * icon_size, ICON_BORDER_COLOR, 16);
|
draw_list->AddCircleFilled({ 0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size) }, 0.5f * icon_size,
|
||||||
draw_list->AddCircleFilled({ 0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size) }, (0.5f * icon_size) - 2.0f,
|
|
||||||
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||||
|
|
||||||
|
// draw_list->AddCircle({ 0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size) }, 0.5f * icon_size, ICON_BORDER_COLOR, 16);
|
||||||
|
// draw_list->AddCircleFilled({ 0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size) }, (0.5f * icon_size) - 2.0f,
|
||||||
|
// ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 16);
|
||||||
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EItemType::Hexagon:
|
case EItemType::Hexagon:
|
||||||
{
|
{
|
||||||
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size));
|
ImVec2 center(0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size));
|
||||||
draw_list->AddNgon(center, 0.5f * icon_size, ICON_BORDER_COLOR, 6);
|
draw_list->AddNgonFilled(center, 0.5f * icon_size, ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 6);
|
||||||
draw_list->AddNgonFilled({ 0.5f * (pos.x + pos.x + icon_size), 0.5f * (pos.y + pos.y + icon_size) }, (0.5f * icon_size) - 2.0f,
|
// draw_list->AddNgon(center, 0.5f * icon_size, ICON_BORDER_COLOR, 6);
|
||||||
ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 6);
|
// draw_list->AddNgonFilled(center, (0.5f * icon_size) - 2.0f,
|
||||||
|
// ImGui::GetColorU32({ color[0], color[1], color[2], 1.0f }), 6);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EItemType::Line:
|
case EItemType::Line:
|
||||||
|
@ -1409,23 +1422,7 @@ void GCodeViewer::render_shaders_editor() const
|
||||||
|
|
||||||
if (ImGui::CollapsingHeader("Options", ImGuiTreeNodeFlags_DefaultOpen))
|
if (ImGui::CollapsingHeader("Options", ImGuiTreeNodeFlags_DefaultOpen))
|
||||||
{
|
{
|
||||||
ImGui::Checkbox("size dependent on zoom", &m_shaders_editor.size_dependent_on_zoom);
|
ImGui::SliderFloat("point size", &m_shaders_editor.point_size, 0.5f, 1.5f, "%.1f");
|
||||||
if (m_shaders_editor.size_dependent_on_zoom)
|
|
||||||
{
|
|
||||||
if (ImGui::SliderInt("min size (min zoom)", &m_shaders_editor.sizes[0], 1, 100))
|
|
||||||
{
|
|
||||||
if (m_shaders_editor.sizes[1] < m_shaders_editor.sizes[0])
|
|
||||||
m_shaders_editor.sizes[1] = m_shaders_editor.sizes[0];
|
|
||||||
}
|
|
||||||
ImGui::SliderInt("max size (max zoom)", &m_shaders_editor.sizes[1], 1, 100);
|
|
||||||
{
|
|
||||||
if (m_shaders_editor.sizes[1] < m_shaders_editor.sizes[0])
|
|
||||||
m_shaders_editor.sizes[0] = m_shaders_editor.sizes[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ImGui::SliderInt("fixed size", &m_shaders_editor.fixed_size, 1, 100);
|
|
||||||
|
|
||||||
if (m_shaders_editor.shader_version == 1)
|
if (m_shaders_editor.shader_version == 1)
|
||||||
{
|
{
|
||||||
ImGui::SliderInt("percent outline", &m_shaders_editor.percent_outline, 0, 50);
|
ImGui::SliderInt("percent outline", &m_shaders_editor.percent_outline, 0, 50);
|
||||||
|
|
|
@ -206,9 +206,7 @@ class GCodeViewer
|
||||||
struct ShadersEditor
|
struct ShadersEditor
|
||||||
{
|
{
|
||||||
int shader_version{ 2 };
|
int shader_version{ 2 };
|
||||||
bool size_dependent_on_zoom{ true };
|
float point_size{ 1.0f };
|
||||||
int fixed_size{ 16 };
|
|
||||||
std::array<int, 2> sizes{ 3, 21 };
|
|
||||||
int percent_outline{ 0 };
|
int percent_outline{ 0 };
|
||||||
int percent_center{ 33 };
|
int percent_center{ 33 };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue