Wednesday, August 25, 2010


So after four months of ever-so-slowly moving forward on cell blending, I had finally see the light at the end of the tunnel. Just in time to have a sudden inspiration on how to do it all easier (sort of).

The goal: enable heightmap and texture blending between cells.
It sounds innocent enough - just fine affected mesh vertices and blend away! Four months of slow work (broken by countless TF2 sessions and some monumental Minecraft bases), and I've finally got step 1 working. There's still some clean-up work on step 1, but that'll be easier and the motivation is now returning.

The problems: The previous major version did a couple things wrong. I got heightmapping and texturing working over the entire sphere using a Miller projection. This had potential, but lacked in several areas: the 'hexness' of the map was lost and it required a very, very high resolution texture to look decent.

I wanted to maintain the hex feel of the map, yet be able to blend heightmaps to create continuous mountain ranges, sea beds, and other land features. Each cell has the potential to align differently in UV space meaning that seams wouldn't match up easily like a flat 2d grid. The first idea was to add more texture channels to each mesh vertex:
  1. Base cell UV's
  2. Neighbor channel 1 (neighbors 1 & 3)
  3. Neighbor channel 2 (neighbors 2 & 4)
  4. Neighbor channel 3 (neighbors 3 & 6)
  5. Optional detail channel 1 (micro detail - bumpmap, etc...)
  6. Optional detail channel 2 (macro, miller projection - color shifts, shading...)
Then to write the HLSL shader to handle the custom vertex format...

Then to write all the testing tools to ensure that the mesh is being build correctly...

The testing tools allowed me to achieve a nice unwrap of the icosahedron mesh and from there to write a 2d-map importer... This step turned out very useful. I can open up Photoshop, set an indexed color palette, and draw the map over the top of an exported unwrap of the cell points, then read it back into the game.
Finally, the blending step. The problem lies in that each cell is independently textured. This will ensure better resolution when zoomed in without massive textures and help to maintain the hex board game feel. The first plan went something like this:
  1. Create base cells
  2. Build base UV coordinates as a single large hexagon or pentagon
  3. Find and sort neighbor cells
  4. Start building render mesh
    • Subdivide each cell for the render mesh.
    • Lookup neighbor mesh vertices 'affected' by each cell vertex.
    • Take affected vertices appropriate texture channel (each vertex has 4+ texture channels - base, neighbor 1, 2, and 3) and align to the cell edge. This is the part that proved to take the longest and I've still got the texture blending ahead.
The epiphany here is to incorporate polar coordinates for better affected vertex lookup and UV texturing. Hexes bordered by a pentagon have some alignment issues with the pentagons along neighbor seams due to the pentagon's having different base angles. Switching to building mesh UV's off polar coordinates will solve this issue as well as some of the slight texture warping that will occur.


Scrap that, polar's didn't work for helping with UV mapping. Things get too funky around the poles.

Random Picture

No comments:

Post a Comment