Expanding on Tile Textures

Discuss modding questions and implementation details.
User avatar
Daniel87
Posts: 391
Joined: Thu Nov 28, 2019 6:25 pm

Expanding on Tile Textures

Post by Daniel87 »

Hey everyone.

I want to add a couple of additional tiles that are missing in the original tile set for landscapes. (mostly mirrored version of the originals plus a few missing variations). Does anyone know if this will be supported in the future?
In Julianos we Trust.

l3lessed
Posts: 1399
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: Expanding on Tile Textures

Post by l3lessed »

Where is the code for the tile generation and use for this located in base build? From the other threads discussions, it does seem like we may need a real math wizard to remedy this.

Technically, there is the tool to create dll overwrites of the original scripts. If we could sort it out and expand the original code to handle this, we could use this dll method to inject the new tiles and script/code right over the original base code. However, I imagine interkarma wouldn't mind a pull request being submitted at that point for it to be updated on the base engine.
My Daggerfall Mod Github: l3lessed DFU Mod Github

My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Daniel87
Posts: 391
Joined: Thu Nov 28, 2019 6:25 pm

Re: Expanding on Tile Textures

Post by Daniel87 »

l3lessed wrote: Fri Apr 23, 2021 7:50 pm Where is the code for the tile generation and use for this located in base build? From the other threads discussions, it does seem like we may need a real math wizard to remedy this.

Technically, there is the tool to create dll overwrites of the original scripts. If we could sort it out and expand the original code to handle this, we could use this dll method to inject the new tiles and script/code right over the original base code. However, I imagine interkarma wouldn't mind a pull request being submitted at that point for it to be updated on the base engine.
So images like tiles are stored in dll files? Oof, never worked with those. Is there good literature concerning how the tile textures work, I mean where they are stored, what part of DFU or DF loads them and handles them, how these catalogues of images work exactly, etc?
In Julianos we Trust.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Expanding on Tile Textures

Post by BadLuckBurt »

You don't need to do anything with a DLL. The terrain textures are stored with the other textures that you can just look at with Daggerfall Imaging.

The texture atlas is requested in Assets\Scripts\Terrain\DaggerfallTerrain.cs. Look at the InstantiateTerrain and UpdateClimateMaterial methods and dig deeper from there into the Assets\Scripts\MaterialReader.cs which is where the heavy lifting happens.

Under DaggerfallTools in Unity, there's also the Texture Array Creator, don't know how it works exactly but others probably do.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
Daniel87
Posts: 391
Joined: Thu Nov 28, 2019 6:25 pm

Re: Expanding on Tile Textures

Post by Daniel87 »

BadLuckBurt wrote: Sat Apr 24, 2021 7:12 am You don't need to do anything with a DLL. The terrain textures are stored with the other textures that you can just look at with Daggerfall Imaging.

The texture atlas is requested in Assets\Scripts\Terrain\DaggerfallTerrain.cs. Look at the InstantiateTerrain and UpdateClimateMaterial methods and dig deeper from there into the Assets\Scripts\MaterialReader.cs which is where the heavy lifting happens.

Under DaggerfallTools in Unity, there's also the Texture Array Creator, don't know how it works exactly but others probably do.
Nice, thank you for the valuable hints!
By any chance, do you know if it might cause problems to extract the old TEXTURES.302 by example, add a couple of images and recompress it with the DFU tools due to some byte/bit insanity going on somehwere in the original/unity DF?

I will for tonight, try this approach:
https://www.reddit.com/r/daggerfallunit ... aggerfall/
In Julianos we Trust.

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Expanding on Tile Textures

Post by BadLuckBurt »

Daniel87 wrote: Sat Apr 24, 2021 12:28 pm Nice, thank you for the valuable hints!
By any chance, do you know if it might cause problems to extract the old TEXTURES.302 by example, add a couple of images and recompress it with the DFU tools due to some byte/bit insanity going on somehwere in the original/unity DF?

