renderer/tr_shader: introduce engine-agnostic normalFormat material stage keyword#307
Conversation
|
This implementation or another one is required for Unvanquished 0.52 because Vega normal maps have to be fixed in a way we don't have to edit materials in the future again. Editing the pictures themselves must be avoided to not uselessly increase the git repository size. |
|
After some deep thoughts, this is the syntax: Even if I have no plan to implement it in engine for normal maps, this syntax allows to implement swizzling. I would like to implement swizzling for PBR maps ( |
|
For files that provide only X and Y channels and infer Z, what does it mean to put -Z? Does it do anything? |
|
Hmm, Right! Z must only be modified with |
dae6cbf to
6ad298a
Compare
|
Well, because of all those corner cases requiring a better source code to be targeted properly, I had to do the refactorization I was first hoping to be able to postpone for after the next release. So this PR is now built atop #317. |
|
New code will not apply custom format transformation on Z if Z is reconstructed from X and Y, but will still apply custom scale on Z. |
86854ac to
7041894
Compare
|
Just rebased. |
|
I forgot to tell it before, but that new code based on the recent factorization (#317) sets an |
|
I also added a warning when people use negative value with |
|
OK, now everything looks fine to me, I think I addressed all the comments. I'm just waiting for this to be merged to push the normal map format fixes on vega map and texture repositories. |
|
LGTM |
Introduce engine-agnostic
normalFormatmaterial stage keyword.There is already a
normalScalekeyword which allows to revert channel by using a negative value, but this is not a way to describe the format of the file that is loaded. So, people would have to use a negativenormalScaleY value in their.shaderfile if the normal map file is stored in DirectX way and the engine is computing normal maps the OpenGL way, but a positive YnormalScalevalue if file format and engine format matches.By introducing the
normalFormatstage keyword, artist can describe the normal map file format and don't mind about what the engine does. It also means the engine may switch its internal format without having to mind anything, the coder implementing another normal format would know how to convert the normal map file in engine whatever the format, not requiring him to ask artists to edit every existing.shadermaterial file.It was possible to make
normalScalekeyword engine-agnostic but that would be a very bad idea because this keyword exist in other engine of this lineage (idtech3 renderer2, OpenJK…, etc.). Then it's better to keep this keyword behaviour the way it works the same as other engine does.For making things easier to think of, the engine is currently assuming a default normal map format is OpenGL (+X +Y +Z), because it's easier to multiply every channel with
1.0by default whatever the channel when there is nothing to do.For backward-compatibility purposes and to keep compatibility with other engines (idtech3 renderer2, XreaL, ET:Legacy, OpenJK, etc.), the
normalMap,normalHeightMapkeywords andbumpMapdeprecated alias set the normal map format to DirectX one. Historically, the Doom 3 engine is an OpenGL engine using DirectX normal map format convention, and XreaL implemented normal maps in order to be able to load Doom3 formats, then expected DirectX normal maps. Engines like those I just quoted are reusing XreaL material stage keywords likenormalMapthat were Doom3 keywords at first, then are expecting DirectX format. It looks like we would have to live with it.While the
normalMapkeyword is expecting normal map in the DirectX format because of backward compatibility with historical engines and third-party ones, Dæmon-based games developers are free to encourage the use of normal map using OpenGL format, maybe use contribution guidelines asking for normal map using OpenGL format explicitely. In such case contributors would just have to add the required line to tell the normal map is using OpenGL format.The material stage keyword syntax is:
OpenGL format:
DirectX format (
normalFormatkeyword is not required sincenomalMapkeyword already does it):Weird format (like the one used in Vega texture set):
With this work, we may one day change the normal map format used in GLSL code (see #274) without having to mind anything: the material parser is telling the engine which conversion to do, and the assets would not have to be edited if they use the
normalFormatkeyword.The Vega map and texture set is expected to use the
normalFormatkeyword to fix normal map orientation in upcoming Unvanquished 0.52.With such design we would be able to add support for alternative material syntax from other games to load normal maps, in such case, the keyword parsing code would just have to set the normal map format this syntax expects. The Darkplaces compatibility layer already does it this way.
Here are the default normal map formats used in engine:
normalMapkeyword: DirectX_normsidecar autoloading: OpenGL