Level of Antialias

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Level of Antialias

Post by geckoman »

Atm I create my device as follows.

Code: Select all

SIrrlichtCreationParameters deviceParameter;
	deviceParameter.DriverType = EDT_DIRECT3D9;
	deviceParameter.AntiAlias = true;
	deviceParameter.Bits = 32;
	deviceParameter.Fullscreen = fullscreen;
	deviceParameter.Vsync = false;
	deviceParameter.WindowSize = dimension2d<s32>(width, height);
	IrrlichtDevice *device = createDeviceEx(deviceParameter);
But with setting AntiAlias to true, what LEVEL of AntiAlias is set in the device?
Can it be set to a specific level?
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

check out the drivers to see what happens.

in the D3D9 driver init function it looks like the driver detects the level of antialiasing based upon the card capabilities?

Code: Select all

	// enable anti alias if possible and desired
	if (antiAlias)
	{
		DWORD qualityLevels = 0;

		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
				devtype, present.BackBufferFormat, !fullScreen,
				D3DMULTISAMPLE_4_SAMPLES, &qualityLevels)))
		{
			// enable multi sampling
			present.MultiSampleType	= D3DMULTISAMPLE_4_SAMPLES;
			present.MultiSampleQuality = qualityLevels-1;
			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
		}
		else
		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
				devtype, present.BackBufferFormat, !fullScreen,
				D3DMULTISAMPLE_2_SAMPLES, &qualityLevels)))
		{
			// enable multi sampling
			present.MultiSampleType	= D3DMULTISAMPLE_2_SAMPLES;
			present.MultiSampleQuality = qualityLevels-1;
			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
		}
		else
		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
					devtype, present.BackBufferFormat, !fullScreen,
					D3DMULTISAMPLE_NONMASKABLE, &qualityLevels)))
		{
			// enable non maskable multi sampling
			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
			present.MultiSampleType	= D3DMULTISAMPLE_NONMASKABLE;
			present.MultiSampleQuality = qualityLevels-1;
		}
		else
		{
			os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
			antiAlias = false;
		}
	}
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Seven wrote:check out the drivers to see what happens.

in the D3D9 driver init function it looks like the driver detects the level of antialiasing based upon the card capabilities?

Code: Select all

	// enable anti alias if possible and desired
	if (antiAlias)
	{
		DWORD qualityLevels = 0;

		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
				devtype, present.BackBufferFormat, !fullScreen,
				D3DMULTISAMPLE_4_SAMPLES, &qualityLevels)))
		{
			// enable multi sampling
			present.MultiSampleType	= D3DMULTISAMPLE_4_SAMPLES;
			present.MultiSampleQuality = qualityLevels-1;
			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
		}
		else
		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
				devtype, present.BackBufferFormat, !fullScreen,
				D3DMULTISAMPLE_2_SAMPLES, &qualityLevels)))
		{
			// enable multi sampling
			present.MultiSampleType	= D3DMULTISAMPLE_2_SAMPLES;
			present.MultiSampleQuality = qualityLevels-1;
			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
		}
		else
		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
					devtype, present.BackBufferFormat, !fullScreen,
					D3DMULTISAMPLE_NONMASKABLE, &qualityLevels)))
		{
			// enable non maskable multi sampling
			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
			present.MultiSampleType	= D3DMULTISAMPLE_NONMASKABLE;
			present.MultiSampleQuality = qualityLevels-1;
		}
		else
		{
			os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
			antiAlias = false;
		}
	}
Maybe it should be configure-able?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Yes, but due to the problems with parameter passing in earlier versions of Irrlicht this wasn't easily possible. Might be in Irrlicht 1.6.
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Post by geckoman »

So if I want 2 Samples instead of 4 Samples I have to recompile Irrlicht? Configuration Options would be really nice, as I drop 66% of my FPS just because I enabled antialias...on a GeForce 8800!
Seven
Posts: 1034
Joined: Mon Nov 14, 2005 2:03 pm

Post by Seven »

