Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Texture creation refactoring + texture filtering options
#1
I'd like to implement shadow maps and anisotropic filtering in some future version of Colobot. But first we need to refactor texture creation. TextureCreateParams structure is too low-level, doesn't contain enough information, and contains some useless information. Plus we could add some graphics options and correct some problems.

I write this post because I want to encourage more involvement in the project of various people, not just few programmers. Someone could help decide where and how to put things in graphics option menu.

From the point of in-game texture usage, there are few specific texture parameters that player should be able to choose in graphics menu. Each one translates to magnification and minification filters, mipmap generation and anisotropic filtering. These should be a single texture type which can be chosen in right option menu:
  • Texture filtering option:
  1. Nearest neightbour = Doom-like filtering, some textures need this (GL_NEAREST / GL_NEAREST)
  2. Bilinear filtering = Linear filtering, UI textures should use this (GL_LINEAR / GL_LINEAR)
  3. Trilinear filtering = Mipmapped linear filtering, world textures can use this (GL_LINEAR / GL_LINEAR_MIPMAP_LINEAR)
  • Mipmap level (4, 8, 16) = Specific number of generated mipmaps, enabled only for trilinear filtering
  • Anisotropy level (1, 2, 4, 8, 16) = Specific number for anisotropic sampling
Current mipmap generation (GL_GENERATE_MIPMAP) is available since OpenGL 1.4, so we need to disable trilinear filtering below that version or precompute and upload mipmaps manually. Current code doesn't set GL_TEXTURE_MAX_LEVEL, which defaults to 1000. Most textures need up to 8 mipmaps. Using trilinear mode without mipmaps is pointless. And using anisotropic filtering without 

Anisotropic filtering can only be enabled when GL_EXT_texture_filter_anisotropic is available. Maximum available anisotropic level should be checked from MAX_TEXTURE_MAX_ANISOTROPY_EXT.

We need to introduce depth texture format (aka GL_DEPTH_TEXTURE24) for future implementation of shadow maps, available only when OpenGL 1.4 or GL_ARB_depth_texture is available. WARNING: GL Context has to be created with 24-bit Depth buffer or else huge performance penalty will be introduced when copying from framebuffer.

Created textures should be generally stored in a class, not single integer, but that's for later. We could add these settings to .ini file first and later to graphics options. Also, we can probably remove VBO switch since the problem has been resolved. We can add these as Trello problems/ideas for game engine and/or Github issues.
"After three days without programming, life becomes meaningless."
~The Tao of Programming
#2
(05-05-2015, 01:50 PM)tomaszkax86 Wrote: I write this post because I want to encourage more involvement in the project of various people, not just few programmers. Someone could help decide where and how to put things in graphics option menu.

Graphics option menu is best choise, but it will be a little overloaded. We should pack some current options from this menu to another, so we could add these new options instead. I mean these checkboxes from the left side would go to submenu "Details", if it's possible with current code.
When we'll have some free space, we could add list with possible options for Texture filtering option (Nearest/Bilinear/Trilinear), below Mipmap level with settings 4,8,16, silimar like current "Number of Particles" options from the right side. It it will be impossible to implement, then maybe some "hack", like "if it's 1, then display 4, when 2, then it's 8, etc...", I don't know what's possible with our current UI, and refactoring UI is planned on 0.3.0. Finally, Anisotropy level with similar 'display system' like Mipmap level option.
Spoiler :
[Image: unknown.png]
#3
Another option is that we can make a small application, that can change all colobot.ini settings out-of-the-game, before GOLD even initially start. In this app we can place everything we want easily, before CEGUI refactoring in GOLD.

I guess, this can be written in Java for basic multiplatform without any additional dependency libraries.
#4
OK, so I implemented trilinear filtering, mipmap levels, and anisotropy. To use them you need to add 3 lines below to [Setup] section in colobot.ini:

Code:
FilterMode=3
MipmapLevel=8
Anisotropy=16

These are very high settings so you can try lower values if game runs slowly. FilterMode=3 means trilinear filtering. Value 2 means bilinear filtering and 1 means nearest neighbour filtering. If they are not present, mode defaults to bilinear, mipmaps are set to 1 and anisotropy to 1. If your computer can't use specified anisotropy, it will use whatever the highest level it can.

Later we can add controls to options menu so we can change these settings in game. Textures have to be reloaded for this to work.
"After three days without programming, life becomes meaningless."
~The Tao of Programming
#5
@tomaszkax86: I have no objections to the functionality you have implemented, but if I have to nitpick, I would advise against adding more code to big classes like CEngine. We should in fact start moving code out of CEngine as it is too big already. For example, all texture-related functionality should go into its own class named like CTextureManager.

@Raptor: I don't like the idea of external program to modify program settings. For one thing, I think it is inconvenient for the user - remembering to launch external program before launching the game itself. And for another thing, it creates an artificial division of settings - one set set in external program and one set in game settings. Deciding which setting goes into which set is a bit unclear.
#6
I think that everything in main menu becomes a bit blurry after enabling these options.

Normal:
[Image: l8udRri.png]
After enabling new options:
[Image: pnwFwld.png]

Also, the background texture looks a bit diffrent.
#7
Some of the text rendering seems to use default/global filtering mode rather than the proper one specified in text.cpp. We'll have to look around UI controls and change filtering mode there. But I don't see any significant differences in background texture.
"After three days without programming, life becomes meaningless."
~The Tao of Programming


Forum Jump:


Users browsing this thread: 3 Guest(s)