#Falloff Inverse Calculation Issue

1 messages · Page 1 of 1 (latest)

gaunt robin
#

heres an image to try and illustrate what the issue is

#

the black is NOT normal and is a part of the second issue

#

it is meant to be a water color (seen on the blue outskirts)

#

and it ISNT meant to be water, it should be a tract of land with water on the outside, rather than whats happening here (the opposite)

weary iron
#

Do you have a region defined with hight set to 0?

gaunt robin
#

nope, because i believe the first region is supposed to fill from 0 to its designated height

weary iron
#

Not according to your code

gaunt robin
#

im confused because this has worked normally as intended previously

gaunt robin
weary iron
#

If the height is lower than the first rehion you skip to the next pixel.

if (currentHeight >= regions[i].height)
                    {
                        colorMap[y * mapChunkSize + x] = regions[i].color;
                    }
                    else
                    {
                        break;
                    }
gaunt robin
#

that fixed the second issue, thank you!

#

Falloff Inverse Calculation Issue

weary iron
#

What values does the falloff map contain?

gaunt robin
#

here is an image to illustrate the issue

#

or did you want me to give specific values (like debug.log)?

weary iron
gaunt robin
#

yea

#

i just wanna know how to inverse the white and black

#

just scroll past the mapgenerator

worn harness
#

1 - value will inverse the falloff (if it falls in a normalised range)

weary iron
#

First of all, you should add some parenthesis to make the order of operations clearer. For example I'm not sure if the size is multiplied by 2 first or if the division is going on first (I think it's the latter, but you should remove any possible factors)

Vector2 position = new Vector2(
                (float)x / size.x * 2 - 1,
                (float)y / size.y * 2 - 1
                );
gaunt robin
worn harness
#

If the value is 0, 1-0 gives you 1. If the value is 1, 1-1 gives you 0. It inverts that range

gaunt robin
#

ohh so like 1 - the ENTIRE thing?

#

1 - ((float)x / (size.x * 2) - 1)?

worn harness
#

I haven't looked at your code, it's just how you invert a normalised range

gaunt robin
#

ah ok

weary iron
#

I also suggest you take 3 radical example cases(one at the edge of the map, one at the center and one in between) and run them through your code on paper or in your head. Then you'll be able to see where the issue is.

#

It might be a simple case of inverting the if conditions or adding oneminus as vertex suggested.

gaunt robin
weary iron
#

Your function is simple enough to calculate on paper or even the head. Take 3 possible input values and check if they produce the desired result.

#

You only need to calculate this part:

{
                Vector2 position = new Vector2(
                (float)x / size.x * 2 - 1,
                (float)y / size.y * 2 - 1
                );

                float t = Mathf.Max(Mathf.Abs(position.x), Mathf.Abs(position.y));
                if (t < falloffStart)
                {
                    heightMap[x, y] = 1;
                } else if (t > falloffEnd)
                {
                    heightMap[x, y] = 0;
                } else
                {
                    heightMap[x, y] = Mathf.SmoothStep(1, 0, Mathf.InverseLerp(falloffStart, falloffEnd, t));
                }
#

Now take x,y equal to 0, size/2 and size/4. The first one would be at the edge, the second at the center and the last one somewhere in the middle.

gaunt robin
#

ok, so i could calculate for [0, 0], [240, 240] and [120, 120]?

weary iron
#

Yes

#

The first one should return 1, the second one 0 and the last one .5 if you want it to look the same as on the previous screenshot that you shared.

gaunt robin
#

im ngl i thought this was a chatgpt type problem but chatgpt just chatting shit atp so imma take a hot second to solve this since my brain isnt the fastest

#

yo ok so @weary iron ty for the help it works now

#

i take back all bad things ive said about chatgpt

#

this machine is a saviour to code

weary iron
#

It's great if you have some understanding on what you're asking.

gaunt robin
#

true but the sad thing is idk how this solution works

weary iron
#

And know how to ask question properly and interpret the answers.

weary iron
gaunt robin
#
        int sizeY = heightMap.GetLength(1);
        // Invert the heightmap values
        for (int y = 0; y < sizeY; y++)
        {
            for (int x = 0; x < sizeX; x++)
            {
                heightMap[x, y] = 1 - heightMap[x, y];
            }
        }```
#

oh true yeah

weary iron
#

Ask it to explain it like you're a 5 year old.

gaunt robin
#

once again thank you for the help