microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.5k stars 404 forks source link

NormalMapEffect/PBREffect support for normal texture encoding options #14

Closed walbourn closed 5 years ago

walbourn commented 8 years ago

Currently the NormalMapEffect assumes the normal-map is always a BiasX2 decode, which means you should always use a UNORM or positive-only format (R11G11B10_FLOAT).

Pixel-shader variants should be provided for other encodings:

Understanding BCn Texture Compression Formats

Real-Time Normal Map DXT Compression

walbourn commented 7 years ago

The DXT5nm solution is really only needed for feature level 9.x. 3Dc (BC5) is better quality.

walbourn commented 6 years ago

There are eight possible shader scenarios here:

The main value of the signed variants is that 0.5 can be exactly represented which unsigned formats can't do.

The green channel inverted scenarios are because there's both 'OpenGL' and 'DirectX' conventions where Y is either up or down depending on the pipeline, handedness, etc. Right now I'm assuming the green never needs inverted.

walbourn commented 6 years ago

Note that glTF2 uses the BiasX2 for normal maps (since they are always stored as PNG). As such, I think signed scenarios are not all that interesting.

walbourn commented 5 years ago

Since these effects only support tangent-space normal mapping, a reasonable solution is to just always reconstruct the z which works with either RGB or BC5.

walbourn commented 5 years ago

I've added reconstruction for the Z channel to the shaders in this commit to support both scenarios.

walbourn commented 5 years ago

To keep the shader permutations down, I'm going to leave the inverted green channel as a content issue. I added a -inverty switch to texconv to help with this scenario.

walbourn commented 5 years ago

To sum up:

All of this is captured in the wiki