epezent / implot

Immediate Mode Plotting
MIT License
4.64k stars 516 forks source link

PlotLine() is broken #432

Closed corporateshark closed 1 year ago

corporateshark commented 1 year ago

The diff 63d5ed94b77acdf73201a00074bfd80467f50f0a introduced some breaking changes in how ImPlot::PlotLine() works.

Before:

Before

After:

After

Code:

auto Sparkline = [](const char* id, const float* values, int count, float min_v, float max_v, int offset, const ImVec4& col,
                    const ImVec2& size) {
    ImPlot::PushStyleVar(ImPlotStyleVar_PlotPadding, ImVec2(0, 0));
    ImPlot::SetNextAxesLimits(0, count - 1, min_v, max_v, ImGuiCond_Always);
    if (ImPlot::BeginPlot(id, size, ImPlotFlags_CanvasOnly | ImPlotFlags_NoChild)) {
        ImPlot::SetupAxes(nullptr, nullptr, ImPlotAxisFlags_NoDecorations, ImPlotAxisFlags_NoDecorations);
        ImPlot::PushStyleColor(ImPlotCol_Line, col);
        ImPlot::PlotLine(id, values, count, 1, 0, offset);
        ImPlot::PushStyleVar(ImPlotStyleVar_FillAlpha, 0.25f);
        ImPlot::PlotShaded(id, values, count, 0, 1, 0, offset);
        ImPlot::PopStyleVar();
        ImPlot::PopStyleColor();
        ImPlot::EndPlot();
    }
    ImPlot::PopStyleVar();
};
epezent commented 1 year ago

I'll be honest. I don't see any difference in the before/after photos.

But I suspect your problem is in the order of arguments passed to PlotLine, which recently added a flags argument before offset and striding. This was a necessary evil, so I'm sorry if that's your issue.

corporateshark commented 1 year ago

The issue is that the lines are seemed to be antialiased in some different way - they are not crisp sharp any more. I will check the order of arguments though.

corporateshark commented 1 year ago

@epezent I checked (and removed) the offset parameter from my code (which was always set to 0 anyways). The result is the same - new untialiased lines look really, well..., ugly. Any other recent changes related to this issue? What else should I check?

corporateshark commented 1 year ago

@epezent I experimented a bit further and here's what I found:

I use the old version of ImPlot (the one that is working correctly for me) and add the ImPlotFlags_AntiAliased flag to BeginPlot(). Now I have exactly the same graphics issue in the old version as is the default behavior of the new version. For some reason, the new version renders lines as if ImPlotFlags_AntiAliased is always set which is not the case.

The actual code in ImPlot indeed ignores the ImPlotFlags_AntiAliased flag and has now only one, always software antialised, code path for lines.

As the documentation says, it looks ugly indeed 😃

ImPlotFlags_AntiAliased   = 1 << 10, // plot items will be software anti-aliased (not recommended for high density plots, prefer MSAA)
nuuSolutions commented 1 year ago

Have you found a workaround?

corporateshark commented 1 year ago

@nuuSolutions Not really, that old code path is completely missing from the new function. Unfortunately, I have to use the last working version 79b05d5e259fc2a83075cc7d8058b13b810da00b.

nuuSolutions commented 1 year ago

I'm pro anti-aliasing, but it should look right/better. Maybe we sign a petition for that!?

epezent commented 1 year ago

We abandoned our custom anti-aliasing pipeline via ImPlotFlags_AntiAliased in favor of ImGui's texture based anti-aliasing for performance and maintainability reasons. Please read up on ImDrawListFlags_AntiAliasedLinesUseTex and ImGuiStyle::AntiAliasedLinesUseTex:

https://github.com/ocornut/imgui/issues/3245

Alternatively, you can enable MSAA in your application (4x should do).