Normal Map Texture Compression

Everything about mods can be found here.

Moderator: Morax

Normal Map Texture Compression

Postby Mortifero » 12 Aug 2016, 19:10

Do anyone have exact info about how the moho engine compresses the normal maps. I need the technical info. I have done my fair share of research about normal map compression. In fact i know how the moho engine compresses them/ removes blue channel as it can be recalculated easily later in the pixel shaders, the red channel goes to the alpha channel and the green channel stays as is(in RGB). What i need is the excact method, or even better a piece of software that can convert "normal" normal maps to the "grayscale" supcom ones. As far as i know the DXT5nm compression method is the most popular but using the gimp addon for that doesnt make my normal map "gray". I will be trying the ATI compressonator later.

Note:
i havent tried importing to the game any textures yet, so the dxt5nm normal maps from the gimp .dds addon may work, although i dought it.
User avatar
Mortifero
Crusader
 
Posts: 17
Joined: 18 Sep 2015, 17:07
Has liked: 1 time
Been liked: 3 times
FAF User Name: Mortifero

Re: Normal Map Texture Compression

Postby nine2 » 13 Aug 2016, 01:49

No :)

You can view the hlsl for the pixel shaders used to render it.. That could help u work it out?
nine2
Councillor - Promotion
 
Posts: 2416
Joined: 16 Apr 2013, 10:10
Has liked: 285 times
Been liked: 515 times
FAF User Name: Anihilnine

Re: Normal Map Texture Compression

Postby Mortifero » 13 Aug 2016, 12:25

Thanks for the reply Anihilnine(i always pronounce your name anihilator, gta vi-v memories)
I finally figured it all out. It was simple, but completely unobvious. GPG said that they used specificaly DXT5 compression for their normal maps. That bothered me for two days, as dxt5 compression is horrible for normal maps, thats why DXT5nm(normalmap) compression was invented. And i thought that was it xD. It wasnt. GPG really did use plain DXT5 compression. As i explained earlier, i figured that the red channel goes to the alpha channel, the blue is ingored by the engine and the green channel stays as is. Thats where all the confusion came from. I was not using photoshop and was trying to do everything in gimp. But photoshop displays the color channels differently. There is a RGB "channel" and you are supposed to copy the green channel to the RGB. What this does is copy the green channel to all other channels except the alpha one. This step here is what is completely unobvious for no photoshop users. This is what makes the normal map appear "grayscale. Then using either the nvidia photoshop .dds plugin export as DXT5(not DXT5nm).

So by doing all this we did the color channel swizzling that the DXT5nm compression method is supposed to do, but for me export a proper normal map as dxt5nm just didnt work ever in any program i used.




Now for gimp users the process is dead simple to achieve the above: After creating your "normal" purple(ish) normal map,
Goto Color->Components->Decompose, click then select RGBA! instead of RGB. After that, all color channels should appear as grayscale layers. So select red layer ctrl+A and ctrl + C then select the alpha layer and paste it with ctrl+V. Now select the green layer and copy paste it on the red layer as well as the blue layer. Then goto color->components->compose, choose RGBA! and with the gimp .dds plugin export it as DXT5.

I havent tested this yet in game but i am fairly certain that it works.

Note:
Some people in all kinds of forums(not supcom specific) that they painted the red and blue layers(channels) with black(thus possibly reducing texture size) but that didnt work for me at all, it gave a messed up normal map that wasnt grayscale and i dont think it would work with supcom, but feel free to try it anyways. All that in gimp, didnt do any of the above in photoshop.
User avatar
Mortifero
Crusader
 
Posts: 17
Joined: 18 Sep 2015, 17:07
Has liked: 1 time
Been liked: 3 times
FAF User Name: Mortifero

Re: Normal Map Texture Compression

Postby ozonex » 16 Aug 2016, 10:22

Mortifero wrote:Now for gimp users the process is dead simple to achieve the above: After creating your "normal" purple(ish) normal map,
Goto Color->Components->Decompose, click then select RGBA! instead of RGB. After that, all color channels should appear as grayscale layers. So select red layer ctrl+A and ctrl + C then select the alpha layer and paste it with ctrl+V. Now select the green layer and copy paste it on the red layer as well as the blue layer. Then goto color->components->compose, choose RGBA! and with the gimp .dds plugin export it as DXT5.


Process in Photoshop looks almost the same, but there is no need to "Decompose", because in Photoshop all channels are always accessible.

When I was working on Map Editor and I waited code for reading dds files from FA, I found out that not all normal maps use DXT5 compression. Sometimes is BGRA32, and I also found one with RGB24. All data about how it will be converted to RGBA is written in DDS Header so I'm not sure if changing compression method will swap channels.

For some engines only Red and Alpha channels are used, so if engine reads normalmap directly, then they can clean G and B channels.

Maybe this can be usefull. Here is code where I gets loaded DDS textures RGBA pixels and convert it to Unity's Normal Map. Interesting is that only Red and Green channels are used. But maybe they are somehow swapped (when its RGBA instead of ARGB), then it will be Alpha and Red channel.
Code: Select all
for(int i = 0; i < Pixels.Length; i++){
   theColour.r = Pixels[i].r;
   theColour.g = Pixels[i].g;
   theColour.b = 1;
   theColour.a = Pixels[i].g;
   Pixels[i] = theColour;
}


Here is file with that code:
https://github.com/ozonexo3/FAForeverMapEditor/blob/master/Assets/Scripts/Ozone%20SCMAP%20Code/GetGamedataFile.cs
FAF Map Editor Alpha v0.605 > Get it now!
User avatar
ozonex
Priest
 
Posts: 358
Joined: 16 Feb 2012, 20:11
Location: Poland
Has liked: 197 times
Been liked: 263 times
FAF User Name: ozonex

Re: Normal Map Texture Compression

Postby Cuddles » 16 Aug 2016, 14:17

Turinturambar defended very valiantly
User avatar
Cuddles
Contributor
 
Posts: 692
Joined: 29 Mar 2013, 14:19
Has liked: 132 times
Been liked: 118 times
FAF User Name: Scoot

Re: Normal Map Texture Compression

Postby Mortifero » 16 Aug 2016, 18:48

Yes exactly that ozonex, the moho engine discards blue and red channels, it only uses the alpha and green, channel that's why the red channel must be copied to the alpha channel. About the compression, I head that even by using dxt5 for all the textures, works. I haven't tested that though.

Thanks for the link cuddles, I did run into that couple weeks ago, interesting that jon mavor responded.

Thanks for the help guys! Much appreciated.
User avatar
Mortifero
Crusader
 
Posts: 17
Joined: 18 Sep 2015, 17:07
Has liked: 1 time
Been liked: 3 times
FAF User Name: Mortifero


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest