The page content looks a bit blurry
Version/Branch of Dear ImGui:
Version 1.91.3
Back-ends:
imgui_impl_win32.cpp + imgui_impl_dx12.cpp
Compiler, OS:
Windows11 + VS2022
Full config/build information:
https://github.com/ocornut/imgui/blob/master/examples/example_win32_directx12/main.cpp
https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples#example-for-directx12-users
Details:
I know this shouldn't be ImGui's problem, I may need to adjust the dx12 related parameters, but I don't know how to handle it.
I use the example (example-for-directx12-users). I found that the loaded image is a bit blurry And with the same resources, we also compared it with WPF.
Screenshots/Video:
Minimal, Complete and Verifiable Example code:
https://github.com/ocornut/imgui/blob/master/examples/example_win32_directx12/main.cpp
https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples#example-for-directx12-users
You need to make sure the application process is DPI aware, otherwise Windows reduce sizes and then perform scaling.
eg call ImGui_ImplWin32_EnableDpiAwareness() is one possible way to make the process dpi aware.
You need to make sure the application process is DPI aware, otherwise Windows reduce sizes and then perform scaling.
eg call ImGui_ImplWin32_EnableDpiAwareness() is one possible way to make the process dpi aware.
My screen DPI is 96, pixels are 1960 * 1080p, and the size is 24 inches The window system has not performed display scaling
Then I don't know what your problem is.
I am not sure, given the grey fringe, it could be that the image use transparency and use premultiplied alpha? Our blending settings don't (btw it was not a good idea on my end). You can use a ImDrawList callback to alter blending settings when drawing your images. May start by modifying the D3D12_BLEND_DESC in imgui_impl_dx12.cpp to check if the image looks correct with that change.
See https://github.com/microsoft/DirectXTK12/blob/main/Src/CommonStates.cpp
We are using:
D3D12_BLEND_DESC& desc = psoDesc.BlendState;
desc.AlphaToCoverageEnable = false;
desc.RenderTarget[0].BlendEnable = true;
desc.RenderTarget[0].SrcBlend = D3D12_BLEND_SRC_ALPHA;
desc.RenderTarget[0].DestBlend = D3D12_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].BlendOp = D3D12_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlendAlpha = D3D12_BLEND_ONE;
desc.RenderTarget[0].DestBlendAlpha = D3D12_BLEND_INV_SRC_ALPHA;
desc.RenderTarget[0].BlendOpAlpha = D3D12_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL;
Which corresponds more or less to CommonStates::NonPremultiplied (not exactly).
Try to change SrcBlend:
desc.RenderTarget[0].SrcBlend = D3D12_BLEND_ONE;
I am not sure, given the grey fringe, it could be that the image use transparency and use premultiplied alpha? Our blending settings don't (btw it was not a good idea on my end). You can use a ImDrawList callback to alter blending settings when drawing your images. May start by modifying the D3D12_BLEND_DESC in imgui_impl_dx12.cpp to check if the image looks correct with that change.
Thank you. the image use transparency and use premultiplied alpha.
After adjustment, the transparent edge feels even more uncomfortable.
Unfortunately as you pointed this not much of this has to do with dear imgui itself.
When you call Image() it emits a ImDrawCmd (you can browse/look at it in details in Metrics->DrawList to see the 4 vertices) which is equivalent to what you would in DX12 by emitting emitted 2 textured triangles to form a rectangle. Maybe there's a pixel alignment issue, I don't know. But you would need to try emitting that yourself or emit vertices manually and see if you can get it to match. Otherwise it can come from a million factors.
Maybe try to create a perfect pixel-grid image, and compare exact output with WPF and our DX12 example to understand what's going on.
The window system has not performed display scaling
I assume you did call that function I mentioned tho, to rule out that possibility?
I am sorry I don't have much resources to help you debug this so I am going to close it, but feel free to post details of your investigation.