Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411283 Posts in 69325 Topics- by 58380 Members - Latest Member: bob1029

March 29, 2024, 02:00:58 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Texturing a map of regular square tiles in a 3D space
Pages: [1]
Print
Author Topic: Texturing a map of regular square tiles in a 3D space  (Read 808 times)
whistlerat
Level 1
*



View Profile
« on: January 11, 2018, 12:26:57 PM »

I'm trying to figure out the best way to go about the problem in the title and am running a little in circles. I'd love advice from anyone who has done this (in any engine or environment)!

The goal: Have an NxM map of regular squares which are textured akin to a regular 2D game, ie with discrete tiles (like this is a grass tile, this is a sand tile, this is a dirt tile, this is a grass tile which borders a dirt tile) not blended like in Unity's terrain system. This map will be regularly changing, so I need a solution which accommodates that.

The options, as I see them:
1) Each tile is a separate quad with its own texture. This is yuck and produces way more gameobjects than necessary.
2) Generate a mesh of quads, chunked into smaller meshes where necessary. Let's pretend it's just one mesh for simplicity. This is what I'm currently doing. Texturing the individual squares of this mesh is where I'm spinning my wheels. Options:
2.1) Use a texture atlas and uv-map the vertices to the quads. I can do this, but am concerned about the fact that this project is 3D; unless I carefully constrain zooming out, mipmapping with a texture atlas is not nice business. But I can do this, and just compensate for mipmapping by giving each texture a buffer.
2.2) Use a Texture2DArray, which is sorta like using an atlas except mipmapping is no longer a problem because textures are not 'next' to each other and so you don't get the bleeding. The main downside to this is that the documentation is nearly nothing, and shader code is apparently my programming nemesis. I'm able to get it working, sorta, but there are weird issues that I didn't foresee (like the fact that it seems to start sampling from the middle of the texture...?? No idea how to effectively control the sampling of each texture) and because I suck at shader code, I'm struggling to properly figure out what's wrong and then fix it.
2.3) Use a Texture2DArray but then blend the tiles together as in this excellent Catlike Coding tutorial. I could do that, I'm confident I can follow along well enough to convert from a hexgrid to a square one, but a pure blending between tiles isn't the look that I or my team are keen on. Might mock it up though.

Any advice? What have other similar projects done? Am I just insanely overthinking this? Crazy
« Last Edit: January 11, 2018, 12:44:23 PM by whistlerat » Logged

oahda
Level 10
*****



View Profile
« Reply #1 on: January 11, 2018, 12:44:02 PM »

2.1) This honestly sounds perfectly fine to me. If it works, and saves you some coding pain for the price of a little extra texture work.

2.2) Can't you offset the UV's to fix this "starting from the middle" issue?

2.3) I think you can prevent the blending by setting up the indices/normals properly. ThinMatrix talks about that sort of stuff in

.
Logged

whistlerat
Level 1
*



View Profile
« Reply #2 on: January 11, 2018, 12:57:54 PM »

2.1) This will probably be my backup! But you're right, if I can make it work then there's no reason to avoid it. Will just have to keep the effects of mipmapping in mind when creating the atlas. Luckily I'm not the artist so wouldn't be responsible for that necessarily  Tongue
2.2) I actually just figured out how to do exactly this!!! Working out how to get variables into the shader and then control it has been almost embarrassingly confusing... I'm definitely over-reliant on things like intellisense, hah. So I'm at least partway through this solution.
2.3) That video is REALLY interesting, thank you! I'm definitely gonna set aside some time to absorb that. Luckily my map is only flat for now, which reduces a lot of the complexity, but it's all useful stuff. I've learned a lot about mesh generation and texturing recently Smiley
Logged

gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #3 on: January 20, 2018, 10:55:49 PM »

Voxel terrain are basically like that, looking at advance minecrafty game optimization will certainly help. For what I know, they groupd similar tile together in a single convex mesh by expending from a tile to its horizontal neighbour first, then look down at the first obstacle to create bigger polygon.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic