Page 1 of 1

The Material System in the New Shaders

Posted: Mon May 04, 2020 6:50 am
by blue_max
A couple of releases ago (?) I introduced the concept of materials in XWA through ddraw, but I haven't really sat down to explain how it works. Please, bear in mind that it would've been impossible to write material definition files for all OPTs out there. Instead, I had to make a few compromises to come up with something that looks "generally OK" for most crafts. The material system is inspired by Blender's Principled Shader and it's also based on my own experience when using the Blender Cycles system.

Anyway, the material system is based on three main settings: Metallicity, Intensity (of the specular reflection), and Glossiness. When writing a new material definition file, the first thing you've got to decide is the metallicity of the material. This value goes from 0 (not metallic at all, like plastic or wood) to 1 (completely metallic). In practical terms, metallicity affects the tint of the specular reflection and how the surface reacts to ambient illumination.

Metallicity 0: The specular reflection is gray/white. The lightness of the texture from the OPT is used to compute how bright is the specular reflection. Ambient illumination directly increases the illumination of the surface
Metallicity 1: The specular reflection is tinted by the color of the surface (the texture from the OPT). Ambient illumination is ignored.

For example, look how the specular reflection is tinted red on the left; but is white on the right in the following image:

Metallic-00-05.png

For the ambient illumination part, look at the following image:

Metallic-Levels.png

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 6:59 am
by blue_max
The next setting is the Intensity of the specular reflection. This value goes from 0 (no specular reflection at all) to 1 (super bright specular reflection). This is easy to understand with another example:

Intensity-Levels.jpg

Glossiness controls the size of the specular reflection. I'm using the Phong Illumination model, so this guy (roughly) corresponds to the exponent of the specular component. Eh... It means it's non-linear. Glossiness 0 is a very wide specular reflection. Glossiness 1 is a very focused and small specular reflection, like glass:

Glossiness-Levels.jpg

I'm glossing over some technical details, but this is the gist.

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 7:13 am
by blue_max
The next setting is the NMIntensity or Normal Mapping Intensity. This is still fake normal mapping and it's based on whatever is rendered on the screen... If you've ever done an embossing filter on an image, it's about the same thing. It's not perfect and I know it causes some artifacts here and there, so I still need to work on that. Another concept that is easier to understand with images:

NMIntensity.jpg

I mentioned earlier that the specular reflection is based on the color of the surface, for both metallic and non-metallic textures. An easy rule is "a white surface will reflect more light than a dark surface". But this is a problem for surfaces that are (nearly) black, like the panels of a TIE-Fighter. In this case, the Intensity setting above won't work at all:

T-F-Intensity.jpg

To fix this problem, I introduced another setting called "SpecularVal" which adds a white specular component to surfaces that won't otherwise display any:

SpeVal-05.jpg

The size of the SpecularVal sheen is also controlled by the Glossiness setting.

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 7:21 am
by Darksaber
lol Thank you :D

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 7:45 am
by BenKenobi
Wow, great work!

First in bringing it to XWA and second in showing how it works and is to be used!

:2thumbs:

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 8:15 am
by blue_max
Thanks for your comments guys; but there's more!

Glass: Early on in the process I decided that if a surface was (semi-)transparent, it had to be glass of some sort. So every surface with transparency above, er, 90% or so (need to double-check that) is automatically rendered with maximum glossiness and a white specular value. However, this is not true for all transparent surfaces. For instance, some hangars have tubes hanging from the ceiling and they will look quite weird. So, to remove the specular sheen on surfaces with transparency you need set the surface as "Shadeless" and use following settings:

Code: Select all

[TEX000NN]
Shadeless   = 1
Intensity   = 0.0
Glossiness  = 0.1
NMIntensity = 0
Laser lights and Sun Colors: Lasers now emit light; but the color and intensity of the light is read from a material file. The format is:

Code: Select all

Light = Red, Green, Blue
Each component should be in the range 0..1. Each Laser OPT comes with multiple colors, so there's multiple entries in the .mat files for the lasers too (just take a look at any Laser*.mat file and you'll see what I'm talking about). Starting on release 1.1.3, Sun colors are also configured using the "Light" setting.

