ENABLE_GCODE_VIEWER -> Improvements in shaders for options
This commit is contained in:
parent
71db69ef41
commit
707268d41d
3 changed files with 27 additions and 37 deletions
|
@ -5,31 +5,23 @@ uniform vec3 uniform_color;
|
|||
uniform float percent_outline_radius;
|
||||
uniform float percent_center_radius;
|
||||
|
||||
vec4 hardcoded_color(float sq_radius, vec3 color)
|
||||
vec4 hardcoded_color(float radius, vec3 color)
|
||||
{
|
||||
if ((sq_radius < 0.005625) || (sq_radius > 0.180625))
|
||||
return vec4(0.5 * color, 1.0);
|
||||
else
|
||||
return vec4(color, 1.0);
|
||||
return ((radius < 0.15) || (radius > 0.85)) ? vec4(0.5 * color, 1.0) : vec4(color, 1.0);
|
||||
}
|
||||
|
||||
vec4 customizable_color(float sq_radius, vec3 color)
|
||||
vec4 customizable_color(float radius, vec3 color)
|
||||
{
|
||||
float in_radius = 0.5 * percent_center_radius;
|
||||
float out_radius = 0.5 * (1.0 - percent_outline_radius);
|
||||
if ((sq_radius < in_radius * in_radius) || (sq_radius > out_radius * out_radius))
|
||||
return vec4(0.5 * color, 1.0);
|
||||
else
|
||||
return vec4(color, 1.0);
|
||||
return ((radius < percent_center_radius) || (radius > 1.0 - percent_outline_radius)) ?
|
||||
vec4(0.5 * color, 1.0) : vec4(color, 1.0);
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = gl_PointCoord - vec2(0.5);
|
||||
float sq_radius = dot(pos, pos);
|
||||
if (sq_radius > 0.25)
|
||||
vec2 pos = (gl_PointCoord - 0.5) * 2.0;
|
||||
float radius = length(pos);
|
||||
if (radius > 1.0)
|
||||
discard;
|
||||
|
||||
gl_FragColor = customizable_color(sq_radius, uniform_color);
|
||||
// gl_FragColor = hardcoded_color(sq_radius, uniform_color);
|
||||
gl_FragColor = customizable_color(radius, uniform_color);
|
||||
}
|
||||
|
|
|
@ -17,28 +17,26 @@ const vec3 LIGHT_FRONT_DIR = vec3(0.6985074, 0.1397015, 0.6985074);
|
|||
|
||||
uniform vec3 uniform_color;
|
||||
|
||||
// x = width, y = height
|
||||
uniform ivec2 viewport_sizes;
|
||||
uniform ivec4 viewport;
|
||||
uniform float point_size;
|
||||
uniform mat4 inv_proj_matrix;
|
||||
|
||||
varying vec3 eye_center;
|
||||
|
||||
float radius = 0.5;
|
||||
// x = tainted, y = specular;
|
||||
vec2 intensity;
|
||||
|
||||
float radius = 0.5 * point_size;
|
||||
|
||||
vec3 eye_position_from_fragment()
|
||||
{
|
||||
// Convert screen coordinates to normalized device coordinates (NDC)
|
||||
vec4 ndc = vec4(
|
||||
(gl_FragCoord.x / viewport_sizes.x - 0.5) * 2.0,
|
||||
(gl_FragCoord.y / viewport_sizes.y - 0.5) * 2.0,
|
||||
(gl_FragCoord.z - 0.5) * 2.0,
|
||||
1.0);
|
||||
|
||||
vec4 ndc = vec4((gl_FragCoord.x / viewport.z - 0.5) * 2.0,
|
||||
(gl_FragCoord.y / viewport.w - 0.5) * 2.0,
|
||||
(gl_FragCoord.z - 0.5) * 2.0,
|
||||
gl_FragCoord.w);
|
||||
// Convert NDC throuch inverse clip coordinates to view coordinates
|
||||
vec4 clip = inv_proj_matrix * ndc;
|
||||
return (clip / clip.w).xyz;
|
||||
return clip.xyz;
|
||||
}
|
||||
|
||||
vec3 eye_position_on_sphere(vec3 eye_fragment_position)
|
||||
|
@ -67,21 +65,22 @@ vec4 on_sphere_color(vec3 eye_on_sphere_position)
|
|||
NdotL = max(dot(eye_normal, LIGHT_FRONT_DIR), 0.0);
|
||||
intensity.x += NdotL * LIGHT_FRONT_DIFFUSE;
|
||||
|
||||
return vec4(vec3(intensity.y, intensity.y, intensity.y) + uniform_color.rgb * intensity.x, 1.0);
|
||||
return vec4(intensity + uniform_color.rgb * intensity.x, 1.0);
|
||||
// return vec4(vec3(intensity.y) + uniform_color.rgb * intensity.x, 1.0);
|
||||
}
|
||||
|
||||
float fragment_depth(vec3 eye_pos)
|
||||
{
|
||||
vec4 clip_pos = gl_ProjectionMatrix * vec4(eye_pos, 1.0);
|
||||
float ndc_depth = clip_pos.z / clip_pos.w;
|
||||
return (((gl_DepthRange.far - gl_DepthRange.near) * ndc_depth) + gl_DepthRange.near + gl_DepthRange.far) / 2.0;
|
||||
return ((gl_DepthRange.far - gl_DepthRange.near) * ndc_depth + gl_DepthRange.near + gl_DepthRange.far) / 2.0;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos = gl_PointCoord - vec2(0.5);
|
||||
float sq_radius = dot(pos, pos);
|
||||
if (sq_radius > 0.25)
|
||||
vec2 pos = (gl_PointCoord - 0.5) * 2.0;
|
||||
float radius = length(pos);
|
||||
if (radius > 1.0)
|
||||
discard;
|
||||
|
||||
vec3 eye_on_sphere_position = eye_position_on_sphere(eye_position_from_fragment());
|
||||
|
|
|
@ -763,13 +763,12 @@ void GCodeViewer::render_toolpaths() const
|
|||
const Camera& camera = wxGetApp().plater()->get_camera();
|
||||
double zoom = camera.get_zoom();
|
||||
const std::array<int, 4>& viewport = camera.get_viewport();
|
||||
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();
|
||||
|
||||
auto render_options = [this, zoom, inv_proj, viewport_sizes, point_size, near_plane_height](const IBuffer& buffer, EOptionsColors colors_id, GLShaderProgram& shader) {
|
||||
auto render_options = [this, zoom, inv_proj, viewport, 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("zoom", zoom);
|
||||
#if ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||
|
@ -779,7 +778,7 @@ void GCodeViewer::render_toolpaths() const
|
|||
shader.set_uniform("percent_outline_radius", 0.15f);
|
||||
shader.set_uniform("percent_center_radius", 0.15f);
|
||||
#endif // ENABLE_GCODE_VIEWER_SHADERS_EDITOR
|
||||
shader.set_uniform("viewport_sizes", viewport_sizes);
|
||||
shader.set_uniform("viewport", viewport);
|
||||
shader.set_uniform("inv_proj_matrix", inv_proj);
|
||||
shader.set_uniform("point_size", point_size);
|
||||
shader.set_uniform("near_plane_height", near_plane_height);
|
||||
|
@ -1422,7 +1421,7 @@ void GCodeViewer::render_shaders_editor() const
|
|||
|
||||
if (ImGui::CollapsingHeader("Options", ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::SliderFloat("point size", &m_shaders_editor.point_size, 0.5f, 1.5f, "%.1f");
|
||||
ImGui::SliderFloat("point size", &m_shaders_editor.point_size, 0.5f, 3.0f, "%.1f");
|
||||
if (m_shaders_editor.shader_version == 1)
|
||||
{
|
||||
ImGui::SliderInt("percent outline", &m_shaders_editor.percent_outline, 0, 50);
|
||||
|
|
Loading…
Reference in a new issue