• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lukabratzi

Matching Tessellation Factors Along Edges

1 post in this topic

Hey everyone,

 

For the past few weeks or so I've been working on setting up tessellation with displacement mapping in my deferred renderer.  Everything works, the displacement is correct, etc, etc but the one thing that's been giving me terrible difficulty is calculating my tessellation factors for my triangles based on the distance from the camera.

 

In particular I'm seeing a lot of gaps between triangle edges whose tessellation factors are different.  So I know that at its most basic level, the problem is that adjacent triangles that "share" an edge (share as in the triangles don't share vertices but just have edges at the same position) aren't being calculated to have the same tessellation factors.  The part that has me stumped is that by my understanding I should be handling this case correctly.

 

The two adjacent triangles are actually two separate sets of 3 vertices.  I know its not efficient and could be better used if I had just 4 vertices and 6 indices, but the 4 vertices that make up a set of 2 adjacent edges should be identical in terms of position, so I don't think that could be the source of the problem.  But in the interest of completion here's the code that creates the mesh:

    int cellCount = 25;
    m_totalSize = 320.f;
    float cellSize = m_totalSize / cellCount;

    std::vector<Vertex> finalVertices(6 * cellCount * cellCount);
    float deltaX = cellSize, deltaZ = cellSize;
    float deltaU = 1.f / cellCount, deltaV = 1.f / cellCount;

    float minX = -m_totalSize * 0.5f, maxX = minX + deltaX;
    float minU = 0.f, maxU = deltaU;
    float minZ = -m_totalSize * 0.5f, maxZ = minZ + deltaZ;
    float minV = 0.f, maxV = deltaV;

    int startingIndex = 0;
    for(int row = 0; row < cellCount; ++row)
    {
        for(int col = 0; col < cellCount; ++col)
        {
            finalVertices[startingIndex++].SetParameters( maxX, 0.f, maxZ, maxU, maxV);
            finalVertices[startingIndex++].SetParameters( minX, 0.f, minZ, minU, minV);
            finalVertices[startingIndex++].SetParameters( minX, 0.f, maxZ, minU, maxV);

            finalVertices[startingIndex++].SetParameters( minX, 0.f, minZ, minU, minV);
            finalVertices[startingIndex++].SetParameters( maxX, 0.f, maxZ, maxU, maxV);
            finalVertices[startingIndex++].SetParameters( maxX, 0.f, minZ, maxU, minV);

            minX += deltaX;
            maxX += deltaX;
            minU += deltaU;
            maxU += deltaU;
        }

        minZ += deltaZ;
        maxZ += deltaZ;
        minV += deltaV;
        maxV += deltaV;

        minX = -m_totalSize * 0.5f;
        maxX = minX + deltaX;
        minU = 0.f;
        maxU = deltaU;
    }

My Hull constant function takes in a patch of 3 points for each triangle and calculates the midpoint of each edge from those three points.  It then calculates the distance from the position of the camera and each midpoint and uses that distance to lerp between a minimum and a maximum tessellation factor (each of which has a corresponding range associated with it).  Since this is where the actual tessellation factors are calculated I'm guessing there's a good chance that its the culprit.  Here is the code from that portion of my shader:

float maxDistance = 150.0f;
float minDistance = 0.f;

