My script height function doesn't show the same height as the shader

Hello there,

After I asked my previous question I started to figure out how a perlin function worked and was able to implement this into a shader, however I now have a problem, because my script that should display the same height as the terrain seems… shifted. So I converted my function from the shader to c# again, but despite having precisely the same function it’s still wrong. I also checked if the vertex changed by the unity_ObjectToWorld matrix and transform.position are both world coordinates and they seem to be the same.

Can anyone of you help me?

If you need to see the shader and the c# script you can find them on this github repository:

My scripts on github

If you want to test the shader you first do need either just a plane (for a 10 x 10 resolution) or a 3d model plane width any other resolution (and make sure every face is 1 x 1 in unity units)
If if you’ve done so then you can move the plane around and view the terrain

Oké, I found the problem!

I used a sine function for a random value at a coordinate, but aparently this isn’t very precise with large numbers (wich I used)

So I’m know writing a new randomise function where I use a sort of sine wave (but linear) instead of the actual sine function and it now mostly works.

Only the randomness in the texture shows some repeating, but that’s not so hard to fix