Need advice: Lines between MapPixels

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

Need advice: Lines between MapPixels

Post by Daniel87 »

Hi everyone!

Progress is fast with my Wilderness Overhaul Mod, but there is one algorithm that gives me a hard time.
See picture for visualization of the problem:
Image

As you can see, there are seams between the Map Pixels due to a limitation in my algrorithm.
Basically I am comparing neighbouring points on the heightmap to calculate the steepness and texture a tile as stone if the hillside is
too steep.
Problem is, I don't know how to account for the neighbouring Map Pixel when comparing heightmapSamples without getting IndexOutOfBounds.
Does anyone have an idea how to approach this?

Code: Select all

static bool SteepnessTooHigh(float steepness, NativeArray<float> heightmapData, float maxTerrainHeight, int hx, int hy, int hDim, int upperBound, int index, int tdDim, NativeArray<byte> tileData)
        {
            if (JobA.Col(index, tdDim) + 1 >= tdDim ||
                JobA.Row(index, tdDim) + 1 >= tdDim)
            {
                return false;
            }
            else
            {
                    float minSmpl = 0;
                    float maxSmpl = 0;
                    float smpl = minSmpl = maxSmpl = heightmapData[JobA.Idx(hy, hx, hDim)] * maxTerrainHeight;
                    for (int a = 0; a <= 1; a++)
                    {
                        for (int b = 0; b <= 1; b++)
                        {
                            smpl = heightmapData[JobA.Idx(hy + a, hx + b, hDim)] * maxTerrainHeight;

                            if (smpl < minSmpl)
                            {
                                minSmpl = smpl;
                            }
                            if (smpl > maxSmpl)
                            {
                                maxSmpl = smpl;
                            }

                        }
                    }

                    float diff = (maxSmpl - minSmpl) * 10f;

                    if (diff > steepness)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
            }
        }
Last edited by Daniel87 on Tue Apr 27, 2021 11:21 am, edited 1 time in total.

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

Re: Need advice: Lines between MapPixels

Post by BadLuckBurt »

Thats going to be tricky. I suppose one way to do it would be to change the heightmap generator to also calculate the outer border of the adjacent map pixels. That way you can at least calulcate the slope correctly. Might cause problems on lower systems since the jobs will be running slightly longer

It worked in the original texturing process because thats just mapping tiles to Perlin Noise without regard for the steepness.
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

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

Re: Need advice: Lines between MapPixels

Post by Daniel87 »

BadLuckBurt wrote: Tue Apr 27, 2021 11:19 am Thats going to be tricky. I suppose one way to do it would be to change the heightmap generator to also calculate the outer border of the adjacent map pixels. That way you can at least calulcate the slope correctly. Might cause problems on lower systems since the jobs will be running slightly longer

It worked in the original texturing process because thats just mapping tiles to Perlin Noise without regard for the steepness.
You're right, but problem is, that DaggerfallTerrain only injects the heightmap and mapData of the current MapPixel into the Script, so I won't have the neighbouring heightmap information available in that thread.
I am thinking if I should just simply extrapolate linerarly and "guess" my way through. As long as the result is not a straight line of non-stone or stone tiles, the human eye shouldn't be able to see the difference.

EDIT: Works like a charm! :D

Image

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

Re: Need advice: Lines between MapPixels

Post by BadLuckBurt »

Sweet, that saves some headaches :) It looks great
Daggerfall Unity on UESP: https://en.uesp.net/w/index.php?title=T ... fall_Unity
Daggerfall Unity on Nexus Mods: https://www.nexusmods.com/daggerfallunity
My github repositories with mostly DFU related stuff: https://github.com/BadLuckBurt

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

Re: Need advice: Lines between MapPixels

Post by Daniel87 »

BadLuckBurt wrote: Tue Apr 27, 2021 11:45 am Sweet, that saves some headaches :) It looks great
Thanks!
Yes, after sinking too many hours in "exact" solutions, I have come to learn that achieving almost the same outcome with cheap tricks is THE way to go, hehe.


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

Re: Need advice: Lines between MapPixels

Post by Hazelnut »

Daniel87 wrote: Tue Apr 27, 2021 11:51 am
BadLuckBurt wrote: Tue Apr 27, 2021 11:45 am Sweet, that saves some headaches :) It looks great
Thanks!
Yes, after sinking too many hours in "exact" solutions, I have come to learn that achieving almost the same outcome with cheap tricks is THE way to go, hehe.
Exactly! Chasing perfection is a bad return on time investment a lot of times. :D

This is especially true for games I think.
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

Post Reply