HS_CONSTANT_FUNC_OUT HSConstFunc(InputPatch<VS_OUTPUT, 3> patch, uint PatchID : SV_PrimitiveID)
{
HS_CONSTANT_FUNC_OUT output = (HS_CONSTANT_FUNC_OUT)0;

float distanceRange = maxDistance - minDistance;
float minLOD = 1.0f;
float maxLOD = 32.0f;

float3 midpoint01 = patch[0].Position + 0.5 * (patch[1].Position - patch[0].Position);
float3 midpoint12 = patch[1].Position + 0.5 * (patch[2].Position - patch[1].Position);
float3 midpoint20 = patch[2].Position + 0.5 * (patch[0].Position - patch[2].Position);
float3 centerpoint = (patch[0].Position + patch[1].Position + patch[2].Position) / 3;

// calculate the distance from camera position to each edge midpoint and the center of the triangle
float e0Distance = distance(cameraPosition, midpoint01) - minDistance;
float e1Distance = distance(cameraPosition, midpoint12) - minDistance;
float e2Distance = distance(cameraPosition, midpoint20) - minDistance;
float eIDistance = distance(cameraPosition, centerpoint) - minDistance;

float tf0 = lerp(minLOD, maxLOD, (1.0f - (saturate(e0Distance / distanceRange))));
float tf1 = lerp(minLOD, maxLOD, (1.0f - (saturate(e1Distance / distanceRange))));
float tf2 = lerp(minLOD, maxLOD, (1.0f - (saturate(e1Distance / distanceRange))));
float tfInterior = lerp(minLOD, maxLOD, (1.0f - (saturate(eIDistance / distanceRange))));

output.edgeTesselation[0] = tf0;
output.edgeTesselation[1] = tf1;
output.edgeTesselation[2] = tf2;
output.insideTesselation  = tfInterior;

return output;
}

Assuming that the math is correct, that makes me think that the other problem area could be my hull shader's partitioning method.  Currently I'm using the integer method as it seems the simplest and easiest to debug, though I know that it will eventually lead to visual popping.  

[domain("tri")]
[partitioning("integer")]
[outputtopology("triangle_cw")]
[outputcontrolpoints(3)]
[patchconstantfunc("HSConstFunc")]
HS_OUTPUT HSMain(InputPatch<VS_OUTPUT, 3> patch, uint i : SV_OutputControlPointID)
{
HS_OUTPUT output = (HS_OUTPUT)0;

output.Position = patch[i].Position;
output.UVCoords = patch[i].UVCoords;
output.tc1 = patch[i].tc1;
output.tc2 = patch[i].tc2;
output.normal = patch[i].normal;

return output;
}

Could it be that the integer partitioning method is the cause for the gaps?  I know that if you specify a tessellation factor of 3.1 for an integer partitioning method, it gets bumped down to a value of 3.***  But even in this case it confuses me that any two edges between two sets of identical points would return differing tessellation factors.

 

Thanks to anyone who takes a look.  Let me know if I can provide any other code or explain anything.

 

*** I have a very basic and disgusting understanding of the various tessellation partitioning types.  If some kind, knowledgeable stranger happens to understand these and wants to throw a bit of an explanation for the advantages/disadvantages of pow and fractional_even/odd then that would be amazing.

Edited by lukabratzi
0

Share this post


Link to post
Share on other sites

I think you're doing it in a more complicated way than you need to.  I worked from Luna's DX11 book, and the code he presents does the LOD calculations in the vertex shader, and caches it in a field of his vs out/hs in vertex structure, so you end up with a per-vertex tessellation factor.  Thus, in the hull shader, you only need to average the two vertex tessellation factors, rather than doing the full LOD calculation, which should save you some performance.

 

http://www.richardssoftware.net/2013/09/bump-and-displacement-mapping-with.html

 

Also, as I was going back over my code, I noticed this comment in the hlsl:

    PatchTess pt;
    
    // Average tess factors along edges, and pick an edge tess factor for 
    // the interior tessellation.  It is important to do the tess factor
    // calculation based on the edge properties so that edges shared by 
    // more than one triangle will have the same tessellation factor.  
    // Otherwise, gaps can appear.
    pt.EdgeTess[0] = 0.5f*(patch[1].TessFactor + patch[2].TessFactor);
    pt.EdgeTess[1] = 0.5f*(patch[2].TessFactor + patch[0].TessFactor);
    pt.EdgeTess[2] = 0.5f*(patch[0].TessFactor + patch[1].TessFactor);
    pt.InsideTess  = pt.EdgeTess[0];
    
    return pt;

So I think that calculating the interior tessellation factor directly might be fouling you up as well.

0

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  
Followers 0