MGE XE - Prototype
There is now an alpha of MGE XE with normal mapping and physically-based rendering (PBR) support at http://www.nexusmods.com/morrowind/mods/26348/.
PBR is an advancement in lighting and texturing that allows your computer to render a greater variety of more complex and beautiful materials. The physics allows them to be consistently interesting in all lighting conditions.
Examples: http://i.imgur.com/RKNnVBN.gif https://www.youtube.com/watch?v=fBZWejnkB04 (Credit: PeterBitt)
It does not perform as well as the current 0.9.10 beta, so I would not recommend it for normal gameplay. You can start with a https://dl.dropboxusercontent.com/u/99804385/morrowind/MGE%20XE%20PBR%20Example%20Crate.7z for object crate_01 (separate download as I lack permission for the base texture).
This thread is open to artists interested in making PBR materials and for testing and feedback on the prototype. It is nowhere near complete yet.
Usage
There are new lighting shaders which add normal mapping, PBR specular and other improvements. The renderer requires material text files to assign normals and other material data to textures. The lighting itself does work without normals, but is still experimental.
The PBR renderer is not activated by default. You must enable per-pixel lighting, and set the "Toggle lighing mode" macro to a key. Use the macro to advance the lighting features.
"Linear lighting" is where all lighting is modified to work correctly in linear space, which may alter light colouration in exchange for physical correctness where lights overlap, and better light falloff. "PBR rendering" is linear space + normals + specular + environment light.
Crate notes
This demonstrates the general ability of the new rendering system. It is about what I could make in one evening. To view, place a crate_01 in front of you, and move it up to head height. It is best viewed in clear weather and at various times of day.
Particular visual features:
- Normal mapping with specular (sun only, for now).
- Different F0 reflectivity (non-glancing surface sheen or gloss) for wood, rust and metal rivets.
- Metallicity applied to make rivets have a coloured environment reflection. The colour is exaggerated for effect. Some improvement is possible.
- Grazing specular for both sky hemisphere and sunlight.
- Non-grazing specular reveals additional surface texture. Best seen when the sun is 15-45 degrees above the horizon. You may need to place multiple crates at different rotations to observe it easily.
Artists
The new material renderer is controlled by material text files. Texture artists must read the sample file mge3/tx_example.txt. All material loading successes and failures will appear in mgeXE.log.
The textures themselves follow a linear, PBR workflow. Textures without a material have a hardcoded default rough material.
Articles on creating PBR textures:
http://www.marmoset.co/toolbag/learn/pbr-theory
https://www.fxguide.com/featured/game-environments-parta-remember-me-rendering/
http://www.marmoset.co/toolbag/learn/pbr-conversion
Extensive reading list:
https://interplayoflight.wordpress.com/2013/12/30/readings-on-physically-based-rendering/
It is very important to read the principles behind this rendering system. The articles will describe the terms and methods used to create new and interesting materials.
MGE XE specific explanations
First, you must be familiar with the different material inputs, which are explained in the PBR articles above. Every engine uses a slightly different materials setup, as textures have to be packed with as much information as possible. MGE XE uses albedo, roughness (not gloss/shininess), metallicity (not specular colour), F0 (incident Fresnel reflectivity), and specular occlusion (aka cavity map). These terms should be easily researchable by looking up "PBR" + the term.
Examine the textures in the crate example. All four channels in the optical map need to be separated. I'm only a technical artist, so it's a medium quality result from a great base texture and a 15 minute baked normal map. In particular the rivet normals don't match the texture at all, and higher quality normals may improve it a lot.
The most interesting surface texture is contained in the roughness channel. It simulates variation in surface texture at about the same scale as the sense of touch, much smaller than a normal map texel.
Other channels need less detail. You can start with only one value per visual material for metallicity and F0. The cavity map is quite important to prevent specular inside creases, pits and overhangs. It can be produced by using levels on the albedo map, or directly if you are baking normals.
F0 is linearly encoded. That means the non-metal range of 0.02-0.08 becomes colour value 5-20. Higher values just lead to a washed out appearance as light is just being reflected back at you. It seems more sensitive to variation than I thought.
An optical parameters texture is not 100% required if the texture is a uniform type of material. Most important to add is roughness which you can pack into the normals alpha.
The optical parameters texture is packed with red:metallicity, green:roughness, blue:F0, alpha:specular occlusion. These are linearly mapped, so for all channels 0/255 makes that parameter 0.0, 128/255 becomes ~0.5, and 255/255 becomes 1.0.
As a starting point for an optical parameters texture you can set red=0, green=roughness, blue=8/255 (try to use physical reference values material composition), alpha=cavity map. Its should compress well with DXT5. Please keep the source data, I may need to make changes to the parameter ranges in the future.
Technical
Technically the PBR beta implements:
- Tangent-space normal reconstruction and normal mapping
- Cook-Torrance BRDF using GGX and height-correlated Smith
- Simple anolytic sky hemisphere environment
- PBR parameters and source textures
- Automatic scaling of light intensity
- Configurable material specification files
PBR advances three parts of rendering: lighting, materials and imaging. While I rely on you all to make great materials, the lighting in Morrowind is tuned for a simpler era. Trying to use it in a PBR render seriously alters global colouration. That means automatic recalibration of all lighting (and proxies like vertex colours) is required. It is currently imperfect for coloured lights, but will be improved.
e.g. with simple lighting:
a point light fsRGB + an ambient light gsRGB = (fsRGB+gsRGB)sRGB where N.L = 1 and gsRGB where N.L = 0
to get a colour match with linear lighting:
flinear = sRGBtoLinear(fsRGB+gsRGB) - glinear, glinear = sRGBtoLinear(gsRGB)
a point light flinear + an ambient light glinear = sRGBtoLinear(fsRGB+gsRGB) where N.L = 1 and sRGBtoLinear(gsRGB) where N.L = 0
which resolves into the desired values on conversion back to sRGB.
Issues
Note that only sunlight creates specular at the moment. Cook-Torrance with 8 lights is very expensive, and no curent professional engine actually tries to do more than 2-4 dynamic lights. Unfortunately Morrowind is all dynamic lights, everywhere. I'm looking into rendering specular for the two most important lights if it's possible to determine.
Shadow rendering is decoupled from the PBR rendering still, so specular is not correctly occluded fully. Correct rendering would require adding shadow code to all materials instead of rendering it later. Rendering shadows in a separate pass takes advantage of early Z rejection to reduce overdraw, which would also be lost.
There are no light probes, so IBL becomes very difficult. There is currently an integrated sky hemisphere instead. It actually makes the sky colour in interiors important, which should get fixed.
There may be minor problems rendering multi-texture blending correctly, e.g. land tiles, because of the complexity of blending two materials.
The material loading is logged in mgeXE.log, so you can see if your texture is detected with a line "-- Loading PBR material
Linear / PBR lighting disabled on non-zwrite alphas. There's a very big difference when the pixel shader is linear but the alpha blending with the frame buffer isn't. There was also an issue where the standard sunflare texture was using PBR lighting.