cronholio

I'm hoping someone can help me get antialising working in my game.

I figured out that when rendering directly to the screen I can set antialiasing using these fields at the top of my render function.

myDevice.RenderState.MultiSampleAntiAlias = true;

myDevice.PresentationParameters.MultiSampleType = MultiSample.SixteenSamples;

myDevice.PresentationParameters.MultiSampleQuality = 8;

I've been building a library though, where every asset has it's own render function, and the screen is rendered to a RenderTarget2D and displayed on a sprite, and I cannot for the life of me antialias the 3D objects in my screen. I tried setting these fields in the game render function, on the render functions of all the individual objects, on the RenderTarget, and on the SpriteBatch. Can anyone help me figure this out



Re: XNA Game Studio Express Anitaliasing when rendering to sprite

Kyle_W

Make sure you are searching the forums before posting a new question.

Perhaps the information on this thread will resolve your issue:

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1273546&SiteID=1





Re: XNA Game Studio Express Anitaliasing when rendering to sprite

cronholio

OK, not to be a jerk, but in general can we all just stop admonishing people to search the forums after they ask a question

Yes I did search the forum. I read every post and all related linked articles in this forum about anti-aliasing. I searched google and found more articles. I read and searched the docs. I read Shawn's Blog about SpriteBatch renderstates. I went through other people's source code. BTW, your suggestion of setting multisample type and quality in the constructor throws an unhandled exception on my machine.

I do not want to fake antialiasing by bluring the alpha channel as in the article George linked. I want to mutisample. As I said in my first post, I have figured out how to multisample when I render directly to the screen. However setting those same propertiess on assets, spritebatches, and the rendertarget2D are not working for me. Setting the sampler state in my postprocess.fx file does nothing. There's some critical piece of information I am missing.

If it helps anyone my game is basicly set up like the hazymind XNA engine here: http://www.thehazymind.com/XNAEngine.htm.





Re: XNA Game Studio Express Anitaliasing when rendering to sprite

Bill Reiss

Are you setting graphics.PreferMultiSampling to true in the Game1 contructor




Re: XNA Game Studio Express Anitaliasing when rendering to sprite

Kyle_W

Well I wouldn't call it an admonishment; just a friendly reminder.  I think I made a reasonable assumption that you had not searched the forums because you made no mention of having tried some of the things mentioned on other threads. If you are saying that these things didn't help you, then I'm sure people will be happy to step in and offer suggestions. A few questions for you:

Are you using the Game class in your game

If so, did you try setting myGraphicsDeviceManager.PreferMultiSampling to true

What exception were you getting when you tried specifying the multisampling options in the RenderTarget2D constructor, and what values did you attempt to set

 





Re: XNA Game Studio Express Anitaliasing when rendering to sprite

cronholio

Kyle_W wrote:

What exception were you getting when you tried specifying the multisampling options in the RenderTarget2D constructor, and what values did you attempt to set

I'm almost positive this is the issue right here. I've watched my graphics Devices through the entire application, PreferMultisample is always true, multisampling is always enabled and the quality and type is always set on the device. The one problem is these properties are never set on the RenderTarget2D, only the graphics device. When I watch my postProcesser I can see that the properties are not being set on the RenderTarget2D. I cannot set the properties directly, and if I try something like this

this.renderTarget = new RenderTarget2D(myDevice, myDevice.Viewport.Width, myDevice.Viewport.Height, 1, myDevice.DisplayMode.Format, MultiSampleType.EightSamples, 4);

I get a InvalidOperationException here's the detail:

System.InvalidOperationException was unhandled
Message="The method call is invalid."
Source="Microsoft.Xna.Framework"
StackTrace:
at Microsoft.Xna.Framework.Graphics.RenderTarget..ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height, Int32 numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, Int32 multiSampleQuality, Boolean isTexture2D)
at Microsoft.Xna.Framework.Graphics.RenderTarget2D..ctor(GraphicsDevice graphicsDevice, Int32 width, Int32 height, Int32 numberLevels, SurfaceFormat format, MultiSampleType multiSampleType, Int32 multiSampleQuality)
at AOEAEngine.AOEAPostProcessor.LoadGraphicsContent(GraphicsDevice myDevice, ContentManager myLoader) in C:\Users\mike\Documents\Visual Studio 2005\Projects\Technology\AOEAEngine\AOEAPostProcessor.cs:line 25
at AOEAEngine.AOEAGame.LoadGraphicsContent(Boolean loadAllContent) in C:\Users\mike\Documents\Visual Studio 2005\Projects\Technology\AOEAEngine\AOEAGame.cs:line 95
at Microsoft.Xna.Framework.Game.Initialize()
at AOEAEngine.AOEAGame.Initialize() in C:\Users\mike\Documents\Visual Studio 2005\Projects\Technology\AOEAEngine\AOEAGame.cs:line 108
at Microsoft.Xna.Framework.Game.Run()
at AOEADemo.AOEADemo.Main() in C:\Users\mike\Documents\Visual Studio 2005\Projects\Technology\AOEAGame\AOEAGame\AOEADemo.cs:line 26

Thanks for any help you can give.





Re: XNA Game Studio Express Anitaliasing when rendering to sprite

cronholio

The answer is I am a dumbass. Even in the constructor the mltisample type and quality cannot be set directly, they must be passed from the GraphicsDevice. Here is the solution:

this.renderTarget = new RenderTarget2D(myDevice, myDevice.Viewport.Width, myDevice.Viewport.Height, 2, myDevice.DisplayMode.Format, myDevice.PresentationParameters.MultiSampleType, myDevice.PresentationParameters.MultiSampleQuality);

So, Kyle was correct, the answer was satring me in the face the whole time.





Re: XNA Game Studio Express Anitaliasing when rendering to sprite

Kyle_W

No need to beat yourself up. We are all learning. I don't think the issue is that you have to pass the settings directly from the presentation parameters of the device. Instead, I think the issue is that the settings must simply match the settings in the presentation parameters. If so, this should be clearly stated in the docs for RenderTarget2D, which it isn't, and I'm sure others will encounter the same problem in the future.



Re: XNA Game Studio Express Anitaliasing when rendering to sprite

Shawn Hargreaves - MSFT

The multisample settings for a rendertarget don't have to match those on the device, but they do have to match those of the current depth buffer.

If you don't set a custom depth buffer along with the custom rendertarget, you will be using the one that was created by default by the device, and that will have the same format as the device itself, so you'll have to match that in your custom rendertarget.

If you want to make a custom rendertarget with a different multisampling format, you need to either make a matching depth buffer to use along with it, or if you don't need depth buffering for this code, set the depth buffer to null while using your custom rendertarget.