How to Antialias with Irrlicht - DirectX9

A forum to store posts deemed exceptionally wise and useful
Chips

How to Antialias with Irrlicht - DirectX9

Post by Chips »

Hello,

Irrlicht is nice little renderer, but I was wondering where the AA had gone.
I don't know if anyone has tried this already, but here's how I managed to improve the quality of rendering if you use the DirectX9 driver. It involves a small recompile of the irrlichtDLL. :D

1. Open CVideoDirectX9.cpp, locate the line (line 190ish)
that sets the swap effect and set ito this:

Code: Select all

present.SwapEffect = D3DSWAPEFFECT_DISCARD; 
2. Add this line:

Code: Select all

present.MultiSampleType	= D3DMULTISAMPLE_2_SAMPLES; 
(or whatever level of multisampling you want to try - check the dx9 guide!)

3. Go down to the line (281ish) that gets the device capabilities.., and add this afterwards:

//antialiasing ON!

Code: Select all

pID3DDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS , TRUE ); 
Recompile and stick the DLL wherever you keep it. Et voila, no more Jaggies!

Note1 that this may break other things, I've only tried it with the demos and my amazing rotating cube app. :D
Note2 You may also want to wrap (3) with a call to CheckDeviceMultiSampleType to make sure that your GFX card supports it, otherwise there could be a small fire, or more likely a crash.

Cheers,
Chips

P.S.
If you are using VC++6 you can only use DX9SDK Oct 2004 and you will need the extras pack from microsoft. This gets rid of that annoying "security cookie" link failure:

Put the extracted libs at the top of your link path before anything else.
http://www.microsoft.com/downloads/deta ... laylang=en
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

Nice post!

I wonder if it's possible to turn antialiasing OFF somehow in a similar way if it is activated via the systems graphics card settings.

jox
It is like it is. And because it is like it is, things are like they are.
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

Interesting. Thnx for sharing that Chips. Is the fix similar for DX8?

I was about to ask you (Jox) about how to fix it since we had already discussed a similar issue in version 0.6. On the other hand I just noticed that setting Vsync on gets rid of the jaggies.

I've been rumbling all around about the zbuffer problem all around and all i had was to set a flag to true :oops: :oops:

edited:
it's not the Vsync flag, it's the one before it (after the fullscreen flag). What does this one do? it's the one that solves the jaggies, even with the regular Irr dll.(checking API for "createDevice")
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

it's the stencilbuffer flag, for shadows...makes sense, doesn't it? heheheh


:wink:
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Post by jox »

What do you mean afecelis? I mean what "fix". What Chips posted was more adding a feature than fixing something (of course he "fixed" not having antialiasing...). Or did I get something wrong?
It is like it is. And because it is like it is, things are like they are.
Guest

Post by Guest »

screenshot, please :)
Chips

Screenshots

Post by Chips »

Hi guys,

Jox - You're right I would expect irrlicht to have something on the video driver interface to allow you to turn multisampling on and off. With DirectX though this is a decision that is made at the point at which you create the device, so when the irrlicht device is first created you would have to specify your antialias requirements. It can also be done at device reset time.

afecelis - For DirectX 8.0 the modification is identical - theoretically :)

Screen shots, (notice the limb of the planet), the nice thing about full scene multisampling is that the whole scene gets anti-aliased. :D

Before
Image

After
Image

Cheers,
Chips
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

@Jox: yup, you're right. It's not a fix but an addon. I thought it had to do with the zbuffer rendering problem, but now I get it :wink:


@Chips: thnx, gonna try DX8 as well. When you say we turn AA on or off when creating the device you refer to the Vsync flag?

ps. Nice and smooth second screen, love it :D
Chips
Posts: 3
Joined: Sun Mar 20, 2005 10:30 am

Post by Chips »

Hi afecelis,
Irrlicht doesnt expose the antialias parameters at the interface, that's why i stuck the mod into the main irrlicht code. I think that they will expose it in the future so you can decide to use AA or not when you create an irrlicht device. For now am keeping the mod in, cause everything looks sweet! :D

Once you have made the mod to the irrlicht source code and recompiled the DLL you wont need to change any of your code that uses irrlicht to get it to work. However it depends on whether your gfx card supports multisampling, and what level it can go to, 2X, 4X ..etc. I have hardcoded 4x in my irrlicht.dll.

The higher the multisampling the smoother things look, but there is a trade off between multisampling and performance and you have to strike a balance.

Happy tweaking!

Cheers,
Chips

P.S.
It definitely does work with the Direct8 driver too, you'll need to mod Cvideodirectx8.cpp instead of course.
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

hehehe, already did!!! :D

thnx for the explanation, you're very kind.

I'll try a level 4 then although the one you dfaulted (2 multisamples) already looks good.

and I'm glad it's built into the dll.

cya around

:wink:
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Very nice addition but it could be integrated better. Like setting a flag in the VideoDriver or passing it to the device's constructor (with an enum named like this: E_AA_DISABLED, E_AA_MULTISAMPLES_2, E_AA_MULTISAMPLES_4 or something like that). Nevertheless, nice addition :).
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
afecelis
Admin
Posts: 3075
Joined: Sun Feb 22, 2004 10:44 pm
Location: Colombia
Contact:

Post by afecelis »

I guess the only problem would be hardware requirements, right? So making it possible to be set from the create device would make it easier according to the system specs you're aiming at?
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

afecelis wrote:I guess the only problem would be hardware requirements, right? So making it possible to be set from the create device would make it easier according to the system specs you're aiming at?
Exactly.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
Chips
Posts: 3
Joined: Sun Mar 20, 2005 10:30 am

Post by Chips »

Perhaps one way to do it would be have a separate class which allowed you to set parameters of the device, a pointer to which would be passed into the device creation code.

IrrlichtDevice *createDevice (...... , CDeviceParameters *pDeviceParameters);

where CDeviceParameters allows you to set up all sorts of settings for the device before it is created.

This would make the code easier to maintain since as new device parameters came along you would not have to keep adding further parameters to the createDevice method. You could also be nice and make the CDeviceParameters default constructor set up a bunch of defaults for your chosen driver. You could also wrap up other things like vsync, fullscreen , bit depth etc, in this one class.

The thread digresses! :)

Cheers,
Chips
jox
Bug Slayer
Posts: 726
Joined: Thu Apr 22, 2004 6:55 pm
Location: Germany

Re: Screenshots

Post by jox »

Chips wrote:Jox - You're right I would expect irrlicht to have something on the video driver interface to allow you to turn multisampling on and off. With DirectX though this is a decision that is made at the point at which you create the device, so when the irrlicht device is first created you would have to specify your antialias requirements. It can also be done at device reset time.
Thanks Chips. You're also right. But this actually doen't answer my question. :) The question was: is there a possibility (regardless wether hacked in or set via parameter) to turn antialiasing off with any code if it is turned on by the system (Windows).

:)
It is like it is. And because it is like it is, things are like they are.
Post Reply