Closed ghost closed 7 years ago
Hey!
Can you provide me a copy of a failing project I could debug?
Hey Discosultan!
I have very good news! I got it to run. I narrowed down exactly what seems to cause the issue, or at least, what function seems to be doing it! I didn't know you'd reply so fast, so sorry about my delay!
When I tried creating a new project it worked fine, which made me realize the only possibly problem could be the graphics device settings I'm using, so I went out and removed the function that creates those settings - and guess what? It worked. Here's the function:
/// <summary> /// A simple realm of uniquity game. /// </summary> public RealmOfUniquity() { //IsMouseVisible = true; GraphicDeviceManager = new GraphicsDeviceManager(this); GraphicDeviceManager.PreparingDeviceSettings += GraphicDeviceManager_PreparingDeviceSettings; Content.RootDirectory = "Content"; GraphicsManager.Penumbra = new Penumbra.PenumbraComponent(this); Components.Add(GraphicsManager.Penumbra); }
/// <summary> /// When it's preparing device things. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void GraphicDeviceManager_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e) { e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth = 1368; e.GraphicsDeviceInformation.PresentationParameters.BackBufferHeight = (int)(e.GraphicsDeviceInformation.PresentationParameters.BackBufferWidth * 0.56222f); e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 8; e.GraphicsDeviceInformation.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; }
The problem seems to be caused by:
e.GraphicsDeviceInformation.PresentationParameters.MultiSampleCount = 8;
Any ideas? I could technically remove this though I'd prefer to keep it in as it was in a sample that once teached me how to get better drawing results. Oh also, if I remove it (or use your lighting engine) it also no longer seems to preserve contents - which in my case it really needs to, to stop flickering effects.
Hmm, seems to be two different issues.
For multisampling, I'm not really sure how to check for hardware support through MonoGame API, but I presume you had it working in a project without Penumbra? There's an issue at MonoGame repo (https://github.com/MonoGame/MonoGame/issues/4734) which makes be doubt if it's even working correctly...
As for flickering and preserving contents, I've made some changes to the way Penumbra specific render targets are created (https://github.com/discosultan/penumbra/commit/18e0af4c17dc965ff4a2998f085fa4b51ccca2fa). Can you build the latest Penumbra from source and verify it changes things for you? I'll push a new version of the nuget package if it solves it for you.
I just build and tested out the latest source - the flickering is still there. In my specific project (which is probably why it's flickering in the first place) I create several render targets during the draw method in case a part of the world has been edited or changed, meaning that at best it 'd be updating several render targets and also changing the graphics device buffer - might this be of any help to fixing the problem? I had the flickering before, and changing it to preserve contents did the trick for me. Here's how I create those rendertargets I mentioned:
if(this.UpdateRenderTarget)
{
if (RenderTarget == null)
{
RenderTarget = new RenderTarget2D(SpriteBatch.GraphicsDevice, BoundingBox.Width, BoundingBox.Height, false, SpriteBatch.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
BackgroundTarget = new RenderTarget2D(SpriteBatch.GraphicsDevice, BoundingBox.Width, BoundingBox.Height, false, SpriteBatch.GraphicsDevice.PresentationParameters.BackBufferFormat, DepthFormat.Depth24Stencil8, 0, RenderTargetUsage.PreserveContents);
}
SpriteBatch.GraphicsDevice.SetRenderTarget(RenderTarget);
SpriteBatch.GraphicsDevice.Clear(Color.Transparent);
SpriteBatch.Begin();
// drawing here
SpriteBatch.End();
SpriteBatch.GraphicsDevice.SetRenderTarget(null);
SpriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, RealmOfUniquity.CameraMatrix);
this.UpdateRenderTarget = false;
}
// draw render target here
The flickering still exists when using the following code:
` private void BuildRenderTargets()
{
// issue exists with or without commenting this out
// DestroyRenderTargets();
PresentationParameters pp = Engine.Device.PresentationParameters;
Lightmap = new RenderTarget2D(Engine.Device, ViewportWidth, ViewportHeight, false,
pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, pp.RenderTargetUsage);
LightmapBindings[0] = Lightmap;
DiffuseMap = new RenderTarget2D(Engine.Device, ViewportWidth, ViewportHeight, false,
pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, pp.RenderTargetUsage);
DiffuseMapBindings[0] = DiffuseMap;
Logger.Write("New lightmap textures created");
}`
I'm currently out of ideas of what might be causing it.
If you could share a project where the flickering is present, I might be able to help you.
Is it possible I can add you somewhere where I can share the project with you? Instant messaging would be great.
Enabled access to render targets used by Penumbra (https://github.com/discosultan/penumbra/commit/64c818a1517fb2c18b314e619f9ba9f879bdf11a).
Hey,
Whenever I try and use this it seems to throw this error: _"An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll
Additional information: HRESULT: [0x80070057], Module: [General], ApiCode: [EINVALIDARG/Invalid Arguments], Message: The parameter is incorrect."
I have no idea what's causing this. I've done exactly what the documentation is telling me to do, and I've been trying to get it to work for a day or two now.
Some details: