• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By isu diss
      How do I fill the gap between sky and terrain? Scaling the terrain or procedural terrain rendering?

    • By Jiraya
      For a 2D game, does using a float2 for position increases performance in any way?
      I know that in the end the vertex shader will have to return a float4 anyway, but does using a float2 decreases the amount of data that will have to be sent from the CPU to the GPU?
       
    • By ucfchuck
      I am feeding in 16 bit unsigned integer data to process in a compute shader and i need to get a standard deviation.
      So I read in a series of samples and push them into float arrays
      float vals1[9], vals2[9], vals3[9], vals4[9]; int x = 0,y=0; for ( x = 0; x < 3; x++) { for (y = 0; y < 3; y++) { vals1[3 * x + y] = (float) (asuint(Input1[threadID.xy + int2(x - 1, y - 1)].x)); vals2[3 * x + y] = (float) (asuint(Input2[threadID.xy + int2(x - 1, y - 1)].x)); vals3[3 * x + y] = (float) (asuint(Input3[threadID.xy + int2(x - 1, y - 1)].x)); vals4[3 * x + y] = (float) (asuint(Input4[threadID.xy + int2(x - 1, y - 1)].x)); } } I can send these values out directly and the data is as expected

                             
      Output1[threadID.xy] = (uint) (vals1[4] ); Output2[threadID.xy] = (uint) (vals2[4] ); Output3[threadID.xy] = (uint) (vals3[4] ); Output4[threadID.xy] = (uint) (vals4[4] ); however if i do anything to that data it is destroyed.
      If i add a
      vals1[4] = vals1[4]/2; 
      or a
      vals1[4] = vals[1]-vals[4];
      the data is gone and everything comes back 0.
       
       
      How does one go about converting a uint to a float and performing operations on it and then converting back to a rounded uint?
    • By fs1
      I have been trying to see how the ID3DInclude, and how its methods Open and Close work.
      I would like to add a custom path for the D3DCompile function to search for some of my includes.
      I have not found any working example. Could someone point me on how to implement these functions? I would like D3DCompile to look at a custom C:\Folder path for some of the include files.
      Thanks
    • By stale
      I'm continuing to learn more about terrain rendering, and so far I've managed to load in a heightmap and render it as a tessellated wireframe (following Frank Luna's DX11 book). However, I'm getting some really weird behavior where a large section of the wireframe is being rendered with a yellow color, even though my pixel shader is hard coded to output white. 

      The parts of the mesh that are discolored changes as well, as pictured below (mesh is being clipped by far plane).

      Here is my pixel shader. As mentioned, I simply hard code it to output white:
      float PS(DOUT pin) : SV_Target { return float4(1.0f, 1.0f, 1.0f, 1.0f); } I'm completely lost on what could be causing this, so any help in the right direction would be greatly appreciated. If I can help by providing more information please let me know.
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 Render to Texture and MSAA/Layered Transparency

This topic is 793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

 

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).

 

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).

 

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.

 

Here is the code for the device, texture, and sampler state:

//Errors are checked in other places and the debug layer is showing no warnings

//Render Target Texture
D3D11_TEXTURE2D_DESC texd;
ZeroMemory(&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->CreateTexture2D(&texd, NULL, &output_texture);

//Sampler State
D3D11_SAMPLER_DESC samplerdesc;
ZeroMemory(&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->CreateSamplerState(&samplerdesc, &samplerstate);

//MSAA Intermediary Texture
ZeroMemory(&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->CreateTexture2D(&texd, NULL, &output_temp_msaa);

//Second Intermediary Texture
ZeroMemory(&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->CreateTexture2D(&texd, NULL, &output_temp);

The texture loading:

hr = D3DX11CreateShaderResourceViewFromFile(
        dev,
	L"Atlas.dds", 
	&rtd,
	NULL,
	&res_texture,
	NULL
);

//in the Render() function:
devcon->PSSetShaderResources(0, 1, &res_texture);

The blend state code:

D3D11_BLEND_DESC desc;
desc.AlphaToCoverageEnable = false;
desc.IndependentBlendEnable = false;
for (int i = 0; i < 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->CreateBlendState(&desc, &blendstate);

Here is the code that converts from output_texture to the output_temp texture for copying:

devcon->ResolveSubresource(
    output_temp_msaa,
    D3D11CalcSubresource(0, 0, 1),
    output_texture,
    D3D11CalcSubresource(0, 0, 1),
    DXGI_FORMAT_B8G8R8A8_UNORM
);
devcon->CopyResource(output_temp, output_temp_msaa);

This is then used as such:

devcon->Map(output_temp, 0, D3D11_MAP_READ, 0, &output_subresource);

and copied, bit by bit, to another location for drawing.

 

Here is the current pixel shader:

//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;
}

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

 

Thanks in advance everybody!

Edited by turbofandude

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement