[TUTORIAL] How to make LoG2 Normal Maps

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
minmay
Posts: 2656
Joined: Mon Sep 23, 2013 2:24 am

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by minmay » Tue May 19, 2015 6:11 pm

THOM wrote:If it's bound to the compression-format I don't understand the discussion here. So is it right, that the filesize is always the same, depending on the compression format? A thing I would never consider of (and therefore never had googled for).
DXT5 is always 128 bits per 16 pixels. DXT3 is always 128 bits per 16 pixels. DXT1 is always 64 bits per 16 pixels. If you wanted to use DXT5 and DXT1 compression, but genuinely never considered learning what they are, then I think you need to slow down a bit.
THOM wrote:Problem in my case: If I choose another compression-option, the result is weired. For egsample like this:

https://www.dropbox.com/s/ugkuyegxl6b3k ... s.jpg?dl=0
Since green-alpha normal maps store one axis in the alpha channel, and DXT1 doesn't have an alpha channel, DXT1 is not an appropriate way to store them. (Incidentally, DXT1 really isn't appropriate for any normal maps, as it degrades colour information very badly and makes the colour channels highly interdependent - see here).
The entire point of the green-alpha normal map system is to allow using S3 compression without totally ruining the map, because the alpha channel in DXT3 and DXT5 has better resolution than the colour channels, and the green channel has the second best resolution.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.

User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by gambit37 » Thu Oct 29, 2015 10:04 am

I'm curious about the "copy red to alpha, make blue and red black" method. What information is lost in this transformation? The blue channel often has quite a bit of visual information in it, and by blanking it out, surely the normal map is degraded somewhat?

minmay
Posts: 2656
Joined: Mon Sep 23, 2013 2:24 am

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by minmay » Thu Oct 29, 2015 10:29 am

gambit37 wrote:I'm curious about the "copy red to alpha, make blue and red black" method. What information is lost in this transformation? The blue channel often has quite a bit of visual information in it, and by blanking it out, surely the normal map is degraded somewhat?
No information is lost by dropping the blue channel. As long as you have two of the three coordinates, that's enough to compute the third one (which the shader typically does on the fly in cases like these).
The only quality you lose comes from the DXT5 compression, since it is a lossy compression method. DXT1 compressed normal maps are awful, they barely look better than uncompressed 8-bit rgb normal maps, because you only have a resolution of 6 bits for one coordinate and 5 bits for the other two (or one, if you drop the blue channel), AND the channels are interdependent leading to further compression artifacts.
In DXT5 with the green/alpha method, you have 6 bits for the green channel and 8 bits for the alpha channel, which gives you higher resolution, AND the channels are independent, which helps a lot with compression artifacts. You use double the memory and disk space compared to DXT1, of course, but the quality of DXT1 normal maps is so awful that you would pretty much never want to use them anyway. The DXT5 way offers much more usable quality, and is still 75% smaller than a completely uncompressed RGBA normal map (which is what Grimrock 1 uses).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.

User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by gambit37 » Wed Nov 04, 2015 9:21 am

Excellent, thank you for the detailed explanation minmay. It makes sense that LoG2 switched to DXT5 compressed normal maps for the space saving alone, in my experiments I see it makes a huge difference.

I'm new to modding true 3D games, so there's a lot of new stuff to learn. Back in the day, I nodded Doom and Duke Nukem 3D, as well as the original Dungeon Master and clones like RTC and DSB. A lot of what I learned there is transferable to LoG2 modding. Of course, the big knowledge gap for me is working with 3D modeling, so there's a bit of a road ahead. Looks like I'll need to learn Blender to do anything really fancy...

Thanks again for your detailed help. You are a credit to the community. :)

User avatar
petri
Posts: 1898
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by petri » Wed Nov 04, 2015 10:20 am

@gambit: I suggest you also take a look at ZBrush, it's a sculpting program that we use to make the high poly versions of Grimrock monsters.

User avatar
Isaac
Posts: 2949
Joined: Fri Mar 02, 2012 10:02 pm

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by Isaac » Wed Nov 04, 2015 10:20 am

gambit37 wrote:Looks like I'll need to learn Blender to do anything really fancy...
Blender is really cool; really powerful.

John Wordsworth's grimFBX utility converts Blender exported FBX models to Grimrock model format, and writes the separate animation files if there are animations in the FBX.

*The link is in his SIG.

minmay
Posts: 2656
Joined: Mon Sep 23, 2013 2:24 am

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by minmay » Mon Feb 15, 2016 8:50 am

Phitt wrote:I'm not sure if the GIMP plugin creates different normal maps by default than the nVidia Photoshop plugin, but with the nVidia plugin using default settings you need to invert the green channel (or export with y inverted), then copy the green channel into the alpha channel, copy the red channel into the green channel and do the rest as you described. Otherwise the lighting on the normal map is off (tested that using a one color diffuse texture and a bumpy normal map with a single light source coming from one direction to see if the shading was correct).
So I finally looked into how the GIMP plugin does it, and what you have to do in order to convert an RGB normalmap to a green-alpha one in GIMP is:
1. Copy the green channel to the alpha channel.
2. Copy the red channel to the green channel.
3. Fill the red and blue channels with black as usual.
No inversion is involved.
You can test this by grabbing a normalmap from Grimrock 1 and the corresponding normalmap from Grimrock 2, for example, assets/env/chain_metal_normal.dds which is present in both asset packs and therefore in both formats. Then use your converting procedure, and if it ends up the same as the Grimrock 2 version, you did it right.

