Jump to content

  • Log In with Google      Sign In   
  • Create Account

DirectX10 setup and weird alpha artefacts


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 TheVastBernie   Members   -  Reputation: 154

Like
0Likes
Like

Posted 06 September 2012 - 05:59 PM

I have a weird problem. I use DirectX10 with SlimDX and I try to get the general setup right, but everytime there is something wrong. This time I encountered a weird error with alpha blending. I simply draw two intersecting planes with a opacity of 0.75f. When I draw them using 2x multisampling I get this result:
screen.png
It looks like a tiny grid on top of my model. Strangely enough when I set multisampling to 1 everything seems fine, until I draw the model with 0.5f opacity, which creates the same artefacts. And that goes through each multisample count.
Here is my device setup:
// Create swap chain description
DXGI.SwapChainDescription swapChainDesc = new DXGI.SwapChainDescription()
{
	 BufferCount = 1,
	 Usage = DXGI.Usage.RenderTargetOutput,
	 OutputHandle = Window.Handle,
	 IsWindowed = true,
	 ModeDescription = new DXGI.ModeDescription(0, 0, new Rational(60, 1), DXGI.Format.R8G8B8A8_UNorm),
	 SampleDescription = new DXGI.SampleDescription(1, 0),
	 Flags = DXGI.SwapChainFlags.AllowModeSwitch,
	 SwapEffect = DXGI.SwapEffect.Discard,
};

// Get device and swap chain
DX10.Device.CreateWithSwapChain(null, DX10.DriverType.Hardware, DX10.DeviceCreationFlags.None, swapChainDesc, out Device, out SwapChain);

// Get back buffer view
using (DX10.Texture2D texture = DX10.Resource.FromSwapChain<DX10.Texture2D>(SwapChain, 0))
	 BackBufferView = new DX10.RenderTargetView(Device, texture);
	  
// Get depth stencil view
DX10.Texture2DDescription descTexture2D = new DX10.Texture2DDescription()
{
	 Width = 1280,
	 Height = 720,
	 MipLevels = 1,
	 ArraySize = 1,
	 Format = DXGI.Format.D24_UNorm_S8_UInt,
	 SampleDescription = BackBufferView.Resource.AsSurface().Description.SampleDescription,
	 Usage = DX10.ResourceUsage.Default,
	 BindFlags = DX10.BindFlags.DepthStencil,
	 CpuAccessFlags = DX10.CpuAccessFlags.None,
	 OptionFlags = DX10.ResourceOptionFlags.None
};
DX10.DepthStencilViewDescription descDepthStencilView = new DX10.DepthStencilViewDescription()
{
	 ArraySize = 1,
	 Dimension = DX10.DepthStencilViewDimension.Texture2DMultisampled,
	 FirstArraySlice = 1,
	 MipSlice = 1,
	 Format = descTexture2D.Format,
};
using (DX10.Texture2D texture = new DX10.Texture2D(Device, descTexture2D))
	 DepthStencilView = new DX10.DepthStencilView(Device, texture, descDepthStencilView);

// Set rasterizer
DX10.RasterizerStateDescription rasteriserDesc = new DX10.RasterizerStateDescription()
{
	 CullMode = DX10.CullMode.Front,
	 DepthBias = 0,
	 DepthBiasClamp = 0,
	 FillMode = DX10.FillMode.Solid,
	 IsAntialiasedLineEnabled = false,
	 IsDepthClipEnabled = true,
	 IsFrontCounterclockwise = false,
	 IsMultisampleEnabled = false,
	 IsScissorEnabled = false,
	 SlopeScaledDepthBias = 0
};
Device.Rasterizer.State = DX10.RasterizerState.FromDescription(Device, rasteriserDesc);
		  
// Set viewport
var viewport = new DX10.Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
Device.Rasterizer.SetViewports(viewport);

// Set blend state
DX10.BlendStateDescription descBlendState = new DX10.BlendStateDescription()
{
	 IsAlphaToCoverageEnabled = true,
	 SourceBlend = DX10.BlendOption.SourceAlpha,
	 DestinationBlend = DX10.BlendOption.InverseSourceAlpha,
	 BlendOperation = DX10.BlendOperation.Add,
	 SourceAlphaBlend = DX10.BlendOption.Zero,
	 DestinationAlphaBlend = DX10.BlendOption.Zero,
	 AlphaBlendOperation = DX10.BlendOperation.Add,
};
descBlendState.SetBlendEnable(0, true);
descBlendState.SetWriteMask(0, DX10.ColorWriteMaskFlags.All);
Device.OutputMerger.BlendState = DX10.BlendState.FromDescription(Device, descBlendState);

// Set depth stencil state
DX10.DepthStencilStateDescription descDepthStencilState = new DX10.DepthStencilStateDescription()
{
	 IsDepthEnabled = true,
	 DepthWriteMask = DX10.DepthWriteMask.All,
	 DepthComparison = DX10.Comparison.LessEqual,
	 IsStencilEnabled = true,
	 StencilReadMask = 0xFF,
	 StencilWriteMask = 0xFF,
	 FrontFace = new DX10.DepthStencilOperationDescription()
	 {
			FailOperation = DX10.StencilOperation.Keep,
			DepthFailOperation = DX10.StencilOperation.Increment,
			PassOperation = DX10.StencilOperation.Keep,
			Comparison = DX10.Comparison.Always,
	 },
	 BackFace = new DX10.DepthStencilOperationDescription()
	 {
			FailOperation = DX10.StencilOperation.Keep,
			DepthFailOperation = DX10.StencilOperation.Decrement,
			PassOperation = DX10.StencilOperation.Keep,
			Comparison = DX10.Comparison.Always,
	 },
};
Device.OutputMerger.DepthStencilState = DX10.DepthStencilState.FromDescription(Device, descDepthStencilState);
Device.OutputMerger.DepthStencilReference = 1;

// Set render targets
Device.OutputMerger.SetTargets(DepthStencilView, BackBufferView);


Strange enough even though I don't use multisampling I must declare the DepthStencilViewDescription.Dimension to be Texture2DMultisampled or this line:
DepthStencilView = new DX10.DepthStencilView(Device, texture, descDepthStencilView);
will throw an error.

If someone wants to reproduce the error, here's the project: https://www.dropbox....yz3daq/Test.rar

So I wonder how to fix this problem since I've never encountered this kind of problem. Also I've been messing around with the device initialization code a lot, and my best bet is that the error lies somewhere within, but maybe you can tell me how to set the device up so that all basic functions work properly (eg multisampling, depth/stencling, alpha blending)

I really hope you can help me with this.

Sponsor:

#2 MJP   Moderators   -  Reputation: 11343

Like
0Likes
Like

Posted 06 September 2012 - 06:05 PM

You have alpha to coverage enabled, which will essentially "dither' your output based on the alpha value. It's meant to be used without blending, so that you can approximate the look of transparent geometry by rendering opaque geometry.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS