I have generated a 1024 X 1024 heightmap using Open simplex noise. Now i want to zoom into a 64X64 area. Every pixel in the 64X64 is not 16X16 on the larger scale.

I tried just generating the area, but problem is, that I want to also calculate normals from it, and the normals are different for the zoomed in area from the big map. The difference comes from the fact that on the big map the height difference between 2 pixels can be quite large, but when zoomed in, new pixels are place between the original 2 so if now normals are calculated, they are totally different.

How can I zoom into an area of a generated heightmap but retain the normals? On the left is the large scale map and on the right is the zoomed in area. Zoomed in area is the upper left corner of the large scale map. As you can see the normals are completely different. Both of these images are textures. There are no meshes or anything only textures, and there will not be any meshes in future either.

enter image description here

This is how I calculate normals from heightMap.

            u = noiseValues[x + (y - 1) * width];
            r = noiseValues[x + 1 + y * width];
        Vector3 up = new Vector3(0, 1, (noiseValues[index] - u)*100);
        Vector3 across = new Vector3(1, 0, (r - noiseValues[index])*100);

        normal = across.Cross(up).Normalized();
        normal = (normal + new Vector3(1, 1, 1)) / 2.0f;

After updating these lines in normal calculation:

 Vector3 up = new Vector3(0, 1/zoomFactor, (noiseValues[index] - u)*100);
        Vector3 across = new Vector3(1/zoomFactor, 0, (r - noiseValues[index])*100);

This is the result after adjusting normal calculation:

enter image description here

  • \$\begingroup\$ The height difference between adjacent pixels will tend to decrease as you zoom in closer, but so does the spacing between the pixels. So both the rise and run are shrinking, keeping the slope consistent. Can you show us how you're calculating the normal from pixel heights? Your formula might just be missing a factor for the horizontal interval between the two samples. \$\endgroup\$
    – DMGregory
    Nov 9 '19 at 16:08
  • \$\begingroup\$ @DMGregory I added piece of code where the normal is calculated. \$\endgroup\$
    – Marko Taht
    Nov 9 '19 at 16:12
  • \$\begingroup\$ Looks like you're assuming the offset between adjacent pixels always (0, 1) vertically, and (1, 0) horizontally, regardless of your zoom level. Have you tried scaling these offsets to match the distance currently represented by a one-pixel gap at your current zoom? Don't forget to normalize the resulting normal to keep it in the range for your normal map. \$\endgroup\$
    – DMGregory
    Nov 9 '19 at 16:15
  • \$\begingroup\$ @DMGregory It looks alot better.There is a lot more detail, but seems to be the same as in large scale. \$\endgroup\$
    – Marko Taht
    Nov 9 '19 at 16:29
  • \$\begingroup\$ Can you update your question to show what you're doing now and how it looks? \$\endgroup\$
    – DMGregory
    Nov 9 '19 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.