0

I got some strange results while rendering text in directX11 over other objects. Each character becomes a black background (my clearing color). If the text gets rendered directly to the background everything is fine. Im using the imgui lib to render. I think this gets caused by a wrong setup of the blending - those are my settings:

D3D11_BLEND_DESC desc;
desc.AlphaToCoverageEnable = false;
desc.IndependentBlendEnable = false;
desc.RenderTarget[0].BlendEnable = false;
desc.RenderTarget[0].SrcBlend = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlend = D3D11_BLEND_ZERO;
desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE;
desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO;
desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;

This is an image which shows the issue:

This is an image which shows the issue

Update #1:

This is the method which im using to draw a string: https://github.com/ocornut/imgui/blob/9cff4d6e5e76dd18d9c4ee7a1560563da2059a44/imgui_draw.cpp#L2937

My clearcolor is:

ImVec4 clearColor = ImVec4(0.f, 0.f, 0.f, 0.f);

With the settings of ErnieDingo im getting this result: The positive part: The boxes around each character are gone. The bad part: Text which is very blurry/unsharp especially if the text gets rendered on a dark background/without background.

Update #2: This image seems to show the issue in a nutshell: enter image description here The overlapping part of the square should be yellow and not green like the one at the top. The fist image also shows that only the transparent background of the font is considered which leads to the strange bars behind each letter.

slize
  • 21
  • 6

1 Answers1

0

Looking at your screenshot, you're simply just rendering quads with texture containing your glpyhs correct? I had a look at my own code for the blendstate, I am assuming you are using a similar technique to what I do.

My code is in C#, but its the same DX settings. You can try these.

        blendStateDescription.RenderTarget[0].IsBlendEnabled = true;
        blendStateDescription.RenderTarget[0].SourceBlend = D3D11.BlendOption.SourceAlpha;
        blendStateDescription.RenderTarget[0].DestinationBlend = D3D11.BlendOption.InverseSourceAlpha; //
        blendStateDescription.RenderTarget[0].BlendOperation = D3D11.BlendOperation.Add;

        blendStateDescription.RenderTarget[0].SourceAlphaBlend = D3D11.BlendOption.SourceAlpha; //Zero
        blendStateDescription.RenderTarget[0].DestinationAlphaBlend = D3D11.BlendOption.InverseSourceAlpha;
        blendStateDescription.RenderTarget[0].AlphaBlendOperation = D3D11.BlendOperation.Maximum;

        blendStateDescription.RenderTarget[0].RenderTargetWriteMask = D3D11.ColorWriteMaskFlags.All;

I use SourceAlpha and InverseSourcealpha, but I believe Using Source as One and Destination as Zero is possibly fine also. But if you refer to the Microsoft DX page in regards to blending, the maths are published there.

Respond on this thread if this isn't quite working. I will assume that your source texture is a RGBA texture and that the alpha component of your texture is 0 and the background is also black.

ErnieDingo
  • 444
  • 5
  • 11
  • Thank you for your answer - i updated my post above - maybe you got another great idea to fix the blurry font. – slize Feb 08 '20 at 15:16
  • Hey @ErnieDingo may i ask you agian since the problem is still there? – slize May 02 '20 at 00:58