WebGL - Textured terrain with heightmap

前端 未结 5 1639
滥情空心
滥情空心 2020-12-31 08:23

I\'m trying to create a 3D terrain using WebGL. I have a jpg with the texture for the terrain, and another jpg with the height values (-1 to 1).

I\'ve looked at vari

5条回答
  •  情书的邮戳
    2020-12-31 08:39

    Two methods that I can think of:

    1. Create your landscape vertices as a flat grid. Use Vertex Texture Lookups to query your heightmap and modulate the height (probably your Y component) of each point. This would probably be the easiest, but I don't think browser support for it is very good right now. (In fact, I can't find any examples)
    2. Load the image, render it to a canvas, and use that to read back the height values. Build a static mesh based on that. This will probably be faster to render, since the shaders are doing less work. It requires more code to build the mesh, however.

    For an example of reading image data, you can check out this SO question.

提交回复
热议问题