D3D11 Render to Texture Transparency/MSAA Issue
<p>I had posted this on Gamedev, however, it's been a few days and no bites. I wanted to see if anyone has an idea what I've missed.</p>

<p>Normally I'd post these as two questions, but I have a feeling they're intertwined. In short, I have a particle system that generates data for a sprite to display on a transparent surface. It's then sent to a geometry shader (through a pass through vertex shader) to extrude a single vertex into quads, then finally to a pixel shader (code below).</p>

<p>The pixel colors are sampled from a 32bit DDS (using an alpha channel to denote transparency) that's being used as a texture atlas (64x64 surfaces).</p>

<p>The two problems are as follows:
Although a single sprite honors its transparency properly, when that sprite passes over another one, one of the quads overwrites the other with a transparent rectangle (you can see the attached images: the first image is a frame with them overlapping, the second is after one has moved away slightly).
I cannot for, for the life of my, get MSAA to cooperate. I've setup a triple Texture2D system to do an output->ResolveSubresource->output_msaa->CopyResource->final_output, and it renders, it's just still aliased.</p>

<p>Here is the code for the device, texture, and sampler state:</p>

<pre><code>//Errors are checked in other places and the debug layer is showing no warnings

//Render Target Texture
D3D11_TEXTURE2D_DESC texd;
ZeroMemory(&amp;texd, sizeof(texd));
texd.Width = config.width;
texd.Height = config.height;
texd.ArraySize = 1;
texd.SampleDesc.Count = 4;
texd.SampleDesc.Quality = D3D11_CENTER_MULTISAMPLE_PATTERN;
texd.MipLevels = 1;
texd.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
texd.BindFlags = D3D11_BIND_RENDER_TARGET;
texd.Usage = D3D11_USAGE_DEFAULT;
hr = dev-&gt;CreateTexture2D(&amp;texd, NULL, &amp;output_texture);

//Sampler State
D3D11_SAMPLER_DESC samplerdesc;
ZeroMemory(&amp;samplerdesc, sizeof(samplerdesc));
samplerdesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP;
samplerdesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP;
samplerdesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
samplerdesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
samplerdesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerdesc.MaxLOD = D3D11_FLOAT32_MAX; 
hr = dev-&gt;CreateSamplerState(&amp;samplerdesc, &amp;samplerstate);

//MSAA Intermediary Texture
ZeroMemory(&amp;texd, sizeof(texd));
texd.Height = config.height;
texd.Width = config.width;
texd.MipLevels = 1;
texd.ArraySize = 1;
texd.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
texd.SampleDesc.Count = 1;
texd.SampleDesc.Quality = 0;
texd.Usage = D3D11_USAGE_DEFAULT;       
hr = dev-&gt;CreateTexture2D(&amp;texd, NULL, &amp;output_temp_msaa);

//Second Intermediary Texture
ZeroMemory(&amp;texd, sizeof(texd));
texd.Height = config.height;
texd.Width = config.width;
texd.MipLevels = 1;
texd.ArraySize = 1;
texd.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
texd.SampleDesc.Count = 1;
texd.SampleDesc.Quality = 0;
texd.Usage = D3D11_USAGE_STAGING;
texd.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
hr = dev-&gt;CreateTexture2D(&amp;texd, NULL, &amp;output_temp);
The texture loading:
hr = D3DX11CreateShaderResourceViewFromFile(
        dev,
    L"Atlas.dds", 
    &amp;rtd,
    NULL,
    &amp;res_texture,
    NULL
);

//in the Render() function:
devcon-&gt;PSSetShaderResources(0, 1, &amp;res_texture);
The blend state code:
D3D11_BLEND_DESC desc;
desc.AlphaToCoverageEnable = false;
desc.IndependentBlendEnable = false;
for (int i = 0; i &lt; 8; i++)
{
    desc.RenderTarget[i].BlendEnable = true;
    desc.RenderTarget[i].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
    desc.RenderTarget[i].SrcBlend = D3D11_BLEND_SRC_ALPHA;
    desc.RenderTarget[i].DestBlend = D3D11_BLEND_INV_SRC_ALPHA;
    desc.RenderTarget[i].SrcBlendAlpha = D3D11_BLEND_ZERO;
    desc.RenderTarget[i].DestBlendAlpha = D3D11_BLEND_ZERO; 
    desc.RenderTarget[i].BlendOp = D3D11_BLEND_OP_ADD;
    desc.RenderTarget[i].BlendOpAlpha = D3D11_BLEND_OP_ADD; 
}       
hr = dev-&gt;CreateBlendState(&amp;desc, &amp;blendstate);
</code></pre>

<p>Here is the code that converts from output_texture to the output_temp texture for copying:</p>

<pre><code>devcon-&gt;ResolveSubresource(
    output_temp_msaa,
    D3D11CalcSubresource(0, 0, 1),
    output_texture,
    D3D11CalcSubresource(0, 0, 1),
    DXGI_FORMAT_B8G8R8A8_UNORM
);
devcon-&gt;CopyResource(output_temp, output_temp_msaa);
</code></pre>

<p>This is then used as such:</p>

<pre><code>devcon-&gt;Map(output_temp, 0, D3D11_MAP_READ, 0, &amp;output_subresource);
</code></pre>

<p>and copied, bit by bit, to another location for drawing.</p>

<p>Here is the current pixel shader:</p>

<pre><code>//These are properly being set, AFAIK.
Texture2D Texture;
SamplerState ss;

struct PS_INPUT {
    float4 p : SV_POSITION;
    float2 t : TEXCOORD;
    float opacity : OPACITY;
};


float4 PShader(PS_INPUT input) : SV_TARGET
{
    float4 color = Texture.Sample(ss, input.t); 
    color.a = input.opacity;        
    return color;
}
</code></pre>

<p>Finally, the images showing the transparent clipping are attached (the offending sprite is in the middle of the screen).</p>

<p>Thanks in advance everybody!</p>

<p>Normal Sprites
<a href="https://i.stack.imgur.com/9ED7J.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9ED7J.png" alt="Normal Sprites"></a></p>

<p>Clipping Sprites
<a href="https://i.stack.imgur.com/Zw2un.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Zw2un.png" alt="Clipping Sprites"></a></p>

<p>Update:
The clipping issue was actually because of a miscommunication between our graphic artist and I. The texture was using black as its indication of transparent, instead of traditional alpha. Accounting for this (by changing pure black to float4(0,0,0,1) in the pixel shader) solved the clipping. The MSAA issue remains.</p>