- Home /
How to smooth out the values?
I am working on a project and one of the parts is to generate a mountain. Someone passed me the source code and I've tried to modify it to fit my needs but the output is not exactly what it needs to be.
It is great to generate some flat values for an island maybe, but not so great at generating smooth height values for a mountain.
At first, it seems to look good because it generates a nice shape but you can see the abrupt changes from color to color. When I pass the texture to a 3D Terrain, this is what it looks like: https://imgur.com/nic3huO
Anyways, the 3D Mountain should not look like this even though the base shape is fine. I am looking for something similar to this height values, it's much smoother: https://imgur.com/QHBFXwK
After analyzing the source code for a while I reckon that the problem seems to be that the values are truncated. I think the problem is in the Noise() function above, especially with the Pow functions, but I'm not sure. I would be very glad if someone can contribute towards fixing this. Thank you and have a Great Day!
Answer by Bunny83 · Jun 29, 2020 at 02:06 PM
Uhm your Noise function returns an integer value. I haven't gone through all the math since we don't even know if the values shown in the code are the ones used (since most of them they are public serialized variables). Anyways since you divide the returned value by 8 and feed them into a Color we can assume that the max value that your Noise function returns is 8 which would equal white (8f / 8 == 1f == white) while a value of 0 would mean black. However since your function returns an integer value in the range of 0 to 8 there are only 9 possible outcomes in the end.
Why do you actually return an integer and doing that int cast at the end? Well that's pretty much the limitation of your function. You might want to switch the return type to "float" and get rid of that int cast at the end.
I was not expecting such an easy fix based on 2 days of trying to figure out the problem with no results. Thank you VERY much!
Your answer
Follow this Question
Related Questions
What's wrong with this script? 4 Answers
Make a high poly count plane with code 0 Answers
How exactly is Perlin Noise implemented? 4 Answers
How to create a terrain in a sphere with Perlin Noise 0 Answers
Adding noise to terrain does nothing 0 Answers