Jump to content
  • Advertisement
Sign in to follow this  
toss-dev

3D UV map blocky voxel models

Recommended Posts

Hello there, I here have a quite technical question, and as my english isn't perfect, feel free to ask any questions if I wasn't clear enough on my explanations.

I am building a homemade voxel model creator. My models are a set of blocks, from which I generate a mesh.
I would like to texture them using an external 2D image file. So, I have to 'uv-map' the vertices of my model, meaning, having a projection of 3D vertices on a 2D plane (texture)
I am looking for an algorithm to generate an optimal texture (optimal: having the lowest memory usage but still holding every vertices, without overlaps)

 

Let me pose the problem more formally. Feel free to look at the example if there is any comprehension issues.

What I have: I have list of planes, where each planes is defined by 2 integers (width, height)

What the algorithm should do:

  • 1) give the smallest (in term of area) rectangle which can hold every planes, without overlaps
  • 2) give the position and orientation of each planes relatively this rectangle. The position is where the plane should be mapped. (x, y), the orientation is 0 or 1, weather the plane is flipped once mapped. Flipped: map on the rectangle from (x, y) to (x height, y width), (instead of (x, y) to (x height, y width))

There might be multiple optimal solutions (as the following example shows, I would like to find an algorithm that generate at least one of them)

 

Example:  (notice that "LEFT" plan is flipped once mapped here) sample.bmp

Source code:  https://github.com/rpereira-dev/VoxelEngine/blob/master/VoxelEngine/src/com/grillecube/client/renderer/model/editor/mesher/ModelMesherCull.java

Screenshot: modelEditor.bmp

 

NB: I've posted this topic on the "graphic and GPU programming" section; as this generated texture will be used in an OpenGL context.

Edited by toss-dev

Share this post


Link to post
Share on other sites
Advertisement

You could map your voxel faces directly to uniform blocks of texture, e.g. 8x8 for each face, and duplicate edge texels at UV discontinuities to still have seamless filtering. 

Here is a paper which does this for general models: http://alice.loria.fr/publications/papers/2010/SEAMLESS/seamless.pdf

That's hard to implement (failing myself for weeks now), but in your case it should be pretty trivial. The only problem you have is to find a good packing of the atlas, so most shared edges are continuous in UV space and you waste only little space on duplicated texels. As you already pack faces sharing a plane that's a good start.

Another idea coming to mind would be using Polycubes, but this means using cube maps when regular textures give the same result a lot faster.

Share this post


Link to post
Share on other sites

Hey JoeJ, thank you for your interest.

The thing is, mapping each block will be a waste of memory (as many block faces are in-deed not visible!)
Also, for other technical reasons, I need those 'plans' to be mapped continuously on the texture.

The paper you give me seems quite complicated to me, I don't think that's necessary. My problem seems much simpler

Still, thank you a lot, my model actually are Polycubes! And I didn't even know about this designation ^^ So I will search from this side

Share this post


Link to post
Share on other sites

Here is a paper comparing all mentioned: http://www.cemyuksel.com/courses/conferences/siggraph2017-rethinking_texture_mapping/rethinking_texture_mapping_course_notes.pdf

... most of it is probably overkill here. Atlas should do it. I linked the Seamless paper to show the idea of duplicated texels and color constraints as both of them apply but only if you want to filter across edges.

 

For the packing you could look at thekla_atlas and UVatlas on github.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!