I will for tonight, try this approach:
https://www.reddit.com/r/daggerfallunit ... aggerfall/
If you look in this class: Assets\Scripts\Utility\TextureReader.cs at the method GetTerrainAlbedoTextureArray, you'll see that it's hard-coded to only accept 56 textures:

Code: Select all

            // Load texture file and check count matches terrain tiles
            TextureFile textureFile = new TextureFile(Path.Combine(Arena2Path, TextureFile.IndexToFileName(archive)), FileUsage.UseMemory, true);
            int numSlices = 0;
            if (textureFile.RecordCount == 56)
            {
                numSlices = textureFile.RecordCount;
            }
            else
            {
                return null;
            }
So even if you supply more textures, they will not be loaded. I wouldn't bother with getting this into DFU just yet, instead create the algorithm in something you're more comfortable with. If I recall correctly, you had the Unity noise function or something close to it in Javascript form right? I'd just make the extended tileset and create an HTML page to experiment. You can use CSS to flip, rotate or mirror tiles as you please. Once the algorithm functions properly it's easy to port it to Unity and request the necessary changes to the way these texture arrays (or atlas) are loaded.

The TextureReader class also contains this method: GetTerrainTilesetTexture which has a switch statement that determines which textures tile and which don't, this would also have to be changed to allow the extended textures to work. This method also creates the flipped and rotated versions so you may not have to extend it manually. It's this bit of code:

Code: Select all

                // Create variants
                Color32[] rotate = ImageProcessing.RotateColors(ref albedo, sz.Width, sz.Height);
                Color32[] flip = ImageProcessing.FlipColors(ref albedo, sz.Width, sz.Height);
                Color32[] rotateFlip = ImageProcessing.RotateColors(ref flip, sz.Width, sz.Height);
The ImageProcessing class that does the rotation / flip is here: Assets\Scripts\Utility\ImageProcessing.cs and would allow you to mirror tiles horizontally or vertically using the FlipHorizontallyColors and FlipVerticallyColors methods.

https://www.dfworkshop.net/wp-content/u ... Atlas1.png

Don't get hung up on the usage of bytes either, I don't know why they were used in this case, probably because you can do binary math with them (which I know nothing about) but, looking in Assets\Scripts\Terrain\TerrainHelper.cs at the Execute method of the UpdateTileMapDataJob struct, they are converted back to a normal index in the atlas that corresponds to the image I posted above:

Code: Select all

                // Get sample tile data
                byte tile = tilemapData[JobA.Idx(x, y, tDim)];

                // Convert from [flip,rotate,6bit-record] => [6bit-record,flip,rotate]
                int record;
                if (tile == byte.MaxValue)
                {   // Zeros are converted to FF so assign tiles doesn't overwrite location tiles, convert back.
                    record = 0;
                }
                else
                {
                    record = tile * 4;
                    if ((tile & rotBit) != 0) record += 1;
                    if ((tile & flipBit) != 0) record += 2;
                }

                // Assign to tileMap
                tileColor.r = tileColor.a = (byte)record;
                tileMap[y * tDim + x] = tileColor;
This is about as far as my input can go. The person who wrote this code has a lot more insight than I do :)
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
Hazelnut
Posts: 3015
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Expanding on Tile Textures

Post by Hazelnut »

That would be me and Interkarma.

Is there a specific question?

Each tile is a byte that's used by the shader. 2 bits are used for rotation & flip leaving 6 bits, so theoretically 8 more tiles could be added however that could cause issues with the city outskirts which use those values. I think you had researched that Burt IIRC. Also FF is needed to represent 0 so the terrain and location tiles don't conflict.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
BadLuckBurt
Posts: 948
Joined: Sun Nov 05, 2017 8:30 pm

Re: Expanding on Tile Textures

Post by BadLuckBurt »

Hazelnut wrote: Sat Apr 24, 2021 2:47 pm Each tile is a byte that's used by the shader. 2 bits are used for rotation & flip leaving 6 bits, so theoretically 8 more tiles could be added however that could cause issues with the city outskirts which use those values. I think you had researched that Burt IIRC. Also FF is needed to represent 0 so the terrain and location tiles don't conflict.
You're correct, the RMB blocks with the city walls use the FF values on the outside of the wall.