The Default Global Material: In release 1.1.3 I added a new special file (DefaultGlobalMaterial.mat) that contains the default settings for all OPTs that don't have a materials definition file. This file can be used to reduce or eliminate the normal mapping for all OPTs, for instance.

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 9:54 am
by korekwerner
now I know why in star wars Battlefront 2 (from EA) there are no space battles we have been waiting for. Because BlueMax has switched from DICE to XWAU and supports fans, not corpo. :-)
A lot of work, but with a focus on the most important models, it can be done in half a year.

KW

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 3:26 pm
by Jaeven
This is very informative. Thank you!

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 5:15 pm
by Vince T
Great Thread, that's extremely helpful! Good work!

Re: The Material System in the New Shaders

Posted: Mon May 04, 2020 8:34 pm
by blue_max
A few more details. Material files have the format "Materials\<OPTName>.mat". Inside, there can be several sections:

Code: Select all

[Default]
Metallic   = 0.25
Intensity  = 0.5
Glossiness = 0.1
The [Default] section applies the settings to all the surfaces in this OPT, overriding the settings from DefaultGlobalMaterial.mat.

Individual surfaces can be grouped together, like this (don't put more than 10 texture names per row, though):

Code: Select all

[TEX00000,TEX00001,TEX00002,TEX00003,TEX00004,TEX00005,TEX00006,TEX00007]
Metallic   = 0.5
Intensity  = 0.8
Glossiness = 0.1

[TEX00027,TEX00028,TEX00029,TEX00030]
Metallic   = 0.5
Intensity  = 0.8
Glossiness = 0.1
The texture names are case sensitive. So "TexNNNNN" is different from "TEXNNNNN". Yeah, I know, I should fix that later... :P

The DefaultGlobalMaterial.mat file doesn't have a [Default] section... it's already default!

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 12:04 am
by Bman
Superb! Thanks for explaining.

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 1:28 am
by Kampher
Thank you very much for taking the time to document all of this, it's very helpful.

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 3:17 am
by Mark_Farlander
Awesome effects as always, Blue!

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 3:31 am
by Driftwood
Don't forget to transition this and all your other existing/pending information into the modding wiki. I can't tell you how much stuff is buried in all of these threads, it's becoming a hassle to find certain "how x y z" works anymore.

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 4:06 am
by blue_max
Driftwood wrote:
Tue May 05, 2020 3:31 am
Don't forget to transition this and all your other existing/pending information into the modding wiki.
OK, but I think someone would need to grant me permission to create new wiki pages.

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 4:37 am
by Driftwood
blue_max wrote:
Tue May 05, 2020 4:06 am
Driftwood wrote:
Tue May 05, 2020 3:31 am
Don't forget to transition this and all your other existing/pending information into the modding wiki.
OK, but I think someone would need to grant me permission to create new wiki pages.
Double check, but you already should have access via your forum account. If not talk to GT, DS, or FF to make sure you have access.

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 7:41 am
by Darksaber
No good asking me about the wiki page, I haven't a clue, I don't use it, I think I may have been on it once lol

My heads my wiki lol

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 10:16 am
by Phoenix Leader
You continue to amaze me with all these new effects, Blue Max. Reflections on metallic and non-metallic textures are surely a great addition.

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 12:08 pm
by Trevor
I notice no support yet of normal/bump maps (instead of fake normal mapping based on texture colours)

It would be good to have support for greyscale bumpmaps so we can start making textures for proper surface granularity.

You might need a toggle to switch between bump and normal map later (normal maps are harder to make, but can look better)

Trev

Re: The Material System in the New Shaders

Posted: Tue May 05, 2020 5:19 pm
by Ace Antilles
blue_max wrote:
Tue May 05, 2020 4:06 am
Driftwood wrote:
Tue May 05, 2020 3:31 am
Don't forget to transition this and all your other existing/pending information into the modding wiki.
OK, but I think someone would need to grant me permission to create new wiki pages.
Talk to Forceflow about that. I haven't worked it out yet either lol

Re: The Material System in the New Shaders

Posted: Fri May 15, 2020 11:45 pm
by llemon
Doing a PBR like model is pretty neat. Are you going to do any gamma correction though?

Re: The Material System in the New Shaders

Posted: Sat May 16, 2020 2:43 am
by blue_max
llemon wrote:
Fri May 15, 2020 11:45 pm
Are you going to do any gamma correction though?
Done since day one :)

Re: The Material System in the New Shaders

Posted: Wed Jun 22, 2022 8:26 am
by Vince T
@blue_max I'll copy this topic over to the Guides section and remove the duplicate replies there. The topic will stay intact for discussion here.