Search Unity

Question Heightmap problem

Discussion in 'Shader Graph' started by Bluelattice5555, Jun 2, 2023.

  1. Bluelattice5555

    Bluelattice5555

    Joined:
    May 8, 2020
    Posts:
    34
    To briefly describe what I've done here:
    • create a 32x32 Terrain Tools terrain
    • sculpt some hills
    • Window>Terrain>Terrain Tools>Utilities>Export Height Map as PNG
    • make a plane in Blender, subdivided to 32x32, apply all transformations, center at origin, export as fbx
    • import plane into Unity
    • make a material and the shader graph in the image, apply to plane
    • use the exported height map in the shader

    So, basically what I'm doing is trying to duplicate the same terrain that Terrain Tools has made, using its own generated height map, on my own self-created plane. As shown in the image however, there is a problem. Terrain Tools is on the left, while my plane is on the right. It seems to be undervaluing darker values, thereby making the height for those values less than what they should be.

    A few things I have investigated already:
    • When looking at the pixel values in an image program, do the values increase linearly, as the height in the Terrain Tools geometry does? Curiously, no they don't. They nearly are linear, but it does have a slight curve to it. The perplexing thing is that it curves in the opposite way the geometry is doing. Instead of it looking like exponential growth, it actually jumps up quickly, then slowly tapers off to the whiter colors. Either way, I would say there's no way the data itself is causing the exponentially growing height I see in the geometry, because it would have the opposite effect on the vertice heights compared to what it is actually doing to them.

    • The data coming out of the Texture 2D LOD heightmap must not be what I think it is because I don't see why I have to be amplifying those values (with multiply) to begin with. White would be FF which is 255, so if you have x, y, z coordinates being 0, 255, 0, that would give a very tall terrain right off the bat. (both planes are a height of only 32, for example). But instead, by default, I get a very flat terrain that is only fixed when I add the multiply node in after the Texture 2D LOD (as shown). It should be noted that the exported height map is actually a greyscale image. But from what I understand about how B&W data is stored, it shouldn't matter if I am grabbing the R, G, B, or even the RGB (3) data. It should all be the same value. When experimenting with the different channels, it appears to have no effect on the geo anyway.

    • I tried messing around with lerp and contrast nodes, but didn't get very far with it.

    • If I just plug an exposed float into the y coordinate, allowing me to adjust the height of all vertices from the shader details, I can explicitly set it to 32 to see if it puts all vertices at 32 units high, which should be the maximum height of the terrain tools geometry. This does work correctly, so we can conclude that there is no funny business going on with a value of n translating to n units high in the world space.

    Why am I doing all of this? a) Terrain Tools is THE WAY to sculpt terrain, so I want to use it for that b) I want to be using my own shader(s) on the terrain c) I do see how you can make your own TerrainLit shader and use it in the terrain settings, but beyond that point I am utterly lost. I can't seem to open that in Shader Graph and writing the code for shaders is out of the question for me.

    EDIT: Man, I don't know how it happens, but the SECOND I bother to write out posts when I have a question, I figure out what I've done wrong. Every time. -_- The solution? Selecting the height map and un-checking sRGB........ Yeah. I would still love to have an explanation though if anyone knows. I feel like grabbing one of the channels' values would have had the same effect as unchecking color like that, but apparently not.
     

    Attached Files:

    Last edited: Jun 2, 2023