Hi Jox
Well you can force DirectX to not multisample the scene by using D3DMULTISAMPLE_NONE instead of D3DMULTISAMPLE_N_SAMPLES which would get you back to the point at which we started
The DirectX AA commands control how your polygons are rasterised from the vertex buffer to the surface/texture/window. The windows system doesnt really have much of a say in what DirectX does with the graphics card, are you thinking about GDI programming i.e. fonts or overlays here?
Once you have a DirectX device you control it directly via the presentation parameters, the scene would look they same whether you rendered it to a window, or to a bitmap file, its separate from any windowsy system level antialiasing that may apply.
So I guess the answer is, yes if you are using DirectX you have full control over how the graphics card multisamples your 3D scene, so you can turn AA on and off at will if your card supports it.
Hope this answers your question and i havent disappeared down a rabbit hole.
Cheers,
Chips
How to Antialias with Irrlicht - DirectX9
Yea, what I meant was the grafics card settings, not windows (like I stated in my first post). Because there you can turn on antialiasing globally.Chips wrote:The windows system doesnt really have much of a say in what DirectX does with the graphics card
Mh, a while ago I had the problem with fonts drawn with irrlicht. When antialiasing was turned on in the graphics card settings, the fonts would be messed up and not readable anymore. Thats why I was interested in turning it off. Though I might look for a better solution like using a font that looks ok with aa turned on.Chips wrote:are you thinking about GDI programming i.e. fonts or overlays here?
yes, thank you!Chips wrote:Hope this answers your question and i havent disappeared down a rabbit hole.
jox
It is like it is. And because it is like it is, things are like they are.
My Workaround
Hey,
Thanks very much for getting me started on this. I've setup the code as follows so it detects what the card can do and then gives the user a choice. (You can use this to turn of AA too!)
When I get around to building a configuration file/program for the user I will have it read in from the text file at this point.
Currently you have to input your option during startup at the command prompt.
Should I post the code? Would you find that useful?
Thanks very much for getting me started on this. I've setup the code as follows so it detects what the card can do and then gives the user a choice. (You can use this to turn of AA too!)
When I get around to building a configuration file/program for the user I will have it read in from the text file at this point.
Currently you have to input your option during startup at the command prompt.
Should I post the code? Would you find that useful?
Workaround
Alright.
At the start of CVideoDirectX9.cpp inside the namespace video I put static variables. You can add as many as you want to correspond with the avaliable AA Settings with DirectX. I have an ATI All-In-Wonder 9600 and I only get a maximum of 6x AA.
static bool AA_0 = true;
static bool AA_2 = false;
static bool AA_4 = false;
static bool AA_6 = false;
static bool AA_8 = false;
static bool AA_12 = false;
static bool AA_16 = false;
Then in the function
//! initialises the Direct3D API
bool CVideoDirectX9::initDriver(const core::dimension2d<s32>& screenSize, HWND hwnd, u32 bits, bool fullScreen, bool pureSoftware, bool vsync)
I placed the following code after the line
ZeroMemory(&present, sizeof(present));
Code
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_2_SAMPLES, NULL ) ) )
AA_2 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_4_SAMPLES, NULL ) ) )
AA_4 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_6_SAMPLES, NULL ) ) )
AA_6 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_8_SAMPLES, NULL ) ) )
AA_8 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_12_SAMPLES, NULL ) ) )
AA_12 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_16_SAMPLES, NULL ) ) )
AA_16 = true;
if( AA_2 == true || AA_4 == true || AA_6 == true || AA_8 == true || AA_12 == true || AA_16 == true)
{
int choice = 0;
cout << "0: No Multisampling" << endl;
if(AA_2 == true)
cout << "1: 2x Multisampling" << endl;
if(AA_4 == true)
cout << "2: 4x Multisampling" << endl;
if(AA_6 == true)
cout << "3: 6x Multisampling" << endl;
if(AA_8 == true)
cout << "4: 8x Multisampling" << endl;
if(AA_12 == true)
cout << "5: 12x Multisampling" << endl;
if(AA_16 == true)
cout << "6: 16x Multisampling" << endl;
cout << ": ";
cin >> choice;
switch(choice)
{
case 1:
if(AA_2 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 2:
if(AA_4 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 3:
if(AA_6 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_6_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 4:
if(AA_8 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 5:
if(AA_12 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_12_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 6:
if(AA_16 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_16_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
default:
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
};
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
}
END Code
You will not that the present.SwapEffect was moved into the else statement.
Finally to complete the code you need to add another line in the function
//! sets the needed renderstates
bool CVideoDirectX9::setRenderStates3DMode()
I placed this code after the line pID3DDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
CODE
if( AA_2 == true || AA_4 == true || AA_6 == true || AA_8 == true
|| AA_12 == true || AA_16 == true)
pID3DDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS , TRUE );
This is why I have the static AA variables. You may not need to make the variables global and just have the
pID3DDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS , TRUE );
statement, but I have not tested this effect.
Now just recompile the DLL and move put that in the project directory. Be aware since you are not reading in from a file you may have to hit alt-tab to get to the appropriate window to input your decision. I would change the the code so you wouldn't have to do this. (And I will eventually)
I hope that helps. And yes, I know that global static variables in a Game Engine is very bad style. You should chanage this to a more refined method. It's quick and dirty but it does work.
At the start of CVideoDirectX9.cpp inside the namespace video I put static variables. You can add as many as you want to correspond with the avaliable AA Settings with DirectX. I have an ATI All-In-Wonder 9600 and I only get a maximum of 6x AA.
static bool AA_0 = true;
static bool AA_2 = false;
static bool AA_4 = false;
static bool AA_6 = false;
static bool AA_8 = false;
static bool AA_12 = false;
static bool AA_16 = false;
Then in the function
//! initialises the Direct3D API
bool CVideoDirectX9::initDriver(const core::dimension2d<s32>& screenSize, HWND hwnd, u32 bits, bool fullScreen, bool pureSoftware, bool vsync)
I placed the following code after the line
ZeroMemory(&present, sizeof(present));
Code
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_2_SAMPLES, NULL ) ) )
AA_2 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_4_SAMPLES, NULL ) ) )
AA_4 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_6_SAMPLES, NULL ) ) )
AA_6 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_8_SAMPLES, NULL ) ) )
AA_8 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_12_SAMPLES, NULL ) ) )
AA_12 = true;
if( SUCCEEDED(pID3D->CheckDeviceMultiSampleType( D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL , D3DFMT_X8R8G8B8, FALSE,
D3DMULTISAMPLE_16_SAMPLES, NULL ) ) )
AA_16 = true;
if( AA_2 == true || AA_4 == true || AA_6 == true || AA_8 == true || AA_12 == true || AA_16 == true)
{
int choice = 0;
cout << "0: No Multisampling" << endl;
if(AA_2 == true)
cout << "1: 2x Multisampling" << endl;
if(AA_4 == true)
cout << "2: 4x Multisampling" << endl;
if(AA_6 == true)
cout << "3: 6x Multisampling" << endl;
if(AA_8 == true)
cout << "4: 8x Multisampling" << endl;
if(AA_12 == true)
cout << "5: 12x Multisampling" << endl;
if(AA_16 == true)
cout << "6: 16x Multisampling" << endl;
cout << ": ";
cin >> choice;
switch(choice)
{
case 1:
if(AA_2 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 2:
if(AA_4 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_4_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 3:
if(AA_6 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_6_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 4:
if(AA_8 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_8_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 5:
if(AA_12 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_12_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
case 6:
if(AA_16 == true)
{
present.SwapEffect = D3DSWAPEFFECT_DISCARD;
present.MultiSampleType = D3DMULTISAMPLE_16_SAMPLES;
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
}
break;
default:
present.SwapEffect = D3DSWAPEFFECT_FLIP;
present.MultiSampleType = D3DMULTISAMPLE_NONE;
};
}
else
{
present.SwapEffect = D3DSWAPEFFECT_FLIP;
}
END Code
You will not that the present.SwapEffect was moved into the else statement.
Finally to complete the code you need to add another line in the function
//! sets the needed renderstates
bool CVideoDirectX9::setRenderStates3DMode()
I placed this code after the line pID3DDevice->SetRenderState(D3DRS_STENCILENABLE, FALSE);
CODE
if( AA_2 == true || AA_4 == true || AA_6 == true || AA_8 == true
|| AA_12 == true || AA_16 == true)
pID3DDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS , TRUE );
This is why I have the static AA variables. You may not need to make the variables global and just have the
pID3DDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS , TRUE );
statement, but I have not tested this effect.
Now just recompile the DLL and move put that in the project directory. Be aware since you are not reading in from a file you may have to hit alt-tab to get to the appropriate window to input your decision. I would change the the code so you wouldn't have to do this. (And I will eventually)
I hope that helps. And yes, I know that global static variables in a Game Engine is very bad style. You should chanage this to a more refined method. It's quick and dirty but it does work.
Great !
Thanks a lot bfschuil !
Your code to choose multisampling level is really great...
Do you think it is easy to modify it to be able to select multisampling level in a project based on the techdemo (exemples) with the first little Irrlicht window to select driver, realtime shadows...
I would like to add a combobox with multisampling quality here and not in the console DOS window...
Do you see a way to do that ???
Thanks
Eviral
I don't know how to set your choice variable directly from my project and to send it to the irrlicht dll...
Your code to choose multisampling level is really great...
Do you think it is easy to modify it to be able to select multisampling level in a project based on the techdemo (exemples) with the first little Irrlicht window to select driver, realtime shadows...
I would like to add a combobox with multisampling quality here and not in the console DOS window...
Do you see a way to do that ???
Thanks
Eviral
I don't know how to set your choice variable directly from my project and to send it to the irrlicht dll...
Don't work to me
sorry i come later!!
I made changes exactly like the post say to get Antialias rendering i can compile without problems but when i execute my aplication and select directx9
for rendering... the aplication doesn't start and console say:
Microsoft Windows XP Professional Se
DirectX9 Renderer
ATI MOBILITY RADEON 9000/9100 IGP at
Was not able to create Direct3D9 dev
Was not able to create DirectX9 devi
Could not create DirectX9 Driver.
Error: Could not load built-in Font.
Anywone can helpme?
I made changes exactly like the post say to get Antialias rendering i can compile without problems but when i execute my aplication and select directx9
for rendering... the aplication doesn't start and console say:
Microsoft Windows XP Professional Se
DirectX9 Renderer
ATI MOBILITY RADEON 9000/9100 IGP at
Was not able to create Direct3D9 dev
Was not able to create DirectX9 devi
Could not create DirectX9 Driver.
Error: Could not load built-in Font.
Anywone can helpme?
RE to eviral
Yes, I forsee being able to make this code so you can choose it graphically eventually. If you want to email me at the_unknown007@msn.com (don't care about getting all sorts of junk mail here) with something that I will notice in the subject line I will pass on that code to you. I probally won't be able to get around to that for at few months thought as I'm quite busy right now.
Will that help you?
Will that help you?
RE to Ishtm
Hey,
Sorry that doesn't work for you. I'm running an ATI AIW 9600 and I'm having no problems. You may want to double check your code to see if you missed something - if you placed the code in the wrong section in the file it will totally mess up your renderer
Sorry that doesn't work for you. I'm running an ATI AIW 9600 and I'm having no problems. You may want to double check your code to see if you missed something - if you placed the code in the wrong section in the file it will totally mess up your renderer
Hi people,
Take a look at this
http://nehe.gamedev.net/data/lessons/le ... ?lesson=46.
Sory that it is not for DirectX put it is about AA and it is very helpful to implement AA in Irrlicht(for bouth drivers not only for DirectX).
Of cource there must be a test to see if the video card suports AA or not and if True than initialize AA( like a Pro C++ graphical programmer ).
Take a look at this
http://nehe.gamedev.net/data/lessons/le ... ?lesson=46.
Sory that it is not for DirectX put it is about AA and it is very helpful to implement AA in Irrlicht(for bouth drivers not only for DirectX).
Of cource there must be a test to see if the video card suports AA or not and if True than initialize AA( like a Pro C++ graphical programmer ).
Kat'Oun