Game Development Community

FSAA and AF in Win32 TGE 1.5.2?

by Jason Parker · in Torque Game Engine · 01/06/2009 (7:00 pm) · 33 replies

I've spent several hours searching for functions to enable FSAA either in the client scripts or from the console. The only function I can find is setFSAA(); and when I tried to use that I get the error "Unable to find function setFSAA()".

I would like to add FSAA and Anisotropic Filtering controls to my graphics options GUI. I can't be the first person to want to do this even though users can force both in their graphics drivers. Fact is, most of my target users don't even install their own graphics drivers, much less know how to access those functions.

I've also tried the function to enable Anisotropic Filtering, and absolutely nothing happens.

I noticed when combing the source code for "FSAA", that the console function setFSAA(); is right after a comment that the following group is Mac specific.

Am I going to have to add in FSAA and AF controls from the ground up, or are my search skills and eyes failing me?
Page «Previous 1 2
#1
01/07/2009 (12:34 am)
From my experience, it worked only on ATI hardware (on Mac for sure, but I'm not certain that it was operational on windows).

Nicolas Buquet
www.buquet-net.com/cv/
#2
01/07/2009 (12:42 am)
Looking in the change logs, it would appear that it's supposed to work for Nvidia hardware as well.

These lines: * FSAA switching now ignores vendor, and assumes it has a radeon card.

* This has no detrimental effect on nvidia cards, as far as I know.
* FSAA now defaults to off, instead of to max samples when it's available.

From: tdn.garagegames.com/wiki/Torque/1.5/WhatsNew

And looking at that page again, it appears those lines are in a platform specific section.
#3
01/07/2009 (7:14 am)
I read your post last night Jason and right after that I decided to take a dive into the engine code base to see what all that would be necessary to make it work on Windows at least. Currently yes the FSAA (and Anisotropic Filtering I don't see any code for it at all) are only implemented for Mac OS X and I plan on having a working solution of some kind this evening which is when I'll have the free time to be able to hopefully come up with a clean implementation that'll work from here on.

I'll only be able to test with a few Nvidia cards (GeForce 7600 GS at this time) so what I am looking into right now might only be Nvidia specific or hopefully it is done the same way for ATI too. I am currently looking at the following documentation on what to do inside of the engine:
developer.nvidia.com/object/gdc_ogl_multisample.html

Now as for as the Anisotropic Filtering is concerned I haven't run into any articles on how to get that working just yet.
#4
01/07/2009 (1:53 pm)
Thanks for taking a look at it. I don't own any ATI hardware to test with, or I'd offer to help you test it. The laptop that has an ATI Radeon Xpress 200 isn't charging anymore and needs a new motherboard. I'm currently running an Nvidia 9800 GT.
#5
01/07/2009 (3:24 pm)
Anisotropic filtering does work in TGE through the setOpenGLAnisotropy function. I don't recall if you need to restart to get it to work though. I know currently I set it through the $pref::OpenGL::textureAnisotropy variable in the prefs.cs file. It works great and makes a huge improvement in my experience, especially on the terrain where it is most noticeable.

As a small side project I have been looking into using the GL_ARB_multisample extension with TGE, so far I have only created code to test if the extension is supported on the video card. I think I will spend some more time looking into it tonight.

Also from what I can tell the setFSAA functions only work on the Mac.
#6
01/07/2009 (9:22 pm)
@ Wes:
Perhaps rendering needs to be reinitialized when turning on the Anisotropy with that function? I might try that... though I'd still like to be able to query the driver for available anisotropic filtering modes and populate a list in the graphics options...

I've been working with C-like scripting for years, and a friend was teaching me C++ briefly. I've also had C++ for Dummies since about early-mid Summer. I know syntax quite well, beginning to learn my way around C++ functions, but I've not yet touched on any sort of OpenGL or DirectX programming so it may be a while before I take a crack at this myself. At most I can probably make it so setting the anisotropy reinits the graphics rendering as it is now... but again, I'd really like a menu of available modes queried from the driver.
#7
01/07/2009 (9:24 pm)
Oh... Wes, one more thing. Is it an ATI or Nvidia adapter that you're using on the system that setting it through prefs.cs works on?
#8
01/08/2009 (1:58 pm)
I am not sure exactly how the anisotropic extension works in OpenGL but I see GL_TEXTURE_MAX_ANISOTROPY_EXT used during texture creation so it might need to be set before the textures are created. That is why you would need to restart (or at least cause the textures to reload) after setting it during a running game. I will eventually be upgrading the options dialog too so I will look into how that all works later.

When I run it I am using an Nvidia GeForce 8500 GT. I have noticed lines sometimes on the terrain that are really ugly separating the textures and the mip maps look blurry at small angles but using anisotropic filtering fixes it.

If all you want is to know the level supported you can use this code and place it under setOpenGLAnisotropy's definition. You could then use a slider bar and pass the value to setOpenGLAnisotropy because it takes a range of 0-1 (min-max).
ConsoleFunction(getOpenGLMaxAnisotropy, F32, 1, 1, "getOpenGLMaxAnisotropy();")
{
	if (dglDoesSupportTexAnisotropy())
		return dglGetMaxAnisotropy();
	else
		return 0.0f;
}

As for FSAA, I did get the WGL_ARB_multisample working and the results are very nice but it only works for windows right now. I will probably clean up the code and release it in the near future.
#9
01/08/2009 (4:18 pm)
Yeah, I've noticed the lines too, but I think that is due to the anisotropy mode being it's lowest when using the prefs to turn it on. Which leads me to believe that if we want control over the different levels of anisotropic filtering that newer cards support, it may have to be coded in as a new function. Just not knowledgeable about OpenGL programming at all yet, so I don't know what's possible. Though I'm sure it is, as I can think of several games that allow setting different levels of anisotropic filtering.

Oh, and the lines aren't there if you just use Trilinear filtering, but of course that doesn't give the texture sharpness further out that anisotropy does.
#10
01/08/2009 (4:27 pm)
$pref::OpenGL::textureAnisotropy is a ratio of 0 (None) 1(Max). It's basically future proof, when I set $pref::OpenGL::textureAnisotropy to 1 on my card it does 16x Anisotropic filtering.
#11
01/08/2009 (5:02 pm)
Odd for me Anisotropy Filtering using $pref::OpenGL::textureAnisotropy = 1; in prefs.cs or forced via nvidia control panel I see zero difference in TGE 1.5.2 in any of the maps. Now when I force FSAA via nvidia control panel it does make a pretty big difference. I'm still working on my multisample implementation for TGE, its pretty god awful how FSAA/GL_multisample was implemented on Windows. This has to be the worst OpenGL extension I have ever had to deal with.
#12
01/08/2009 (6:02 pm)
Yea multisample on windows has been a real pain in the ass.

In case it helps I'll share the way that I implemented it. I created a test window before setScreenMode in OpenGLDevice::activate. Using the test window's DC I used glGetExtensionsStringARB to test for WGL_ARB_pixel_format and WGL_ARB_multisample. Then again using that window I iterated all the pixel formats looking for all the supported multisample modes using wglChoosePixelFormatARB and wglGetPixelFormatAttribivARB. After that the only thing I had to do was make a new version of ChooseBestPixelFormat that I called ChooseBestPixelFormatEx that took a multisample argument. Instead of using wglDescribePixelFormat like ChooseBestPixelFormat the new funtion uses wglChoosePixelFormatARB. In the case that the card does not support the new extensions ChooseBestPixelFormatEx calls ChooseBestPixelFormat.

I'm not sure why you guys are not seeing a result from textureAnisotropy. Here is an image of mine without and with $pref::OpenGL::textureAnisotropy equal to 1.

server3.uploadit.org/files/Onverse-AF.JPGThe JPG took a little away from the quality of the bottom image but the effect is still noticeable. Of course it is nothing like what FSAA does.
#13
01/08/2009 (7:44 pm)
I didn't say that I don't see a result from turning on anisotropic filtering. I do, but there is no fine control over the AF mode used. I haven't done a side by side comparison of 16x AF forced in the driver next to AF turned on by Torque yet, so I don't know if it's actually using the max AF capable.

Even if it is using the max, there is a use for users to be able to set lower modes. TGE is intended to support a wide range of hardware, and that means the stuff in between, not just at the ends. It isn't just GeForce 2 at the low end, and shader cards at the high end with nothing in between. Just because a card can enable a certain level of AF, doesn't mean that card will perform well with the AF setting maxed. Hence my interest in controlling the AF mode in engine, rather than just toggling max, or not.

Anyhow, that's AF. FSAA is another story. This may be more a personal preference because users with cards that can handle anti-aliasing a decently complex scene should also be able to run at higher resolutions where AA is less needed. But if you're running TGE on, say, a 720p TV, your max res is 1280x720... Without AA, the jagged lines are pretty bad.
#14
01/08/2009 (9:32 pm)
How did you solve this problem:
Could not load this WGLEXT function: wglGetExtensionsStringARB

I get that when I use dwglGetExtensionsStringARB() API that was defined as:
engine/platformWin32/GLWinExtFunc.h:
//WGL_ARB_extensions_string
WGL_GROUP_BEGIN(WGL_ARB_extensions_string)
WGLEXT_FUNCTION( const char*, wglGetExtensionsStringARB, (HDC), return NULL; )
WGL_GROUP_END()

I've been fighting this damn problem for over a day now and I still cannot figure out what the hell is wrong.

Update:
I found out what the whole deal is. The extension APIs aren't hooked until way after the SetScreenMode() is finished and I need them to be during SetScreenMode(). So I decided to cheat and do the following for example (right after I have created a dummy/text window with an OpenGL context):
*(void**)&dwglGetExtensionsStringARB    = (void *)dwglGetProcAddress("wglGetExtensionsStringARB");

Then I just check the function to make sure it isn't NULL before calling it and by then I'll know soon enough if it is or isn't available right at that point.
#15
01/09/2009 (2:01 am)
Jason, I understand what you are trying to say now. $pref::OpenGL::textureAnisotropy is not a boolean value, it is a float with a range of 0-1. So 0.5 is a valid value and if you have a max of 16x then a value of 0.5 will be 8x.

Nathan, You're right you cannot get the address to wglGetExtensionsStringARB until after a valid rendering context has been made current. You can do this in the dummy window very easily by creating a rendering context after creating the device context.

I manged to merge my MSAA and AF changes back into the base 1.5.2 code. I did it on my laptop that does not support AA and only supports 2xAF, so I am not 100% sure that it all works. I also changed the options dialog in the starter.fps so it has options for trilinear and Anisotropic filtering and MSAA. This might help clear up some problems.

This includes just the changed files and a patch file if you want to view just what changed. Copy the files over the base TGE 1.5.2 code.
MSAA_V2.zip
Edit: Moved to better server
Edit: Updated to new version
#16
01/09/2009 (6:06 am)
Downloaded and will take a look at it soon. I'll let you know how everything works since you said you cannot test with your laptop... After I'm done exploring map changes and the new map on Legions. ;)

Ran into a problem...

Changing the AF mode while fullscreen has left me with a running executable and no window... heh.

Worked fine every time I tested in windowed mode.

Going to continue testing.

Okay to update:

Changing the Trilinear filtering toggle to off or on in fullscreen crashes it.
Changing anisotropic filtering in fullscreen crashes it. Doesn't matter if it was enabled or disabled to begin with.
Changing Anti-aliasing in fullscreen crashes it. Doesn't matter if it was enabled or disabled to begin with.
Changing everything else in fullscreen is fine.

Changing anything in windowed is fine.

(edited my three responses into one...)
#17
01/09/2009 (10:00 am)
Like most bugs it does not happen for me. My first thought is that it is crashing because the display device is recreated when those settings change. A quick check would be to take a look at the console.log file and look for any errors.

Does it crash if you switch to the D3D render driver and back to OpenGL? That will cause it to recreate the display device also.

If not you can try putting...
setDisplayDevice( "OpenGL", 1024, 768, 32, true );
into the console, this will refresh the display device just like the options dialog does but without changing to D3D. Change the resolution values to match your settings.

If this crashes as well then you can try doing it to an unmodified TGE 1.5.2 build and see if that crashes. Knowing that it does not happen to unmodified TGE will isolate it to my changes and make this a lot easier.

In any case see if you can cause it to happen in a debug build. We need to find out where it happens and what exception is thrown.
#18
01/09/2009 (12:29 pm)
FSAA works great Wes, thank you for sharing :) (Vote:5 ;)

Edit: I also have the problem, that the game crash on startup if fullscreen is set. Not when switching to fullscreen but when fullscreen was set and start the exe.
What I see from the log is much more disabled Extensions than usual:

Fullscreen (with crash)
1/9 21:55:26 OpenGL Init: Enabled Extensions
1/9 21:55:26   WGL_ARB_pixel_format
1/9 21:55:26   WGL_ARB_multisample
1/9 21:55:26     Mode:2x
1/9 21:55:26     Mode:4x
1/9 21:55:26     Mode:8x
1/9 21:55:26     Mode:16x
1/9 21:55:26     Mode:32x
1/9 21:55:26 OpenGL Init: Disabled Extensions
1/9 21:55:26   ARB_multitexture
1/9 21:55:26   EXT_blend_color
1/9 21:55:26   EXT_blend_minmax
1/9 21:55:26   EXT_paletted_texture
1/9 21:55:26   EXT_compiled_vertex_array
1/9 21:55:26   NV_vertex_array_range
1/9 21:55:26   EXT_texture_env_combine
1/9 21:55:26   EXT_packed_pixels
1/9 21:55:26   EXT_fog_coord
1/9 21:55:26   ARB_texture_compression
1/9 21:55:26   EXT_texture_compression_s3tc
1/9 21:55:26   3DFX_texture_compression_FXT1
1/9 21:55:26   (ARB|EXT)_texture_env_add
1/9 21:55:26   EXT_texture_filter_anisotropic
1/9 21:55:26   WGL_EXT_swap_control
1/9 21:55:26

