Results 1 to 10 of 13

Thread: Smoothening tile edges

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Don't forget that in order to draw the hexgons, they're deconstructed into triangles and you're essentially setting the alpha level on a shared vertex between two triangles which causes exactly what you describe. if you render the scene in wireframe that should make it more obvious.


    You don't have to shade your fragments in the classical sence, IE you can control the behaviour with properties that don't come along with the vertices.

    for example, if you wanted to fade the edge of a hex out or blend it etc following the edge, you'd instead control the blending as a function of the distance to that line.

    Not the only solution but in a really basic way :

    Pass the two points that make up a hex edge as uniforms into your shader.


    In your pixel shader you can then do some simple maths to work out the fragments distance to the line and then shade it accordingly, You can then get any result you like.


    You could also tesselate the hexes for more than 6 triangles, say spitting those 6 into 3 each, this will give you a greater vertex density bringing you closer to the look of per-pixel but signifigantly quicker (note any situation where a shader's main bottleneck is the fragment shader, you should look to see if you can move certain things to the vertex/evaluation/control shaders and then come closer to the per pixel result by evenly tesselating your source geometry. Check out 'Opacity Maps', specifically a similar optimization made with opacity mapped particle systems)

    You could also render all hexes on the outside as textured circles of radi equal to that of the hex, with half of the circle fading opacity to zero. the circles would then be aligned (by querying the surrounding blank hexes) so that the faded side points out, this would give a feathered but much smoother looking edge when 'zoomed' out by larger factors.

    You could also 'mask' by rendering over the edges of the hexes, like a 'fog of war' on lots of rts titles. Then you don't have to worry about smoothing the hexes, instead worry about drawing a smooth border. This is actually what I'd do because you could quickly identify long rows of hexes in the map by walking around it's edge, then you could draw one big overlay/mask over that group, giving an even smooth all the way down etc

    Alternativley you could render the map as a low resolution, filtered, alpha texture (where 0 is no hex etc) Then as you render your actual map, you translate the map coord to this texture and then sample it, using the result as the alpha value in your hex render. the filtering from a low resolution texture will greatly smooth out the edge. If you do this you should scale the co-ordinates slightly so the mask is referenced slightly smaller than the actual hexes, this would be like 'feathering' the alpha edge, encroaching the blend further into the visible hexes (if you get me)


    Edit : For anybody reading unfamiliar with shaders, here's me practicing some tutorial writing again - Fragment Shader = Pixel Shader. Control and Evaluation shaders are new additons in GL4.0, seperate from Geometry shaders you may of heard of. Control+Evaluation lets you take arbitary source vertices (called a 'patch' in this context) apply the tesselation hardware and get varied (yet still subject to the hardwired tesselation routines) output containing a higher number of vertices. You can control all per vertex data that gets pumped in and effect new, greater number of vertices that pop out of the tesselation. Geometry shaders are vaugely similar in that you can generate or bypass output via code but they are a lot more relaxed and varied in what they can do. They can also be used to tesselate although its very slow, hence the tesselation control/evaluation shaders which are specifically intended for the task of subdividing surfaces. An example of the difference is that a geometry shader could output cubes if you input points, or output 3D fishes if you input lines where as the tesselation shader couldn't. It could however take a simple cube and output a smoothed cube (smoothed edges or offset the new points into a sphere). So can the Geometry stage with some trickery (but not as quick),
    Last edited by phibermon; 27-04-2013 at 04:12 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •