OpenGL Shaders (GLSL)

From FreeSpace Wiki
Revision as of 05:05, 27 January 2010 by Echelon9 (talk | contribs) (Mac users: Updated to reflect current state of Mac OpenGL code)
Jump to: navigation, search

Introduction

As most of users know, FS2_Open has been ported to OpenGL API from its original DirectX API. Since 3.6.9. builds, OpenGL has been the preferred API and DirectX support is not guaranteed anymore in future builds. Eventually, DirectX support might be completely dropped.

In addition, starting with 3.6.10. nightly test builds, the graphic engine has been enhanced in order to use shaders following the OpenGL Shading Language (GLSL). This new rendering add-on has allowed the inclusion of normal and parallax mapping effects and a general improvement in the game looking with nearly no performance loss (or even with performance gains).


Notes and system requirements

  • Because of the used shader code, a Shader Model 3.0 capable GPU is needed for shaders to work. So you need:
    • nVidia: GeForce 6xxx or newer card.
    • ATI/AMD: Radeon (X1xxx), HD 2xxx or newer card.
    • Others (Intel included): Possibly, there's no working card.
  • You also need a set of shader files (see below).
  • If your card is not SM3.0 capable or you don't have the needed shader files, the game will automatically fall back to legacy fixed render pipeline, (you will lose normal and parallax effect).
  • Legacy fixed render pipeline can be also forced through -no_glsl flag. This flag is useful for troubleshooting or performance tests.
  • Within F3 lab, if GLSL mode has been enabled, fixed render pipeline can be optionally switched on/off. In this way, shader vs. legacy rendering quality can be evaluated. Nevertheless, this setting is restricted to F3 lab, the rest of the game will continue using GLSL.


Known issues

ATI/AMD X1xxx GPUs

These GPUs are, in theory, SM 3.0 capable so they should run the shaders fine. BUT THEY DON'T. The game usually crashes or freezes with these GPUs.

Several SCP people are studying the issue. Speculation about its lack of Vertex Texture Fetch support has been stated as the source of the issue. But nothing has been set as the final conclusion. Here you have a link to VTF article in opengl.org wiki.

Possible solutions:

  • Use -no_glsl.
  • Use-at-your-own-risk hack for Windows XP 32-bit users:
    • Update your Catalyst to the latest version.
    • Locate 7.9 or older Catalyst version.
    • Extract the installation archive but do not install it.
    • Grab Atioglxx.dll from it.
    • Copy Atioglxx.dll in FS2 folder. In this way your system will be updated to the last Catalyst version BUT FS2 will use an old one.
    • Run the game. Expect possible bad performance.
    • (If you prefer, you can look for just old Atioglxx.dll download links in HLP forums).


Mac users

Shaders are now much improved on Mac OS X, and very closely match the feature set available on Windows. The central problem is performance slowdowns that are caused by bugs in Apple's graphics drivers. Environment mapping also leads to an odd effect in which portions of the desktop or other programs are rendered onto in-game objects.

ForceWare 169.xx

These drivers are buggy and don't work fine (several graphical glitches). Why the hell are you using them? They're ancient. Update to a newer version NOW.


