0
\$\begingroup\$

I have started with LWJGL3 and trying to built game engine. I'm stuck on generating terrains and this is my second big problem and I'm exhausted so I need some advice on how to solve my problem.

What I want to achieve : I want to have all textures in one place and to have some kind of texture map that I will use to render specific texture at that place.

example: textures
enter image description here

map

enter image description here

but result is enter image description here

Only thing that I think is problem is because I use same points (index buffers)

enter image description here

So instead of 8 points, I have 6. Is it possible that then texture gets all messed up?

Should I use all points, even if they are at same or almost the same location? But then I would have a lot more vertices than actually need it.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

Use atleast 4 unique vertices per quad and dont use "shared vertices" between quads.

In your case it looks like the vertices are not shared but the uv coordinates dont match with the vertices due to wrong indexing. shared vertices can be spotted along the edges to the next quad, because interpolation would occur between shared edges, e.g. going from one texture into the other. its called vertex blending, in your case it doesnt look like vertex blending.

Each vertex (indexed vertex) must have a uv coordinate that matches the corners of your texture inside the big texture atlas. You are asking to implement a texture atlas based terrain with hard edges and without vertex blending. Please read about uv mapping, vertex coloring, vertex blending, texture atlas. it really helps to know the techniques in detail.

Thats how you can solve your problem:

  1. Generate a big image that contains all your little snippets for the terrain with atleast 2 pixels space between every texture island or sprite. The image must be power of two. 256x256, 512x512, 1024x1024, etc. is power of two. Its more efficient and some gpus have limitations with non power of two textures.
  2. draw your terrain on a sheet of paper by drawing all triangles independently and assigning a uv coordinate for every triangle. That sheet is your reference of expected output and you can use it for debugging (its because you need to match uv coordinates for every quad / triangle pair)
  3. Dont use "shared vertices" between quads if you want hard looking edges between quad tile geometry and textures to get a classic 2d look. it means that every quad is independent and consists of its own unique 4 vertices, normally a quad is 6 vertices because you actually draw 2 triangles, but you can get away with "sharing" vertices inside the quad by using the center 2 vertices twice inside index buffer but not outside with the next quad!

if you use indexing to save some vertices you have to use DrawIndexed method and not regular draw! You can read about the difference when looking for vertex input layout, jagged vertex buffers, etc.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .