#Falloff Inverse Calculation Issue
1 messages · Page 1 of 1 (latest)
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)
Do you have a region defined with hight set to 0?
nope, because i believe the first region is supposed to fill from 0 to its designated height
Not according to your code
im confused because this has worked normally as intended previously
really? should i add one?
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;
}
What values does the falloff map contain?
a float for the start and end, as well as a vector2int for the size of it
here is an image to illustrate the issue
or did you want me to give specific values (like debug.log)?
No that's fine. It would be pain in the ass to go through each pixel.
yea
i just wanna know how to inverse the white and black
the code should be in this link: https://paste.myst.rs/qac1w7f4
just scroll past the mapgenerator
1 - value will inverse the falloff (if it falls in a normalised range)
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
);
so like (float)x / (size.x * 2) - (1 - value)? or am i misinterpreting?
If the value is 0, 1-0 gives you 1. If the value is 1, 1-1 gives you 0. It inverts that range
I haven't looked at your code, it's just how you invert a normalised range
ah ok
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.
sorry i dont understand what you mean. 3 radical examples of the values of the edge, center and middle?
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.
ok, so i could calculate for [0, 0], [240, 240] and [120, 120]?
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.
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
It's great if you have some understanding on what you're asking.
true but the sad thing is idk how this solution works
And know how to ask question properly and interpret the answers.
That's where chat gpt shines. Just ask it to explain it.
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
Ask it to explain it like you're a 5 year old.
once again thank you for the help