Edit: I've looked at the gimp-dds source, and the only differences between the DXT5 and DXT5nm export options are that DXT5nm adds the normalmap flag to the file (which Grimrock doesn't care about afaik), moves the red channel to the alpha channel, and fills the red channel with white (not black). It doesn't change the compression or mipmap generation algorithm. So I see no reason to use it over the plain DXT5 export option.

Also, here's a Script-Fu script I made to convert RGB maps to Grimrock style green-alpha ones automatically, including the mipmaps. This allows you to convert Grimrock 1 normal maps to Grimrock 2 normal maps with the press of a button, and without degrading the quality by regenerating mipmaps. It fills the red and blue channels with the current background colour, so you probably want to select black for the background colour before running it. It also serves as a demonstration of how terrible my Scheme knowledge is:

Code: Select all

(define orig-image 0)

(define (rgb-ga-layer layer)
  (plug-in-normalmap 1 orig-image layer 0 0 1 0 0 0 8 0 0 0 0 0 layer)
  (let*
  (
  (new-image (car (plug-in-decompose 1 orig-image layer "RGBA" 1)))
  )
  (gimp-edit-copy (car (gimp-image-get-layer-by-name new-image "green")))
  (gimp-floating-sel-anchor (car (gimp-edit-paste (car (gimp-image-get-layer-by-name new-image "alpha")) TRUE)))
  (gimp-edit-copy (car (gimp-image-get-layer-by-name new-image "red")))
  (gimp-floating-sel-anchor (car (gimp-edit-paste (car (gimp-image-get-layer-by-name new-image "green")) TRUE)))
  (gimp-drawable-fill (car (gimp-image-get-layer-by-name new-image "red")) 1)
  (gimp-drawable-fill (car (gimp-image-get-layer-by-name new-image "blue")) 1)
  (plug-in-recompose 1 new-image layer)
  )
)

(define (script-fu-rgb-ga img)
  (gimp-image-undo-group-start img)
  (set! orig-image img)
  (for-each rgb-ga-layer (vector->list (cadr (gimp-image-get-layers img))))
  (gimp-displays-flush)
  (gimp-image-undo-group-end img)
  (list img)
)

(script-fu-register
  "script-fu-rgb-ga"
  "RGBA to Green-Alpha"
  "Convert an RGBA normal map to a Green-Alpha one."
  "Andrew Minton"                             ;author
  "cc0 or whatever"        ;copyright notice
  "February 19, 2016"                          ;date created
  "RGBA"                     ;image type that the script works on
  SF-IMAGE "Image" 0
)
(script-fu-menu-register "script-fu-rgb-ga" "<Image>/Colors/Components")
Remove the "(plug-in-normalmap 1 orig-image layer 0 0 1 0 0 0 8 0 0 0 0 0 layer)" line if you don't want to normalize the RGB map first (I included it because sometimes people compressed their Grimrock 1 normalmaps with DXT1, which degrades the quality really bad, and renormalizing generally makes the damage a little less noticeable)
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.

User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by AdrTru » Sat May 07, 2016 1:33 pm

I discover new possibility how to make plugins for Paint.net

I make very easy plugin for conversion LOG1.normal to LOG2.nomal and LOG2.normal to LOG1.nomal.
Plugin tested picture and use the correct conversion.

Installation: Copy .dll file from http://ulozto.cz/xASV3gs9/log1tolog2normal-dll to PaintNet/Effects directory.

In menu/Effects/NormalMap/ is created plugin "LOG1 to LOG2 normal map convert"


here is code for CodeLab plugin in PaintNet ( only for info )
SpoilerShow

Code: Select all

// Name:Log1 to LOG2 normal map convert 
// Submenu: NormalMap
// Author: Adrtru
// Title:
// Version: 1
// Desc:
// Keywords:
// URL:
// Help:
#region UICode
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
    ColorBgra CurrentPixel;
    
    bool LOG1 = ( src[1,1].B == 0 ) ;
    
    for (int y = 0; y < rect.Bottom; y++)
    {
        for (int x = 0; x < rect.Right; x++)
        {
            CurrentPixel = src[x,y];
            if (LOG1 ) {
             CurrentPixel.R = CurrentPixel.A;
             CurrentPixel.A = 255;
             CurrentPixel.B = 255;
             CurrentPixel.G = CurrentPixel.G;
             } 
             else 
             {
             CurrentPixel.A = CurrentPixel.R;
             CurrentPixel.R = 0;
             CurrentPixel.B = 0;
             CurrentPixel.G = CurrentPixel.G; 
             }
            dst[x,y] = CurrentPixel;
        }
    }
}

My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,

User avatar
Eleven Warrior
Posts: 726
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: [TUTORIAL] How to make LoG2 Normal Maps

Post by Eleven Warrior » Sun May 08, 2016 4:12 am

Will try this out ArdTru cool matey :)

Post Reply