Windowed:
1/9 21:59:16 OpenGL Init: Enabled Extensions
1/9 21:59:16   ARB_multitexture (Max Texture Units: 4)
1/9 21:59:16   EXT_blend_color
1/9 21:59:16   EXT_blend_minmax
1/9 21:59:16   EXT_compiled_vertex_array
1/9 21:59:16   NV_vertex_array_range
1/9 21:59:16   EXT_texture_env_combine
1/9 21:59:16   EXT_packed_pixels
1/9 21:59:16   EXT_fog_coord
1/9 21:59:16   ARB_texture_compression
1/9 21:59:16   EXT_texture_compression_s3tc
1/9 21:59:16   (ARB|EXT)_texture_env_add
1/9 21:59:16   EXT_texture_filter_anisotropic (Max anisotropy: 16)
1/9 21:59:16   WGL_EXT_swap_control
1/9 21:59:16   WGL_ARB_pixel_format
1/9 21:59:16   WGL_ARB_multisample
1/9 21:59:16     Mode:2x
1/9 21:59:16     Mode:4x
1/9 21:59:16     Mode:8x
1/9 21:59:16     Mode:16x
1/9 21:59:16     Mode:32x
1/9 21:59:16 OpenGL Init: Disabled Extensions
1/9 21:59:16   EXT_paletted_texture
1/9 21:59:16   3DFX_texture_compression_FXT1
#19
01/09/2009 (3:07 pm)
Turns out I had the same problem once I got to work. My laptop did not have the problem because it did not support multi-sample. So the source of the problem is kind of funny: (actual quote from TGE code)
// HACK: The Voodoo5 on W2K will only work if the initial rendering
// context is windowed.  Can you believe this crap?
When in fullscreen mode Torque creates a window destroys it and creates the full screen window. I just had to move my test for MSAA above this code that creates the first window. That is why if you're not in full screen it works because this code is skipped.

When this code failed the torque fell back to the D3D rendering device and that is why most of the extensions became unsupported. WGL_ARB_pixel_format and WGL_ARB_multisample should have been as well if I had initiaized the D3D device correctly.

This new link has both of these problems fixed as well as the MSAA only enabled during actual rendering in the TS control. This might give a little speed boost and avoid possible problems because it is not wasted on the UI. For some reason on my card at 16xMSAA glDisable(GL_MULTISAMPLE) is ignored, but at other levels it works. I guess this is actually common to a few video cards.

Like before this includes just the changed files and a patch file if you want to view just what changed. Copy the files over the base TGE 1.5.2 code. I added a second patch file instead of changing the other one to help if some people are merging and not copying.
MSAA_V2.zip
#20
01/09/2009 (4:43 pm)
Great thread. nice work!
Page «Previous 1 2