Basically title. I looked through the forums with the search function and I mostly found people saying it’s not working right now?
If it does work (on DirectX that is) how do i make it work?
Thanks in advance
Obviously temporal antialiasing is interesting as it is very challenging to do well, but I think a simple MSAA solution would be nice as well and it should in theory be easy to set up.
Am using forward rendering, no deferred stuff (yet?)
EDIT: Yes i am using graphics.PreferMultiSampling = true; as well
Maybe a mistake on my part, i will research further
To add to the issue something i forgot:
An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [E_INVALIDARG/Invalid Arguments], Message: The parameter is incorrect.
Now if I set the DepthFormat.DepthNone it works as well (which it obviously should as Tom posted in the code snippet). And obviously without Depth MSAA can’t work, but no depth is no option anyways
Interesting… the only thing I can think of is that somehow we’re initializing the MSAA incorrectly or we’re using a setting that isn’t supported on your hardware.
This is the framework code that gives the exception:
// Create the view for binding to the device.
_depthStencilView = new DepthStencilView(GraphicsDevice._d3dDevice, depthBuffer,
new DepthStencilViewDescription()
{
Format = SharpDXHelper.ToFormat(DepthStencilFormat),
Dimension = DepthStencilViewDimension.Texture2D
});
If I change the code to this:
DepthStencilViewDimension dsvDimension;
if (MultiSampleCount > 1)
{
dsvDimension = DepthStencilViewDimension.Texture2DMultisampled;
}
else
{
dsvDimension = DepthStencilViewDimension.Texture2D;
}
DepthStencilViewDescription desc = new DepthStencilViewDescription()
{
Format = SharpDXHelper.ToFormat(DepthStencilFormat),
Dimension = dsvDimension
};
there is no exception, but rendering seems to output a black surface…
Found this information, not sure if it’s relevant?
In case you render to texture with multisampling, you also need to resolve your resource, multi sampled textures are bound as Texture2DMS (instead of Texture2D) in shaders.
To do so, you need to create a second texture (with same format/size), but with only one sample.
Then once you’re done rendering your multisampled texture, you need to do the following call:
I got this error from RenderDoc:
"“Invalid output merger - Depth target is different size or MS count to render target(s)”
Apparently the depth buffer is wrong in some way.
Apparently, the texture inside the RenderTarget is created without multisampling. This is the code:
internal override SharpDX.Direct3D11.Resource CreateTexture()
{
// TODO: Move this to SetData() if we want to make Immutable textures!
var desc = new SharpDX.Direct3D11.Texture2DDescription();
desc.Width = width;
desc.Height = height;
desc.MipLevels = _levelCount;
desc.ArraySize = ArraySize;
desc.Format = SharpDXHelper.ToFormat(_format);
desc.BindFlags = SharpDX.Direct3D11.BindFlags.ShaderResource;
desc.CpuAccessFlags = SharpDX.Direct3D11.CpuAccessFlags.None;
desc.SampleDescription.Count = 1;
desc.SampleDescription.Quality = 0;
desc.Usage = SharpDX.Direct3D11.ResourceUsage.Default;
desc.OptionFlags = SharpDX.Direct3D11.ResourceOptionFlags.None;
if (_renderTarget)
{
desc.BindFlags |= SharpDX.Direct3D11.BindFlags.RenderTarget;
if (_mipmap)
{
// Note: XNA 4 does not have a method Texture.GenerateMipMaps()
// because generation of mipmaps is not supported on the Xbox 360.
// TODO: New method Texture.GenerateMipMaps() required.
desc.OptionFlags |= SharpDX.Direct3D11.ResourceOptionFlags.GenerateMipMaps;
}
}
if (_shared)
desc.OptionFlags |= SharpDX.Direct3D11.ResourceOptionFlags.Shared;
return new SharpDX.Direct3D11.Texture2D(GraphicsDevice._d3dDevice, desc);
}
public int MultiSampleCount { get; private set; }
is a property of RenderTarget. It looks like it should be property of the base class Texture2D instead, since the texture needs it to initialize itself. Of course, I only know about DirectX, not the other platforms.
Well, I think it should be prioritized higher, since not having it means a visual degradation from XNA. All the fancy DX 12 stuff can come later. MSAA is a 10-year old technology, it really isn’t good that MonoGame doesn’t support it.
I’m trying myself to get MSAA to work for RTs but I can’t properly get it to work.
Can you or someone else share how you got it to work?
I’ve changed the RenderTargets to have proper sampleDescription / quality (not sure about that one) and have that not crash on me any more, but I don’t have a real clue how MSAA resolve works. Can someone help me or guide me?
I understand I need to resolve the multisampled texture to a non-msaa’d texture to use it, but where does the shader access the texture / where do i need to make the switch?
EDIT: Nevermind i got it. I’ll post a short guide soon