I am trying to render a DXGI_FORMAT_A8_UNORM texture (precisely, a font bitmap) in multiple colors by specifying the color per vertex and then apply the alpha value from the sampled texture in the pixel shader. When white is specified as the vertex color, the rendered texture looks as expected, however with darker colors the texture looks "thinned" or less opaque, as displayed in the attached picture. These are the used shaders, with fontSampler using D3D11_FILTER_MIN_MAG_MIP_POINT as filter:

Texture2D shaderTexture : register(t0);
SamplerState fontSampler : register(s0);

struct VS_INPUT
    float2 pos : POSITION;
    float4 col : COLOR;
    float2 tex : TEXCOORD0;

struct VS_OUTPUT
    float4 pos : SV_POSITION;
    float4 col : COLOR;
    float2 tex : TEXCOORD0;

    VS_OUTPUT output;
    output.pos = mul(projection, float4(input.pos.xy, 0.f, 1.f));
    output.col = input.col;
    output.tex = input.tex;
    return output;

float4 PS(VS_OUTPUT input) : SV_TARGET
    input.col.a = shaderTexture.Sample(fontSampler, input.tex).a;
    return input.col;

colored alpha texture

  • \$\begingroup\$ What blending mode are you using? BTW, you may want to look at SpriteFont in the DirectX Tool Kit. \$\endgroup\$ Apr 18 '19 at 6:33
  • \$\begingroup\$ I don't observe an error here. Are you sure it's not an optical illusion due to the eye's varying levels of response / perception of contrast in dark ranges versus bright ranges? \$\endgroup\$
    – DMGregory
    Apr 19 '19 at 22:30
  • \$\begingroup\$ @ChuckWalbourn BlendEnable = true; SrcBlend = D3D11_BLEND_SRC_ALPHA; DestBlend = D3D11_BLEND_INV_SRC_ALPHA; BlendOp = D3D11_BLEND_OP_ADD; SrcBlendAlpha = D3D11_BLEND_INV_SRC_ALPHA; DestBlendAlpha = D3D11_BLEND_ZERO; BlendOpAlpha = D3D11_BLEND_OP_ADD; RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; and blend factor { 0.f, 0.f, 0.f, 0.f }; \$\endgroup\$ Apr 20 '19 at 11:33
  • \$\begingroup\$ @DMGregory I'm positive that there is a subtle difference \$\endgroup\$ Apr 20 '19 at 11:34
  • \$\begingroup\$ As a temporary workaround, i have changed the pixel shader to incorporate the grayscale value: static const float3 conv = { 0.3, 0.59, 0.11 }; float4 PSFONT(VS_OUTPUT input) : SV_TARGET { float gray = mul(conv, input.col.rgb); input.col.a = shaderTexture.Sample(fontSampler, input.tex).a * (1.25-gray/4); return input.col; } \$\endgroup\$ Apr 20 '19 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.