Tech ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES - Use vertex attributes and matrices in shaders.
Shader: flat - Gizmo SLA Supports points
This commit is contained in:
parent
3165a4d0d5
commit
a6e84aec20
@ -146,11 +146,11 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
|
|||||||
|
|
||||||
ColorRGBA render_color;
|
ColorRGBA render_color;
|
||||||
const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes;
|
const sla::DrainHoles& drain_holes = m_c->selection_info()->model_object()->sla_drain_holes;
|
||||||
size_t cache_size = drain_holes.size();
|
const size_t cache_size = drain_holes.size();
|
||||||
|
|
||||||
for (size_t i = 0; i < cache_size; ++i) {
|
for (size_t i = 0; i < cache_size; ++i) {
|
||||||
const sla::DrainHole& drain_hole = drain_holes[i];
|
const sla::DrainHole& drain_hole = drain_holes[i];
|
||||||
const bool& point_selected = m_selected[i];
|
const bool point_selected = m_selected[i];
|
||||||
|
|
||||||
if (is_mesh_point_clipped(drain_hole.pos.cast<double>()))
|
if (is_mesh_point_clipped(drain_hole.pos.cast<double>()))
|
||||||
continue;
|
continue;
|
||||||
@ -194,7 +194,7 @@ void GLGizmoHollow::render_points(const Selection& selection, bool picking)
|
|||||||
// Matrices set, we can render the point mark now.
|
// Matrices set, we can render the point mark now.
|
||||||
Eigen::Quaterniond q;
|
Eigen::Quaterniond q;
|
||||||
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
|
q.setFromTwoVectors(Vec3d::UnitZ(), instance_scaling_matrix_inverse * (-drain_hole.normal).cast<double>());
|
||||||
Eigen::AngleAxisd aa(q);
|
const Eigen::AngleAxisd aa(q);
|
||||||
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
if (use_attributes) {
|
if (use_attributes) {
|
||||||
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * instance_matrix *
|
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * instance_matrix *
|
||||||
|
@ -130,10 +130,18 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
#if ENABLE_GLBEGIN_GLEND_REMOVAL
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
GLShaderProgram* shader = picking ? wxGetApp().get_shader("flat_attr") : wxGetApp().get_shader("gouraud_light");
|
||||||
|
#else
|
||||||
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
|
GLShaderProgram* shader = wxGetApp().get_shader(picking ? "flat" : "gouraud_light");
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
if (shader == nullptr)
|
if (shader == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
bool use_attributes = boost::algorithm::iends_with(shader->get_name(), "_attr");
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
|
||||||
shader->start_using();
|
shader->start_using();
|
||||||
ScopeGuard guard([shader]() { shader->stop_using(); });
|
ScopeGuard guard([shader]() { shader->stop_using(); });
|
||||||
#else
|
#else
|
||||||
@ -148,12 +156,22 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
|||||||
|
|
||||||
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
|
const GLVolume* vol = selection.get_volume(*selection.get_volume_idxs().begin());
|
||||||
const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
|
const Transform3d instance_scaling_matrix_inverse = vol->get_instance_transformation().get_matrix(true, true, false, true).inverse();
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
const Transform3d instance_matrix = Geometry::assemble_transform(m_c->selection_info()->get_sla_shift() * Vec3d::UnitZ()) * vol->get_instance_transformation().get_matrix();
|
||||||
|
#else
|
||||||
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
|
const Transform3d& instance_matrix = vol->get_instance_transformation().get_matrix();
|
||||||
const float z_shift = m_c->selection_info()->get_sla_shift();
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (!use_attributes) {
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
const float z_shift = m_c->selection_info()->get_sla_shift();
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
glsafe(::glTranslated(0.0, 0.0, z_shift));
|
glsafe(::glTranslated(0.0, 0.0, z_shift));
|
||||||
glsafe(::glMultMatrixd(instance_matrix.data()));
|
glsafe(::glMultMatrixd(instance_matrix.data()));
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
}
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
|
||||||
ColorRGBA render_color;
|
ColorRGBA render_color;
|
||||||
for (size_t i = 0; i < cache_size; ++i) {
|
for (size_t i = 0; i < cache_size; ++i) {
|
||||||
@ -197,9 +215,16 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
|||||||
shader->set_uniform("emission_factor", 0.5f);
|
shader->set_uniform("emission_factor", 0.5f);
|
||||||
|
|
||||||
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
|
// Inverse matrix of the instance scaling is applied so that the mark does not scale with the object.
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
const Transform3d support_matrix = Geometry::assemble_transform(support_point.pos.cast<double>()) * instance_scaling_matrix_inverse;
|
||||||
|
if (!use_attributes) {
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
glsafe(::glPushMatrix());
|
glsafe(::glPushMatrix());
|
||||||
glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z()));
|
glsafe(::glTranslatef(support_point.pos.x(), support_point.pos.y(), support_point.pos.z()));
|
||||||
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
|
glsafe(::glMultMatrixd(instance_scaling_matrix_inverse.data()));
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
}
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
|
||||||
if (vol->is_left_handed())
|
if (vol->is_left_handed())
|
||||||
glFrontFace(GL_CW);
|
glFrontFace(GL_CW);
|
||||||
@ -214,24 +239,59 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
|||||||
Eigen::Quaterniond q;
|
Eigen::Quaterniond q;
|
||||||
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>());
|
q.setFromTwoVectors(Vec3d{0., 0., 1.}, instance_scaling_matrix_inverse * m_editing_cache[i].normal.cast<double>());
|
||||||
const Eigen::AngleAxisd aa(q);
|
const Eigen::AngleAxisd aa(q);
|
||||||
glsafe(::glPushMatrix());
|
|
||||||
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
|
|
||||||
const double cone_radius = 0.25; // mm
|
const double cone_radius = 0.25; // mm
|
||||||
const double cone_height = 0.75;
|
const double cone_height = 0.75;
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (use_attributes) {
|
||||||
|
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * instance_matrix *
|
||||||
|
support_matrix * Transform3d(aa.toRotationMatrix()) *
|
||||||
|
Geometry::assemble_transform((cone_height + support_point.head_front_radius * RenderPointScale) * Vec3d::UnitZ(),
|
||||||
|
Vec3d(PI, 0.0, 0.0), Vec3d(cone_radius, cone_radius, cone_height));
|
||||||
|
shader->set_uniform("projection_view_model_matrix", matrix);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
glsafe(::glPushMatrix());
|
||||||
|
glsafe(::glRotated(aa.angle() * (180. / M_PI), aa.axis().x(), aa.axis().y(), aa.axis().z()));
|
||||||
glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale));
|
glsafe(::glTranslatef(0.f, 0.f, cone_height + support_point.head_front_radius * RenderPointScale));
|
||||||
glsafe(::glRotated(180., 1., 0., 0.));
|
glsafe(::glRotated(180., 1., 0., 0.));
|
||||||
glsafe(::glScaled(cone_radius, cone_radius, cone_height));
|
glsafe(::glScaled(cone_radius, cone_radius, cone_height));
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
}
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
m_cone.render();
|
m_cone.render();
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (!use_attributes)
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
const double radius = (double)support_point.head_front_radius * RenderPointScale;
|
const double radius = (double)support_point.head_front_radius * RenderPointScale;
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (use_attributes) {
|
||||||
|
const Transform3d matrix = wxGetApp().plater()->get_camera().get_projection_view_matrix() * instance_matrix *
|
||||||
|
support_matrix * Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), radius * Vec3d::Ones());
|
||||||
|
shader->set_uniform("projection_view_model_matrix", matrix);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
glsafe(::glPushMatrix());
|
||||||
glsafe(::glScaled(radius, radius, radius));
|
glsafe(::glScaled(radius, radius, radius));
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
}
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
m_sphere.render();
|
m_sphere.render();
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (!use_attributes)
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
glsafe(::glPopMatrix());
|
||||||
|
|
||||||
if (vol->is_left_handed())
|
if (vol->is_left_handed())
|
||||||
glFrontFace(GL_CCW);
|
glFrontFace(GL_CCW);
|
||||||
|
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (!use_attributes)
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,6 +333,9 @@ void GLGizmoSlaSupports::render_points(const Selection& selection, bool picking)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
|
if (!use_attributes)
|
||||||
|
#endif // ENABLE_GLBEGIN_GLEND_SHADERS_ATTRIBUTES
|
||||||
glsafe(::glPopMatrix());
|
glsafe(::glPopMatrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user