The Material System in the New Shaders

Want to edit the game, build your own craft and missions? Here you'll find help, tools, guides and people to discuss with.
Post Reply

The Material System in the New Shaders

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Mon May 04, 2020 6:50 am

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
You do not have the required permissions to view the files attached to this post.

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Mon May 04, 2020 6:59 am

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.
You do not have the required permissions to view the files attached to this post.

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Mon May 04, 2020 7:13 am

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.
You do not have the required permissions to view the files attached to this post.

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Mon May 04, 2020 7:21 am

lol Thank you :D
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
BenKenobi
Cadet 2nd Class
Posts: 94
Joined: Wed Mar 18, 2020 12:30 pm

Post by BenKenobi » Mon May 04, 2020 7:45 am

Wow, great work!

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

:2thumbs:

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Mon May 04, 2020 8:15 am

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.

korekwerner
Cadet 1st Class
Posts: 154
Joined: Wed Mar 20, 2019 7:04 pm

Post by korekwerner » Mon May 04, 2020 9:54 am

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

User avatar
Jaeven
XWAU Member
Posts: 578
Joined: Mon Mar 30, 2015 3:18 am

Post by Jaeven » Mon May 04, 2020 3:26 pm

This is very informative. Thank you!

User avatar
Vince T
Fleet Admiral (Administrator)
Posts: 14045
Joined: Fri Apr 27, 2001 11:01 pm
Contact:

Post by Vince T » Mon May 04, 2020 5:15 pm

Great Thread, that's extremely helpful! Good work!
Your ship, Captain. I need a drink. - Vince Trageton
Vince T's X-Wing HQ - where the bad guys get their gear

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Mon May 04, 2020 8:34 pm

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!

Bman
Lieutenant Commander
Posts: 1167
Joined: Mon Apr 05, 2004 11:01 pm

Post by Bman » Tue May 05, 2020 12:04 am

Superb! Thanks for explaining.
W-I-P: TFTC, MC Viscount Cr., ISD-II Avenger, NL-1 Platform, Ton-Falk Esc. Cr., & Misc.

Kampher
Cadet 2nd Class
Posts: 79
Joined: Tue May 09, 2006 11:01 pm

Post by Kampher » Tue May 05, 2020 1:28 am

Thank you very much for taking the time to document all of this, it's very helpful.

User avatar
Mark_Farlander
Rebel Alliance
Posts: 580
Joined: Tue Jan 16, 2018 10:47 pm

Post by Mark_Farlander » Tue May 05, 2020 3:17 am

Awesome effects as always, Blue!
I don't judge tactics. The Battle is the best and only Judge.

User avatar
Driftwood
Admiral (Moderator)
Posts: 2174
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Tue May 05, 2020 3:31 am

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.

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » 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.

User avatar
Driftwood
Admiral (Moderator)
Posts: 2174
Joined: Wed Oct 22, 2003 11:01 pm
Contact:

Post by Driftwood » Tue May 05, 2020 4:37 am

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.

User avatar
Darksaber
Vice Admiral
Posts: 10931
Joined: Mon Jan 10, 2000 12:01 am
Contact:

Post by Darksaber » Tue May 05, 2020 7:41 am

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
“You can please some of the people all of the time, you can please all of the people some of the time, but you can’t please all of the people all of the time”.”
- John Lydgate

Good Things Come To Those Who Wait....
Darksaber's X-Wing Station

User avatar
Phoenix Leader
Rebel Alliance
Posts: 437
Joined: Wed Aug 08, 2018 2:20 pm

Post by Phoenix Leader » Tue May 05, 2020 10:16 am

You continue to amaze me with all these new effects, Blue Max. Reflections on metallic and non-metallic textures are surely a great addition.

User avatar
Trevor
Lieutenant JG
Posts: 541
Joined: Thu Dec 04, 2014 7:11 pm

Post by Trevor » Tue May 05, 2020 12:08 pm

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

User avatar
Ace Antilles
Admiral (Moderator)
Posts: 7829
Joined: Sat Jan 22, 2000 12:01 am
Contact:

Post by Ace Antilles » Tue May 05, 2020 5:19 pm

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
Chief XWAU Team annoying nitpicker.
Ace Antilles - The X-Wing Outpost
Image

llemon
Recruit
Posts: 5
Joined: Sun Mar 31, 2019 2:16 pm

Post by llemon » Fri May 15, 2020 11:45 pm

Doing a PBR like model is pretty neat. Are you going to do any gamma correction though?

User avatar
blue_max
XWAU Member
Posts: 2295
Joined: Wed Mar 20, 2019 5:12 am

Post by blue_max » Sat May 16, 2020 2:43 am

llemon wrote:
Fri May 15, 2020 11:45 pm
Are you going to do any gamma correction though?
Done since day one :)

User avatar
Vince T
Fleet Admiral (Administrator)
Posts: 14045
Joined: Fri Apr 27, 2001 11:01 pm
Contact:

Post by Vince T » Wed Jun 22, 2022 8:26 am

@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.
Your ship, Captain. I need a drink. - Vince Trageton
Vince T's X-Wing HQ - where the bad guys get their gear

Post Reply