The discussion started here: viewtopic.php?f=14&t=4485&start=130 and here: viewtopic.php?f=5&t=4749.

I'll leave it up to Daniel to explain what he's after exactly but basically more transitions than the basic ones that are used now. If I understood his questions in the other threads correctly that is.
DFU on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
DFU Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

.

User avatar
King of Worms
Posts: 4751
Joined: Mon Oct 17, 2016 11:18 pm
Location: Scourg Barrow (CZ)
Contact:

Re: Expanding on Tile Textures

Post by King of Worms »

I suggest partial copy/paste of the PM you send to me, the explanatiom there was very clear. Yes its about expanding the tile set so the transitions works better.

Daniel has it already very thought out, we just need these additional tiles to be added to the curent 56 ones.

User avatar
Daniel87
Posts: 391
Joined: Thu Nov 28, 2019 6:25 pm

Re: Expanding on Tile Textures

Post by Daniel87 »

Hazelnut wrote: Sat Apr 24, 2021 2:47 pm That would be me and Interkarma.

Is there a specific question?

Each tile is a byte that's used by the shader. 2 bits are used for rotation & flip leaving 6 bits, so theoretically 8 more tiles could be added however that could cause issues with the city outskirts which use those values. I think you had researched that Burt IIRC. Also FF is needed to represent 0 so the terrain and location tiles don't conflict.
At my mod, I hit a road block related to the tile set of the original daggerfall. Basically my question would be:
- Do you know if it is possible to append additional tiles for terrain transitions to the existing original tile sets of Daggerfall? and
- Is there a way of unpacking these tile set files of original DF, adding new tiles and repacking them or would placing additional textures in StreamingAssets/Textures be easier to implement?

General fact: I can only rotate tiles by 180° (the so-called "Flip"-Bit that only rotates) and by 90°(Rotate-Bit) but I cannot mirror them, which is required in about 50% of terrain transitions. Since they cannot be flipped horizontally or vertically, it currently looks like in the image below.

Image

These are the tiles which I would need to mirror in Photoshop and add into the original tile set or append in another way. Flipping them by code might also solve the problem partially but then still there would be some terrain transitions missing, which were never included in the original DF, see below.

Image

The tiles with red frame:
These tiles would need a mirrored version. Usually, they consist of 2x the same and 1x a second tile + 1x third tile, by example (dirt, dirt, water, stone). I would need a version with (dirt, dirt, stone, water) where they are simply flipped on one axis.

The tiles with green frame:
From these tiles I would need a version, where there is a third texture included.
by example we have (dirt, water, dirt, water) in the four corners. What I would need to add to the atlas is (dirt, water, dirt, stone) and (dirt, water, dirt, grass) etc.
I think all permutations possible would be:
Dirt: (dirt, water, dirt, stone) , (dirt, water, dirt, grass), (dirt, stone, dirt, grass)
Water: (water, dirt, water, grass), (water, dirt, water, stone), (water, stone, water, grass)
Stone: (stone, dirt, stone, grass), (stone, water, stone, grass), (stone, dirt, stone, water)
Grass: (grass, dirt, grass, water), (grass, dirt, grass, stone), (grass, water, grass, stone)

Then there is also a couple of versions with all 4 tile types joining that also is not in the standard tile set:
(water, dirt, stone, grass), (water, stone, dirt, grass), (water, grass, stone, dirt), (water, grass, dirt, stone)

I am not sure if that will be all possible permutations needed, but we could still extend on that, if it is basically possible to add more than X tiles per set.

I hope I could explain what I am planning to do and where I am failing.
Currently I hardcoded all possible terrain transitions, also the ones that were not possible before (water -> grass) or (water -> stone) and are only used in locations.
Last edited by Daniel87 on Sat Apr 24, 2021 7:15 pm, edited 1 time in total.
In Julianos we Trust.

Post Reply