IntroductionSince about 2008, Freespace Open was given the capability for programmable shaders. With programmable shaders came per-pixel lighting which, for the most part, emulated the behavior of OpenGL’s adhoc lighting model. OpenGL’s lighting model has served us quite well and moving from the per-vertex fixed function lighting to per-pixel has breathed a lot of life into the engine. But as GPUs are getting faster and home consoles are getting more powerful, it’s time we looked into replacing this lighting model to take advantage of the unused GPU power our users are increasingly obtaining. Physically plausible lighting seems to be the trend this console generation and game engines are shipping with physically-based renderers.
In an effort to not fall behind modern game engines, I am proud to introduce physically-based rendering in Freespace Open. After finishing off most of the principal development of soft shadows and deferred lighting (which should hopefully be hitting trunk not too far into the future), I’ve transitioned most of my efforts into upgrading Freespace Open’s lighting model. This started by first introducing high-dynamic range rendering into the engine. Once that was ready, I went forth and crafted much more realistic lighting shaders that take advantage of the increased range of color luminance values.
Builds with physically-based rendering no longer use the legacy adhoc lighting model which was plagued with arbitrary terms and constants. Now, the engine is using a much more accurate lighting function based off of the Blinn-Phong lighting model and Shlick’s Approximation for Fresnel reflections. It’s not perfectly accurate and will likely require tweaking and additional changes in the future but I’d say it’s a pretty good start
This post will aim to introduce developers targeting assets for Freespace Open on how to best take advantage of the more realistic lighting in the rendering engine.
New Lighting Parameter: GlossA lot of modders in this community are familiar with specular power. Specular power is a parameter for lighting that determines the size of specular highlights. This parameter originally could only be set game-wide through a command line parameter called -ogl_spec. Now, gloss can be set per-pixel via texture mapping.
Though specular power was configurable, the behavior of the resulting highlight did not match that of reality. The overall brightness from the of the highlights lessened as the the highlight got smaller which doesn’t respect energy conservation for reflected light. Our new lighting model, however, accounts for this. In addition to specular power, gloss also controls the the size of reflections from environment maps via MIP map selection which is a very important visual cue for metallics and smooth objects.
(Gloss values of 0.0, 0.25, 0.5, 0.75 and 1.0)
Gloss has the subsequent effect of making surfaces look very smooth and shiny with high values. Subsequently, low gloss values make surfaces look rough and dull. Artist are encouraged to put a lot of detail into gloss textures. Much of the density of detail normally put into diffuse maps should instead be put into the gloss maps instead.
Gloss is stored in the alpha channel of Freespace’s Reflectance maps which will be explained in the next section.
Reflectance MapsReflectance maps are Freespace’s new specular texture format. Reflectance maps use the RGB channels for specular color while the alpha channel is used for per-pixel gloss. The RGB color channels are gamma corrected from the sRGB response curve into linear color space. Reflectance maps are defined by appending "-reflect" to the filenames of texture images.
Because the engine now uses a physically-based lighting model, specular color in reflectance maps should correspond to real-world specular reflectance values. When used in combination with diffuse maps, a wide range of real-life materials can be replicated.
Dielectrics (non-metal materials like rubber, plastic, cloth, stone, wood, etc), should have traditional diffuse maps while given very low specular monochrome color values in the reflectance map.
(A plastick-y looking Loki with a glossy finish thanks to a colored diffuse, low monochrome specular, and high gloss)
Metallic materials should be given a black or very dark diffuse map while given high specular color values; this is to simulate the fact that metals do not absorb or refract light but rather reflect all light. Metallics also change the color of their reflected light which means their specular colors do not have to be monochrome.
(Gold Ulysses created by having a black diffuse and specular reflectance colors for gold)
There are a variety of reference values available provided by the vendors of various commercial engines.
CryEngine (
source)
Unity 5 (
source)
Remember Me (
source)
Deprecation Model for Shine MapsLegacy specular maps, known as shine maps, are still accepted by appending “-shine” to texture maps. Legacy specular maps do not support gloss channels as the alpha channel is specified to attenuate environment map reflections. The RGB channels are not gamma corrected. A constant gloss factor will be applied to the corresponding model instead of per-pixel gloss.
ConclusionThis isn’t exactly the best guide on physically-based workflows but hopefully it’ll be enough for artists to get started. So tl;dr, things to remember:
- Gloss is very important. Put a lot of detail into this.
- Low gloss = blurry reflection. High gloss = sharp reflection.
- Low gloss = wide, dull highlight. High gloss = small, bright highlight.
- Reflectance maps should be used to take advantage of physically-based lighting.
- Gloss lives in the alpha channel of reflectance maps.
- Specular color lives in the RGB channels of reflectance maps and are gamma corrected from sRGB.
- Reflectance maps are defined with “-reflect’.
- “-shine” still works but you can’t apply per-pixel gloss with them and the RGB values will not be gamma corrected. If both -shine and -reflect are found, -reflect will be used instead.
- When authoring a metallic texture map, apply black diffuse and high specular color. Specular does not have to be monochrome.
- When authoring a non-metallic texture map, apply a colored diffuse and low specular color. Specular must be monochrome.