Reputation: 6708
I generate a grayscale heightmap in Unity, and I would like to render it. Similar to a terrain in Unity, but not using the terrain component and with the ability to change very often without too much performance loss.
Currently I generate a grid mesh (in c#) and then alter the vertexes each frame in a script. This, however, is slow, and limits the resolution of my heightmap (Unity only allows meshes up to 65000 vertices).
So I was wondering, is there a better way to render this heightmap?
Notes:
Thanks a lot!
Upvotes: 1
Views: 1208
Reputation: 6708
I found how to do this a while ago, but forgot to post my solution. So here it is over a year later, maybe it'll help someone else:
You can simply add a vertex function into any shader:
First add something like: #pragma surface surf Standard fullforwardshadows vertex:vert
(the vertex:vert
part is important, a similar line will probably already be in the shader, so just add that to that line).
Then create the vertex function with the name you have it ("vert" in my case):
void vert(inout appdata_full v) {
float4 wsr = tex2Dlod(_MyTexture, v.texcoord);
v.vertex.y = wsr.r + wsr.g + wsr.b;
}
You'll also need a sampler in there somewhere (I just put it above the vert function)
sampler2D _MyTexture;
Upvotes: 1