XNA Hexagon 3D tiles color picking 3D picking
The game would consist of one world map (grand scale, for travel, still same hexagons) and dungeon/cave/event maps (lower scale) where you explore/fight. Lots more to tell on this.
It wasn't easy to get it working. Each hexagon is created separately, then all duplicate vertices it creates are removed so there are none wasted. This means it doesn't have to be a X by Y grid. At some point that seemed important...
Texturemapping is done completely in HLSL, since I found it too hard to calculate texturecoordinates given the nature of the regular hexagon vs. the square (it's probably not that hard, but it was for me). Turned out to be very easy to get a perfect tiling in the pixel shader. This means my vertices don't use any texturecoords in the vertex declaration. Normals are precalculated and averaged so all triangle transitions are smooth.
Importing a heightmap to make it look more interesting, but the goal would be all procedural generation.
Also, it was pretty hard to find info on 3D hexagon tiles. So I had to figure out a lot from scratch, so I don't know about the cleverness of the result... What I have is a bit of a hack amalgamation of stuff right now.
Rambling on... I'm pretty proud of the color picking, although it can probably be done better! It works perfectly though. In the beginning I used a sine function to cycle colors, but it wasn't exact, so now I did a much simpler and better thing. 16.7 M hexagons are possible and each would be pickable with no aliasing (not using alpha channel). I render the scene to a separate RenderTarget with inly color. Then I render the entire textured and lit scene again to the backbuffer. and sample the mouse X and Y from it to get the color and each hexagon has a color field. I then cycle all hexagons until I find the color, that's our hex. This works great with mouse-over detection. It was awful with DrawUserIndexedPrimitives, but DrawIndexedPrimitives made a huge difference.
Directional and point lights working (only directional showing in shots).
But first to try out techs and how to do things. Here below are some screenshots of the graphical side of things. All shots are capped at 60 fps. Without cap, for a 64 x 64 hex map it's currently some ~290 fps (3770K, GTX 670).
That's all so far. Next step is terrain decals, which I got stuck on. I'm probably in over my head. We'll see...
Trying some stuff to solve the problem with texturing; it mirrors around the center of each hex in some offset way:
Now texturing with HLSL! Success! Also new accurate color picking!!!
Last shot showing a sprite drawn for each vertex to show vertex numbers on a 128 x 128 hexagon map (no optimizing in any way), not good for frame rates: