-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
normalmap compressed with crunch -dxn
are loaded with reverted B channel
#183
Comments
crunch -dxtn
are loaded with reverted B channelcrunch -dxn
are loaded with reverted B channel
Is it related to DaemonEngine/crunch@902f075 ? This crunch commit talks about things “that breaks reconstruction of the z part in DXN compressed normal maps”. And we have an issue with z part. @gimhael, does that ring a bell to you? The bizarre thing is that we used |
The current code for reading normal maps comes from here: https://therealdblack.wordpress.com/2010/06/26/texture-tools-and-normal-maps/ It references: http://realtimecollisiondetection.net/blog/?p=28 This is done so that all of the possible normal map formats can be loaded without additional shader permutations. Here is the existing code with comments for reference:
Some details on the formats: Here are the normal map formats we support: Uncompressed RGB(A) texture
This is correct for the assumptions made. DXT1/BC1 compressed texture This format obviously works with the z recalculation from before. DXT5/BC3 compressed texture (DXT5nm) x is stored in the alpha channel because the alpha channel is compressed separately from rgb channels in this format. This weird layout greatly enhances the quality for compressed normal maps. See this nvidia post for a comparison. With the existing function, you get the following when simplified:
So the same shader code gives the correct result. BC5/3Dc/Red Green compressed texture See the RGB(A) calculation for the proof that it works. With OpenGL 3.3+ or the ARB_texture_swizzle extension, you could use texture swizzle masks to avoid the extra multiply with alpha, and similarly avoid extra shader permutations. |
Thanks @cmf028 for that awesome piece of knowledge! And thanks to be there :D. I guess it also explains why normal maps compressed with It would be very good to create a wiki zone for such engine design choice, something titled like “Engine design and behavior” and sub-articles to knowledge like this one or this one. So it looks like we have a collision with “heightmap in normal map alpha channel” feature and “normal map compression using alpha channel” hack. This is calling for a proper support of lose heightmaps. This is basically the formats we would have to support:
And the features:
The later is sometime called bump map but dæmon uses both Note that to easily add the support of these feature a revamp of stage collapsing is required first because without a revamp the number of conditional blocks to code to support |
Note that just for knowledge about the alpha channel DXT trick, I noticed that an heightmap in alpha channel of a PNG file with a pure blank RGB stream can compress smaller than an heightmap in a PNG grayscale stream. This even after being optimized by multiple optimisers like |
Fixed in PR that was breaking it. |
This bug was uncovered in #180.
All our normal maps are compressed with
crunch -dxn
and our engine loads them with reverted blue channel (Z component). This was hidden by the bug in the normalmap code that was loading the Z component from alpha channel instead of blue one. Hopefully we did not ship any heightmap in alpha channel and sincecrunch -dxn
drops the alpha channel in any way, it looks like the engine was just using an empty Z component). The normalmap loads correctly if loaded from another format (like webp).With
r_normalMapping
disabled:With
r_normalMapping
enabled and normal map compressed withcrunch -dxn
:With
r_normalMapping
enabled and normal map compressed withcrunch -dxn
and Z component reverted in engine to workaround the bug:With
r_normalMapping
enabled and normal map compressed withwebp
:The source tree in #180 is meant to be correct. I created a test map with assets I created to be sure they are the way they must be, then fixed the engine to render the test map. The correct engine in this tree is able to render correctly xonotic maps and unvanquished maps if their normal maps were not compressed with
crunch -dxn
.We need someone to fix the normalmap loading when they are compressed with
dxn
(use the branch in #180 branch as a base as master is not correct).The symptom is a map being almost entirely dark. No need for special map to reproduce the bug, just load released
chasm
with this branch (or any other map):It may be possible that the whole normalmap is reverted, reverted red (X) and reverted green (Y) leads to subtle changes while reverted blue (Z) just break everything.
I'll upload the test map soon but testing with released maps is enough to reproduce the bug. The test map will be useful to check that the bug is entirely fixed. While it's very easy to check for the correct loading of the blue channel with any released map, it may be very difficult and time-consuming to check for the correct loading of red and green channel without the test map.
The text was updated successfully, but these errors were encountered: