2

I am working on generating a procedural 3D terrain in libGDX. I've managed to create the mesh, but now I am having trouble finding an efficient way of texturing it.

The way I do it now is by creating a pixmap and iterating through all the heightmap values. Based on each height value, I extract one pixel from an appropriate texture (e.g. if the value is < 100 extract a pixel from the water texture, if it's > 100 && < 150 extract the pixel from the sand texture etc.) and after doing some blending I place it in the pixmap I've created. In the end, I'll just generate a new texture based on the pixmap I've created and assign it to the terrain. This works and gives out satisfying results, but iterating through every single pixel and creating a texture this way leads to very bad performance and long start up times for my game. My question is, what other options do I have?

Is there a more efficient way of creating textures than by iterating through pixmaps one pixel at a time? Is there a way to efficiently "copy a part of a pixmap and paste it onto another"?

Should I do it in some completely different manner? Maybe FBO's or Shaders? If so, please point me to some resources, I don't have much experience with those.

Thanks!

Mihai Fumarel
  • 160
  • 1
  • 14
  • 1
    Yes, this could be done very efficiently with a shader and multi-texturing. You would pass the vertex height from the vertex shader to the fragment shader. In the fragment shader you could select the pixel from the appropriate texture with a step function call to avoid dependent texture reads (which could slow it down). Sorry, can't take the time right now to spell it all out but maybe you can find some LibGDX shader tutorials by searching. – Tenfour04 Dec 04 '18 at 15:18

0 Answers0