geckoman wrote:So if I want 2 Samples instead of 4 Samples I have to recompile Irrlicht? Configuration Options would be really nice, as I drop 66% of my FPS just because I enabled antialias...on a GeForce 8800!
is there a control panel for your card that allows you to 'clip' the capabilities of the card so that it returns the desired value?

Image[/img]
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Post by geckoman »

Sure I can set every value I want, but thats no solution for the problem :(
Seems like I have to wait for 1.6 eh?
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Well, you can recompile Irrlicht... Or add a patch?!
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

I was bored this evening and made a patch for it:

Code: Select all

Index: include/SIrrCreationParameters.h
===================================================================
--- include/SIrrCreationParameters.h	(Revision 2027)
+++ include/SIrrCreationParameters.h	(Arbeitskopie)
@@ -25,7 +25,7 @@
 			Fullscreen(false),
 			Stencilbuffer(false),
 			Vsync(false),
-			AntiAlias(false),
+			AntiAlias(0),
 			WithAlphaChannel(false),
 			IgnoreInput(false),
 			HighPrecisionFPU(false),
@@ -100,8 +100,8 @@
 		be a good idea to make it possible to switch this option off
 		again by the user.
 		This is curently not supported in OpenGL under Windows.
-		Default value: false */
-		bool AntiAlias;
+		Default value: 0 */
+		u8 AntiAlias;
 
 		//! Whether the main framebuffer uses an alpha channel.
 		/** In some situations it might be desireable to get a color
Index: source/Irrlicht/CD3D8Driver.cpp
===================================================================
--- source/Irrlicht/CD3D8Driver.cpp	(Revision 2027)
+++ source/Irrlicht/CD3D8Driver.cpp	(Arbeitskopie)
@@ -144,7 +144,7 @@
 //! initialises the Direct3D API
 bool CD3D8Driver::initDriver(const core::dimension2d<s32>& screenSize,
 		HWND hwnd, u32 bits, bool fullScreen, bool pureSoftware,
-		bool highPrecisionFPU, bool vsync, bool antiAlias)
+		bool highPrecisionFPU, bool vsync, u8 antiAlias)
 {
 	HRESULT hr;
 	D3DLibrary = LoadLibrary( "d3d8.dll" );
@@ -225,20 +225,48 @@
 	#endif
 
 	// enable anti alias if possible and whished
-	if (antiAlias)
+	if (antiAlias > 0)
 	{
+		if(antiAlias > 16)
+		{
+			antiAlias = 16;
+		}
+
 		if (!FAILED(pID3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
 				devtype , present.BackBufferFormat, !fullScreen,
-				D3DMULTISAMPLE_2_SAMPLES)))
+				(D3DMULTISAMPLE_TYPE)antiAlias)))
 		{
 			// enable multi sampling
 			present.SwapEffect      = D3DSWAPEFFECT_DISCARD;
-			present.MultiSampleType = D3DMULTISAMPLE_2_SAMPLES;
+			present.MultiSampleType = (D3DMULTISAMPLE_TYPE)antiAlias;
 		}
 		else
 		{
-			os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
-			antiAlias = false;
+			bool success = false;
+			--antiAlias;
+
+			while(!success && antiAlias > 0)
+			{
+				if(!FAILED(pID3D->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT,
+					devtype , present.BackBufferFormat, !fullScreen,
+					(D3DMULTISAMPLE_TYPE)antiAlias)))
+				{
+					present.MultiSampleType	= (D3DMULTISAMPLE_TYPE)antiAlias;
+					present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
+
+					success = true;
+				}
+				else
+				{
+					--antiAlias;
+				}
+			}
+
+			if(!success)
+			{
+				os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
+				antiAlias = false;
+			}
 		}
 	}
 
Index: source/Irrlicht/CD3D8Driver.h
===================================================================
--- source/Irrlicht/CD3D8Driver.h	(Revision 2027)
+++ source/Irrlicht/CD3D8Driver.h	(Arbeitskopie)
@@ -103,7 +103,7 @@
 		//! initialises the Direct3D API
 		bool initDriver(const core::dimension2d<s32>& screenSize, HWND hwnd,
 				u32 bits, bool fullScreen, bool pureSoftware,
-				bool highPrecisionFPU, bool vsync, bool antiAlias);
+				bool highPrecisionFPU, bool vsync, u8 antiAlias);
 
 		//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
 		//! driver, it would return "Direct3D8.1".
Index: source/Irrlicht/CD3D9Driver.cpp
===================================================================
--- source/Irrlicht/CD3D9Driver.cpp	(Revision 2027)
+++ source/Irrlicht/CD3D9Driver.cpp	(Arbeitskopie)
@@ -152,7 +152,7 @@
 //! initialises the Direct3D API
 bool CD3D9Driver::initDriver(const core::dimension2d<s32>& screenSize,
 		HWND hwnd, u32 bits, bool fullScreen, bool pureSoftware,
-		bool highPrecisionFPU, bool vsync, bool antiAlias)
+		bool highPrecisionFPU, bool vsync, u8 antiAlias)
 {
 	HRESULT hr;
 	Fullscreen = fullScreen;
@@ -271,44 +271,53 @@
 	#endif
 
 	// enable anti alias if possible and desired
-	if (antiAlias)
+	if (antiAlias > 0)
 	{
+		if(antiAlias > 16)
+		{
+			antiAlias = 16;
+		}
+
 		DWORD qualityLevels = 0;
 
 		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
 				devtype, present.BackBufferFormat, !fullScreen,
-				D3DMULTISAMPLE_4_SAMPLES, &qualityLevels)))
+				(D3DMULTISAMPLE_TYPE)antiAlias, &qualityLevels)))
 		{
 			// enable multi sampling
-			present.MultiSampleType	= D3DMULTISAMPLE_4_SAMPLES;
+			present.MultiSampleType	= (D3DMULTISAMPLE_TYPE)antiAlias;
 			present.MultiSampleQuality = qualityLevels-1;
 			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
 		}
 		else
-		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
-				devtype, present.BackBufferFormat, !fullScreen,
-				D3DMULTISAMPLE_2_SAMPLES, &qualityLevels)))
 		{
-			// enable multi sampling
-			present.MultiSampleType	= D3DMULTISAMPLE_2_SAMPLES;
-			present.MultiSampleQuality = qualityLevels-1;
-			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
-		}
-		else
-		if (SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
+			bool success = false;
+			--antiAlias;
+
+			while(!success && antiAlias > 0)
+			{
+				if(SUCCEEDED(pID3D->CheckDeviceMultiSampleType(adapter,
 					devtype, present.BackBufferFormat, !fullScreen,
-					D3DMULTISAMPLE_NONMASKABLE, &qualityLevels)))
-		{
-			// enable non maskable multi sampling
-			present.MultiSampleType	= D3DMULTISAMPLE_NONMASKABLE;
-			present.MultiSampleQuality = qualityLevels-1;
-			present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
+					(D3DMULTISAMPLE_TYPE)antiAlias, &qualityLevels)))
+				{
+					present.MultiSampleType	= (D3DMULTISAMPLE_TYPE)antiAlias;
+					present.MultiSampleQuality = qualityLevels-1;
+					present.SwapEffect		 = D3DSWAPEFFECT_DISCARD;
+
+					success = true;
+				}
+				else
+				{
+					--antiAlias;
+				}
+			}
+
+			if(!success)
+			{
+				os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
+				antiAlias = 0;
+			}
 		}
-		else
-		{
-			os::Printer::log("Anti aliasing disabled because hardware/driver lacks necessary caps.", ELL_WARNING);
-			antiAlias = false;
-		}
 	}
 
 	// check stencil buffer compatibility
Index: source/Irrlicht/CD3D9Driver.h
===================================================================
--- source/Irrlicht/CD3D9Driver.h	(Revision 2027)
+++ source/Irrlicht/CD3D9Driver.h	(Arbeitskopie)
@@ -136,7 +136,7 @@
 		//! initialises the Direct3D API
 		bool initDriver(const core::dimension2d<s32>& screenSize, HWND hwnd,
 				u32 bits, bool fullScreen, bool pureSoftware,
-				bool highPrecisionFPU, bool vsync, bool antiAlias);
+				bool highPrecisionFPU, bool vsync, u8 antiAlias);
 
 		//! \return Returns the name of the video driver. Example: In case of the DIRECT3D8
 		//! driver, it would return "Direct3D8.1".
Index: source/Irrlicht/COpenGLDriver.cpp
===================================================================
--- source/Irrlicht/COpenGLDriver.cpp	(Revision 2027)
+++ source/Irrlicht/COpenGLDriver.cpp	(Arbeitskopie)
@@ -71,7 +71,7 @@
 
 	GLuint PixelFormat;
 
-	if (AntiAlias)
+	if (AntiAlias > 0)
 	{
 		// Create a window to test antialiasing support
 		const c8* ClassName = "GLCIrrDeviceWin32";
@@ -189,7 +189,13 @@
 			// valid numbers are 2, 4, 8.  My experience is that 8 does not
 			// show a big improvement over 4, but 4 shows a big improvement over
 			// 2.
-			const s32 numSamples = 4;
+
+			if(AntiAlias > 16)
+			{
+				AntiAlias = 16;
+			}
+
+			const s32 numSamples = AntiAlias;
 			f32 fAttributes[] =
 			{
 				0.0, 0.0
@@ -242,7 +248,7 @@
 	}
 
 	// search for pixel format the simple way
-	if (!AntiAlias)
+	if (AntiAlias < 2)
 	{
 		for (u32 i=0; i<5; ++i)
 		{
@@ -505,7 +511,7 @@
 	glDepthFunc(GL_LEQUAL);
 	glFrontFace( GL_CW );
 
-	if (AntiAlias)
+	if (AntiAlias >= 2)
 	{
 		if (MultiSamplingExtension)
 			glEnable(GL_MULTISAMPLE_ARB);
Index: source/Irrlicht/COpenGLDriver.h
===================================================================
--- source/Irrlicht/COpenGLDriver.h	(Revision 2027)
+++ source/Irrlicht/COpenGLDriver.h	(Arbeitskopie)
@@ -385,7 +385,7 @@
 		//! bool to make all renderstates reset if set to true.
 		bool ResetRenderStates;
 		bool Transformation3DChanged;
-		bool AntiAlias;
+		u8 AntiAlias;
 
 		SMaterial Material, LastMaterial;
 		COpenGLTexture* RenderTargetTexture;

Since I'm a total noob in OpenGL I don't know if this is totally right. I'm struggling with this line

Code: Select all

glEnable(GL_MULTISAMPLE_ARB);
I'm not sure if this just enables anti aliasing at all or just to a specific level but there is a difference between 0 samples and 8 ;)

Hope it helps somebody :)
Last edited by Sylence on Sun Jan 04, 2009 1:08 am, edited 1 time in total.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Thanks for the patch. Did you add it to the tracker already?
Two improvements: Use u8 for the value in SIrrCreationParameter (saves space and reduces the number of possible values to useful ranges) and don't skip the smaller AA levels in the screen check. Because if you specify level 8 and your card doesn't support this, it would be nice to get level 4 instead of no screen (or antialias) at all :D
Oh, and why do you think that OpenGL is limited to the values you mentioned?
I'll add the Linux part for the OpenGL driver once the rest is finalized :)
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Yes I added this to the tracker.
I changed the type from s32 to u8 now and re-added the check for smaller levels.

Regarding the OpenGL limitations: As I said I don't know OpenGL and there was this comment in the source that said that 2,4, and 8 were the only valid values so I believed this ;)
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
geckoman
Posts: 143
Joined: Thu Nov 27, 2008 11:05 am
Location: Germany
Contact:

Post by geckoman »

Wow that's fast!
As I used ONLY stable Releases so far I don't know to much about the tracker etc. but as I understand this, the next version of irrlicht (1.6?) should then contain this patch.

Am I right?
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

Yes. Hybrid commited this to the SVN trunk. So either you have to wait for 1.6 or you download the source from SVN and compile the engine on your own.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
Post Reply