Zelimir Fedoran
email zelimir.fedoran@gmail.com

Textured Voxels!

Posted on
May 2nd, 2010
Tags
, ,

I have decided on using 16 by 16 pixel tiles for my voxel textures. I may reduce the size of the tiles later on to give the world more of a 8-bit feel. However, I think that the 16 by 16 size works well. I may also do normal or parallax mapping depending on how well it works with the pixelated 3d blocks. For now I have chosen an art style similar to Minecraft. Once I get things running I will aim for a more cell shaded style (something along the lines of the Wind Waker).

textured1textured2textured0textured3

The Problem

I ran into some issues with textures. Why? Well because the quad merging optimizations I made cause textures to stretch. Also, I decided to use a texture atlas for the texture tiles. This makes repeating, instead of stretching, tiles a more difficult task.

Traditionally, to draw a voxel of a particular type, for example a rock type voxel, I would have tell the graphics card which texture to use before I can draw that type. For example, I could set the texture to a rock texture which would allow me to draw the rock voxels. Drawing each voxel type, one by one, would be silly. By using a texture atlas I can draw rock voxels and grass voxels at the same time. A texture atlas is simply a large texture which contains all of the texture tiles.

How is this possible? Well, since the rock and grass textures are inside the same texture I do not need to swap textures. All I need to do is tell the graphics card where inside the large texture my desired textures are located for each voxel type. This is done by setting texture coordinates at each vertex. These coordinates map the pixels of a texture from 0 to 1 in both the x and y axis. The nice thing about texture coordinates is that you can repeat the texture by setting the texture coordinates for an axis higher than 1. For example a texture coordinate of (3,0) would tell the graphics card to repeat the texture 3 times along the X-axis for this vertex. The problem is that for this does not work for a texture atlas.

The Solution

I can create 2 texture atlases, one would be a column of tiles and the other a row of tiles. Then I can tell the graphics card to repeat vertical textures using the row texture atlas and to repeat horizontal textures using the column texture atlas. I have included screen shots of stretching caused by the quad merging optimizations and how using a column texture atlas can fix horizontal stretching.

Textured Voxels Without Merging QuadsTextured Voxels With Quad Merging Causing Texture StretchingTextured Voxels With Quad Merging and Correct Horizontal TilingTextured Voxels With Quad Merging and Correct Horizontal Tiling