Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


[SlimDX] Anti-aliasing?


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
11 replies to this topic

#1 Mathy   Members   -  Reputation: 104

Like
1Likes
Like

Posted 17 March 2010 - 11:17 AM

Hi there. I am rendering 2D through Direct3D on the SlimDX wrapper, because I was told that DirectDraw was deprecated or obsolete. Now, the edges of my faces of the meshes I render look terrible. I would like them to be anti-aliased. I've done a lot of research myself, and I've figured out that multisampling and anti-aliasing is apparently the same? (Correct me if I'm wrong) So I tried initializing the device in the following way:
            Dim PresentParameters As New PresentParameters
            PresentParameters.BackBufferCount = 1
            PresentParameters.BackBufferFormat = Format.R5G6B5
            PresentParameters.BackBufferWidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width
            PresentParameters.BackBufferHeight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height
            PresentParameters.Windowed = False
            PresentParameters.SwapEffect = SwapEffect.Discard
            PresentParameters.EnableAutoDepthStencil = False
            PresentParameters.Multisample = MultisampleType.FourSamples
            PresentParameters.MultisampleQuality = 2

            Dim Direct3D As New Direct3D
            DEVICE = New Device(Direct3D, 0, DeviceType.Hardware, Control.Handle, CreateFlags.HardwareVertexProcessing, PresentParameters)
Notice that the present parameter's multi sample property is set to four samples, and the quality is set to two. I read somewhere that the quality depends on what the graphics card can hold. From what I can see, my graphics card can render the final outcome just fine, but the edges are still jagged. I am rendering sphere meshes, that has materials applied to them. There's been a few complaints in regards to myself appearing "lazy" to some, because they thought I didn't do enough research before going here first. That's not the case, and I appologize. I've tried to be describing the issue as well as I can with my beginner knowledge in game programming.

Sponsor:

#2 user88   Members   -  Reputation: 268

Like
0Likes
Like

Posted 17 March 2010 - 08:53 PM

Hi Mathy. Yes, multisampling is the one of anti-aliasing (AA) techniques. There are lot of AA algorithms but directx uses the one and it is implemented in hardware level.

I think three things can be wrong that your AA is not working:

1) AA is disabled is graphics driver. I don't know how to do it with ATI graphics cars, but nVidia has "nVidia ControlPannel". In Vista as well as Window 7 you can find it in Control Pannel => Personalization => Display Settings => Advanced Settings => GeForce 9600 GSO tab (in my case) => Start the nVidia Control Pannel. Here select "Manage 3D settings" (left side of window) and "Application-controlled" for "Antialiasing - Mode".

2) Check MultisampleAntialias state. Use Device.GetRenderState(RenderState.MultisampleAntialias).

3) Can be that you set incorrect values of Multisample or MultisampleQuality in PresentParameters. Have a look to SmapleFramework that produces with SlimDX SDK. There are examples how to do that correctly.

#3 Mathy   Members   -  Reputation: 104

Like
0Likes
Like

Posted 17 March 2010 - 10:05 PM

Quote:
Original post by user88
Hi Mathy. Yes, multisampling is the one of anti-aliasing (AA) techniques. There are lot of AA algorithms but directx uses the one and it is implemented in hardware level.

I think three things can be wrong that your AA is not working:

1) AA is disabled is graphics driver. I don't know how to do it with ATI graphics cars, but nVidia has "nVidia ControlPannel". In Vista as well as Window 7 you can find it in Control Pannel => Personalization => Display Settings => Advanced Settings => GeForce 9600 GSO tab (in my case) => Start the nVidia Control Pannel. Here select "Manage 3D settings" (left side of window) and "Application-controlled" for "Antialiasing - Mode".

2) Check MultisampleAntialias state. Use Device.GetRenderState(RenderState.MultisampleAntialias).

3) Can be that you set incorrect values of Multisample or MultisampleQuality in PresentParameters. Have a look to SmapleFramework that produces with SlimDX SDK. There are examples how to do that correctly.


Still doesn't work! I appreciate your very well-described help, and your ability to give me a list of possibilities.



Here's what I did so far.


Right-clicked on my desktop and clicked "NVIDIA Control Panel".

Clicked "Manage 3D settings" to the left.

I went to the "Global Settings" tab.

I selected "Application-controlled" for "Antialiasing - Mode".

I selected "Multisampling" for "Antialiasing - Transparency".

I selected "On" for "Antialiasing - Gamma correction".

Now, I went back to my program, and made sure that I set the MultisampleAntialias in my Render procedure.

I now tried opening the program - still aliased edges on the spheres.

I experimented with different MultiSample and MultiSampleQuality numbers, even though I have no clue of what I am doing. Anyway, below you see the results.



All these multisample settings were tested with MultisampleQuality 1.


Multisample: MultisampleType.TwoSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Multisample: MultisampleType.ThreeSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Multisample: MultisampleType.FourSamples - Initializes just fine, but without antialiasing.

Multisample: MultisampleType.FiveSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Multisample: MultisampleType.SixSamples - Getting error "Invalid call (-2005530516)" upon initialization.


From here I didn't test any other. Now, I find it weird that FourSamples initializes, and TwoSamples doesn't. In games such as Battlefield 2, I can easily have 2, 4, 6 or 8 X antialiasing.

My graphics card is an NVidia Quadro NVS 140M.

#4 Mathy   Members   -  Reputation: 104

Like
0Likes
Like

Posted 17 March 2010 - 10:19 PM

I might want to mention that I am using Direct3D9. I heard that DirectX 10 is not supported on DirectX 9 cards (or is it generally supported, just not with all features?)

#5 user88   Members   -  Reputation: 268

Like
0Likes
Like

Posted 17 March 2010 - 11:05 PM

Quote:
Original post by Mathy
Multisample: MultisampleType.TwoSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Multisample: MultisampleType.ThreeSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Multisample: MultisampleType.FourSamples - Initializes just fine, but without antialiasing.

Multisample: MultisampleType.FiveSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Multisample: MultisampleType.SixSamples - Getting error "Invalid call (-2005530516)" upon initialization.

Do you use Debug version of Direct3D. It can give you more information about error.

Here you can read about debug version and here you can download tool for debug logs capture.


#6 Mathy   Members   -  Reputation: 104

Like
0Likes
Like

Posted 17 March 2010 - 11:32 PM

Apparently the error was "Invalid quality" or something.

But once I got the error fixed by changing to a valid quality (normally 0), it still didn't work.

#7 Evil Steve   Members   -  Reputation: 1983

Like
0Likes
Like

Posted 17 March 2010 - 11:46 PM

Does your card / driver actually support AA? If you look at the DX caps viewer (comes with the SDK), what do you see under:
Direct3D9 Devices/your_graphics_adapter/D3D Device Types / HAL / Adapter formats / D3DFMT_R5G6B5 (Fullscreen) / Render Format Compatibility / D3DFMT_R5G6B5 / ?

#8 Mathy   Members   -  Reputation: 104

Like
0Likes
Like

Posted 17 March 2010 - 11:50 PM

Quote:
Original post by Evil Steve
Does your card / driver actually support AA? If you look at the DX caps viewer (comes with the SDK), what do you see under:
Direct3D9 Devices/your_graphics_adapter/D3D Device Types / HAL / Adapter formats / D3DFMT_R5G6B5 (Fullscreen) / Render Format Compatibility / D3DFMT_R5G6B5 / ?


Yes it does.

D3DMULTISAMPLE_NONE: 1 quality level
D3DMULTISAMPLE_NONMASKABLE: 8 quality levels
D3DMULTISAMPLE_2_SAMPLES: 1 quality level
D3DMULTISAMPLE_4_SAMPLES: 8 quality levels
D3DMULTISAMPLE_8_SAMPLES: 3 quality levels

#9 Mathy   Members   -  Reputation: 104

Like
0Likes
Like

Posted 18 March 2010 - 12:33 AM

I figured out the issue. I had a post-processing blur shader that ruined it. Removing the shader fixed the problem. Is there any way I can get that blur shader to work with Anti Aliasing though?

Also, how would I programmatically see how many quality levels the graphics card supports etc? I can't find anything about this.

#10 user88   Members   -  Reputation: 268

Like
1Likes
Like

Posted 18 March 2010 - 01:47 AM

Quote:
Original post by Mathy
Also, how would I programmatically see how many quality levels the graphics card supports etc?


Here is a code snippet from SlimDX SDK 2009 Simple Framework:

static void BuildMultisampleTypeList(SettingsCombo9 combo)
{
List<MultisampleType> possibleMultisampleTypes = new List<MultisampleType>
{
MultisampleType.None,
MultisampleType.NonMaskable,
MultisampleType.TwoSamples,
MultisampleType.ThreeSamples,
MultisampleType.FourSamples,
MultisampleType.FiveSamples,
MultisampleType.SixSamples,
MultisampleType.SevenSamples,
MultisampleType.EightSamples,
MultisampleType.NineSamples,
MultisampleType.TenSamples,
MultisampleType.ElevenSamples,
MultisampleType.TwelveSamples,
MultisampleType.ThirteenSamples,
MultisampleType.FourteenSamples,
MultisampleType.FifteenSamples,
MultisampleType.SixteenSamples
};
int quality;
foreach (MultisampleType type in possibleMultisampleTypes)
{
if (GraphicsDeviceManager.Direct3D9Object.CheckDeviceMultisampleType(combo.AdapterOrdinal, combo.DeviceType, // Direct3D9Object is of SlimDX.Direct3D9.Direct3D type
combo.AdapterFormat, combo.Windowed, type, out quality))
{
combo.MultisampleTypes.Add(type);
combo.MultisampleQualities.Add(quality); // note, quality (or quality - 1, can't remember) is highest value of quality level in current multisample type
}
}
}
}





#11 Mathy   Members   -  Reputation: 104

Like
0Likes
Like

Posted 18 March 2010 - 04:15 AM

Quote:
Original post by user88
Quote:
Original post by Mathy
Also, how would I programmatically see how many quality levels the graphics card supports etc?


Here is a code snippet from SlimDX SDK 2009 Simple Framework:
*** Source Snippet Removed ***


Perfect!

I've rated you excellent!

#12 Josh Petrie   Moderators   -  Reputation: 3177

Like
0Likes
Like

Posted 18 March 2010 - 04:18 AM

Quote:

Here is a code snippet from SlimDX SDK 2009 Simple Framework:

Do note that this sample framework no longer exists in this form.

Josh Petrie | Game Developer, Undead Labs





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