MGE XE Physically-based Rendering Prototype

Post » Tue Jan 26, 2016 5:06 pm

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 ", and any loading problems there. It has to intercept the loading of textures, which may not be 100% yet.



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.

User avatar
Jack Moves
 
Posts: 3367
Joined: Wed Jun 27, 2007 7:51 am

Post » Tue Jan 26, 2016 12:08 pm

http://www.nexusmods.com/morrowind/mods/26348?.


Changelog


- Auto material path mostly fixed. Successful auto lookups will appear in mgeXE.log.

- Working mipmaps + anisotropic sampling on normals and optical parameter textures.

User avatar
aisha jamil
 
Posts: 3436
Joined: Sun Jul 02, 2006 11:54 am

Post » Tue Jan 26, 2016 10:52 pm

Thank you, Hrnchamd! This sounds very interesting.

User avatar
Victoria Bartel
 
Posts: 3325
Joined: Tue Apr 10, 2007 10:20 am

Post » Tue Jan 26, 2016 4:33 pm

Powerful Hrnchamd.

User avatar
Latino HeaT
 
Posts: 3402
Joined: Thu Nov 08, 2007 6:21 pm

Post » Tue Jan 26, 2016 9:57 pm

Here is a little gallery showing normal mapped vanilla textures all using the default material: https://imgur.com/a/XAYbx

Of course very low res but still a good base to have I think. I might upload that thing to the nexus soon, its only 60 mb.

The lighting is amazing. I can imagine that even current settings will look just great when speculars and fresnel are excluded by shadows.

Frames in the middle of Balmora go down from 45 to 18 for me. (GTX 760, Intel i5 6500, 16gb ddr4)
In the wilderness it drops from 60 (vsync cap, cant deactivate it) to 29 frames.


So texturers please be realy careful with your texture sizes! Reasearch if in doubt ;)
User avatar
Lizbeth Ruiz
 
Posts: 3358
Joined: Fri Aug 24, 2007 1:35 pm

Post » Tue Jan 26, 2016 10:10 am

https://imgur.com/a/zgviU.


I mgeXE.log everything good:



May be something wrong with textures?

User avatar
Chica Cheve
 
Posts: 3411
Joined: Sun Aug 27, 2006 10:42 pm

Post » Tue Jan 26, 2016 12:33 pm

I developed the fix using your textures. It's still working here, maybe I should add more logging.



Edit: Updated the download with extra shader logging. Please run that, cycle all the lighting modes and post the log.

User avatar
Amanda Leis
 
Posts: 3518
Joined: Sun Dec 24, 2006 1:57 am

Post » Wed Jan 27, 2016 12:11 am

Do what?

User avatar
michael danso
 
Posts: 3492
Joined: Wed Jun 13, 2007 9:21 am

Post » Tue Jan 26, 2016 7:47 pm

You have to bind the function to cycle the lighting modes to a macro. The normal dynamic lighting is the default and doesn't show the new mapping techniques.

User avatar
Ronald
 
Posts: 3319
Joined: Sun Aug 05, 2007 12:16 am

Post » Tue Jan 26, 2016 1:37 pm

What I need to click to do it?

User avatar
Carolyne Bolt
 
Posts: 3401
Joined: Mon Jul 10, 2006 4:56 am

Post » Tue Jan 26, 2016 2:33 pm

First you have to open MGEXEgui.exe and switch to the In-Game tab. Then open the macro editor and click on a button you want to bind. Then select function and "Toggle lighting mode". Save and start up the game. Once in-game press the button you bound the macro to to cycle the lighting mode until you have the correct lighting setting.

User avatar
louise hamilton
 
Posts: 3412
Joined: Wed Jun 07, 2006 9:16 am

Post » Tue Jan 26, 2016 4:06 pm

Ok, thank you!


PBR lighting mode is now work for me:


http://i.imgur.com/zG2nabN.jpg


But it also make bump-mapped models to look ugly:


http://i.imgur.com/OmhFDFI.jpg

User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am

Post » Tue Jan 26, 2016 9:12 am

I'm trying to think of forum-appropriate terminology to use to describe my response to viewing this gallery... please do release this. I would love to experience this for myself. I'll have to skip work that day to recover.

User avatar
Heather beauchamp
 
Posts: 3456
Joined: Mon Aug 13, 2007 6:05 pm

Post » Wed Jan 27, 2016 12:16 am


I agree! I..we..need.. this! :icecream:

User avatar
Stace
 
Posts: 3455
Joined: Sun Jun 18, 2006 2:52 pm


Return to III - Morrowind