Closed walbourn closed 5 years ago
The DXT5nm solution is really only needed for feature level 9.x. 3Dc (BC5) is better quality.
There are eight possible shader scenarios here:
BiasX2
z = sqrt( 1. - dot( xy, xy ) );
BiasX2
then z = sqrt( 1. - dot( xy, xy ) );
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.
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.
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.
I've added reconstruction for the Z channel to the shaders in this commit to support both scenarios.
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.
To sum up:
_UNORM
formats)_BC5_UNORM
format)All of this is captured in the wiki
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:
3Dc
)DXT5nm
)Understanding BCn Texture Compression Formats
Real-Time Normal Map DXT Compression