Description of shaders

  • Shader files have got .sdr extension.
  • They are placed in effects subfolder within general data structure. They work like any other game file: they can be packed in vp archives and they are fully affected by overall precedence priority.
  • Starting from version 3.6.10., MediaVP package includes a full set of shaders within mv_core.vp.
  • The game uses a fixed number of shaders (66). Each one of them can be identified through its name with the next key. It also shows the order used in the name convention, so there's a lb shader but not a bl one.
    1. Null: Just color/shading only, no lighting or textures used. As you can imagine, there's no mixed usage with any other kind of shader.
    2. l: lighting enabled.
    3. f: indicates fog based lighting condition effects. (Not to be confused with the -f that denotes fragment shaders).
    4. b: uses base/diffuse map.
    5. g: glow map. As always, this effect is switched on by -glow flag and it needs associated glow maps. (It only exists for fragment shaders).
    6. s: specular map. As always, this effect is switched on by -spec flag and it needs associated specular maps. (It only exists for fragment shaders).
    7. n: normal map. This effect only exists in GLSL mode. It needs the usage of -normal flag and new normal maps.
    8. h: height map (parallax mapping). This effect only exists in GLSL mode. It needs the usage of -height flag AND -normal flag. So you cannot have parallax mapping without normal mapping. It also needs the usage of new height maps. (It only exists for fragment shaders).
    9. e: environment map. As always, this effect is switched on by -env flag AND -spec flag. So you cannot have env mapping effect without specular bright effect. This happens because the env mapping effect is affected by the alpha channel on the specular map. This also happens in legacy fixed render pipeline mode.
    10. The -v files are vertex shaders, the -f files are fragment shaders.
  • Vertex and framgent shaders are paired up by the needed functions in the fragment part. Therefore, there are less vertex shaders than fragment ones. The used vertex shaders are:
    1. Null-v, which offers color/shading only.
    2. l*-v, which offers lighting and mapping, (ie. textures), support.
    3. *f*-v, which gives you fog support.
    4. *n*-v, which provides access to the tangent space data needed for normal maps.
    5. *e-v, which adds the env translation matrix.
    6. Special case: b-v, which offers mapping support, (ie. textures), but no lighting.
  • Examples of vertex and fragment pairs:
    • The only special thing that lbgs-f needs is lighting, which means it only has to be paired up with l-v.
    • But lbgse-f needs envmap support too, so it is paired up with le-v which has access to the env translation matrix.
    • In F3 lab, if all the textures are turned off, so there's only lighting applied over the white bare flat surfaces of the POF model, l-v and Null-f are the used shaders.
    • In F3 lab, if all the textures AND also the lighting are turned off, Null-v and Null-f are used. Only a white silhouette of the ship is rendered.
    • b-v and b-f / bg-f. This pair is used in HUD target box, where the game renders a textured ship, with glowmaps (bg-f) or without them (b-f), but it lacks any lighting. It is also used in F3 lab if lighting is turned off while keeping the textures on.
      Side note: As the game doesn't use a g-f shader, in F3 lab, you cannot turn off lighting and diffuse textures while keeping glowmaps. In this situation glowmaps are also turned off.


Listing of Vertex to Fragment Sets

Basic Shaders:
null-v: null-f
b-v: b-f, bg-f
l-v: lb-f, lbg-f, lbgs-f, lbs-f, lg-f, lgs-f, ls-f, null-f
le-v: lbgse-f, lbse-f, lgse-f, lse-f

NORMAL Map Shaders:
ln-v: lbgn-f, lbgsn-f, lbn-f, lbsn-f, lgn-f, lgsn-f, ln-f, lsn-f
lne-v: lbgsne-f, lbsne-f, lgsne-f, lsne-f

FOG Based Shaders:
lf-v: lfb-f, lfbg-f, lfbgs-f, lfbs-f
lfe-v: lfbgse-f, lfbse-f

FOG Based NORMAL Shaders:
lfn-v: lfbgn-f, lfbgsn-f, lfbn-f, lfbsn-f
lfne-v: lfbgsne-f, lfbsne-f


External links:

http://en.wikipedia.org/wiki/Shader

http://en.wikipedia.org/wiki/GLSL

http://www.opengl.org/documentation/glsl/

OpenGL Org's Typhoon Labs Shader Designer

http://www.opengl.org/sdk/tools/ShaderDesigner/

nVidia Shader applications:

http://developer.nvidia.com/object/fx_composer_home.html

http://developer.nvidia.com/object/nv_shader_debugger_home.html

http://developer.download.nvidia.com/shaderlibrary/webpages/shader_library.html

ATI Shader tools

http://developer.amd.com/gpu/rendermonkey/Pages/default.aspx

http://developer.amd.com/gpu/archive/ashli/Pages/default.aspx

Apple OpenGL tools

http://developer.apple.com/graphicsimaging/opengl/opengl_serious.html