Skip to main content
GameDev.net gamedev.net
🔒 Locked

Barycentric coordinates and triangles (D3D11)

Started by jollyjeffers Feb 21, 2009 at 6:54 AM 5 replies 6.3k views
Original Post
jollyjeffers
jollyjeffers
Afternoon all, I've been playing around with the new D3D11 tesselation features (Hull and Domain shaders - journal rambling here and here). Unfortunately the details on these features are a little limited, even if you're lucky enough to have the speclets that the docs are based on [headshake]. Currently I'm not getting errors but I'm also not getting anything rendered. I suspect my interpretation of some parts is wrong and was hoping someone here could clarify [smile] Barycentric Coordinates Choice details:
Quote:
For a tri patch, use a float3 (for barycentric coordinates)
Quote:
The tessellator generates a couple of things: (1) A set of domain points - UV for isoLine or quad domains and UVW (barycentric) for a tri domain. Each of these domain points is input to its own Domain Shader invocation. Each Domain Shader invocation also all sees shared input of all the Hull Shader output data.
Assuming my basic implementation is correct my domain shader has:
  • Three control point vertices
  • A 3D vector (uvw) SV_DomainLocation
  • Patch constants (currently unused) Basically it's the middle part thats got me. As I understand it the barycentric coords are ratios of the 3 control points - and the tesselator (between the HS and DS) generates a number of new vertices defined in terms of a barycentric coordinate that the DS receives. Taking that further, I have three world space vertices and a 3D barycentric coordinate. I need to generate a new world space vertex from this information. From wikipedia and mathworld it seems that I can just use the 3D vector as a weighting of the 3 vertices. However all examples I've found deal with a float/2D triangle (ok, so all triangles are coplanar by definition) and 2D barycentric coordinates. This is what I've used before. Consequently I suspect my code is fundamentally wrong:
    float3 finalVertexCoord = float4( 0.0f, 0.0f, 0.0f, 0.0f );
        
    finalVertexCoord += patch[0].position.xyz * uvw.x;
    finalVertexCoord += patch[1].position.xyz * uvw.y;
    finalVertexCoord += patch[2].position.xyz * uvw.z;
    
    If I'm generating rubbish vertex coordinates then it would explain why I get no errors but also see no output. Can anyone clarify whether my approach is correct or if its flawed? I'm a bit rustier with maths than I'd like [sad] Cheers, Jack
  • <hr align="left" width="25%" />
    Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
    yahastu
    yahastu
    Hey Jolly,

    I have no idea about this new D3D11 stuff, but your use of barycentric coordinates looks sound. Did you verify that uvw.x + uvw.y + uvw.z = 1?
    momotte
    momotte
    hm, have you tried using uv as fractions of the triangle edges?

    something like:

    float3 edge0 = patch[1].position.xyz - patch[0].position.xyz;float3 edge1 = patch[2].position.xyz - patch[0].position.xyz;finalVertexCoord += edge0 * uvw.x;finalVertexCoord += edge1 * uvw.y;


    I'm not sure how the 'w' coordinate should be used if it's meant to be this way, but as what you quoted says "UV for isoLine or quad domains and UVW (barycentric) for a tri domain", it may have something to do with the coordinates outside the triangle bounds (it's not needed for quads, and values of uv such as u+v > 1 && <= 2, are valid inside a quad, but not a triangle, so perhaps... ? (but it doesn't seem to make much sense to add another dimension to readjust coordinates outside the triangle bounds, the tesselator could just generate u/v values satisfying the u+v <= 1 condition))

    also, depending on what you do later on with 'finalVertexCoord', having 0.0 in the w component might not help. have you tried sticking 1.0 in finalVertexCoord.w ?
    Zipster
    Zipster
    Perhaps uvw.xyz and uvw.uvw don't map to the same values? I know that up through DX10 they're supposed to be synonymous but perhaps things changed in DX11, or it's different in the DS? That's really all I can think of, since the math itself is fine; at least as far as I can tell from what you've posted.

    And shouldn't you have some contacts at Microsoft you can probe about this? [wink]
    momotte
    momotte
    (by the way, in what space are the coordinates you receive ? if they were multiplied by a projection matrix in the VS, and you're tesselating in clipspace, you definitely should not trash the position's 'w' component, but instead lerp the full float4 vectors)
    xissburg
    xissburg
    Quote:
    Original post by jollyjeffers

    From wikipedia and mathworld it seems that I can just use the 3D vector as a weighting of the 3 vertices.


    Well, I don't think I can help, I couldn't understand what is the problem but...isn't this (Determining if a point is inside a triangle) wrong at Wikipedia? Shouldn't the coordinates add up to one? I mean λ1 + λ2 + λ3 = 1. =o
    .
    jollyjeffers
    jollyjeffers
    Thanks for the replies all, much appreciated!

    I've been doing more reading since and I suspect that it may not be the barycentric part that is broken, especially as no one here thinks I'm doing something fundamentally wrong (the spaces and aliases should be fine).

    Quote:
    And shouldn't you have some contacts at Microsoft you can probe about this? [wink]
    I'm heading over to Seattle next weekend, so if I can't crack it by then I'll be sure to ask [grin]

    Quote:
    isn't this (Determining if a point is inside a triangle) wrong at Wikipedia? Shouldn't the coordinates add up to one? I mean λ1 + λ2 + λ3 = 1
    I can't see anything wrong with it. The rules quoted for interior/edges seems the same as all other definitions I've read...?!


    Cheers,
    Jack
    <hr align="left" width="25%" />
    Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |

    Topic Locked

    This topic has been locked by a moderator. New replies are not allowed.

    Sign in to reply to this topic.