• Advertisement
Sign in to follow this  

Output triangle strips in the geometry shader

This topic is 976 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am implementing the "Real-time stochastic rasterization on conventional GPU". But I only use HLSL, so I do not understand how the GS in GLSL output triangle strips.

 

First is output vertices' attributes

flat out vec4 pack0, pack1, pack2, pack3, pack4, pack5;

flat out vec3 wsTanZA; // normal vector
flat out vec3 wsTanZB;
flat out vec3 wsTanZC;

The source  code means that each output vertex will have 9 attributes (pack0 -> pack5 and 3 vector normals). Is that right?

 

 

And source code to output triangle strips is:

 layout(triangle_strip, max_vertices = 9) out;

....

void emitConvexHull(in vec3 v0, in vec3 v1, in vec3 v2, in vec3 v3, in vec3 v4, in vec3 v5, const in float zmin) {

    // Swap the lowest y vertex to position 0.
    // In the case of ties, resolve to the lower x
    // (the latter is specified by Graham, but does it matter?)
    // 5 comparisons
    xysort(v0.xy, v1.xy);
    xysort(v0.xy, v2.xy);
    xysort(v0.xy, v3.xy);
    xysort(v0.xy, v4.xy);
    xysort(v0.xy, v5.xy);

    // Compute sort keys relative to v0.  Store them in the z component.
    computeSortKey(v0, v1);
    computeSortKey(v0, v2);
    computeSortKey(v0, v3);
    computeSortKey(v0, v4);
    computeSortKey(v0, v5);

    // Sort by keys in increasing (CCW) order-- 10 comparisons in a sorting network.
    zsort(v1, v2);    zsort(v1, v3);    zsort(v1, v4);    zsort(v1, v5);
    zsort(v2, v3);    zsort(v2, v4);    zsort(v2, v5);    
    zsort(v3, v4);    zsort(v3, v5);
    zsort(v4, v5);

    // The first two vertices and the last must be on the convex hull.
    // Use v5 as the apex of the fan; we'll keep coming back to it.
    chEmit(v0);
    chEmit(v5);
    chEmit(v1);
    // Last known "good" vertex on the CH, constantly updated
    vec2 G = v1.xy;

    // Now we must determine which of points [2,3,4], if any, are on the hull.

    // Vertex 2: check corners 123, 124, 125
    vec2 toNext = v2.xy - G;
    if (isRightTurn(toNext, v3.xy - G) &&
        isRightTurn(toNext, v4.xy - G) &&
        isRightTurn(toNext, v5.xy - G)) {
        chEmit(v5);  chEmit(v2);  G = v2.xy;
    }

    // Vertex 3: check corners G34, G35
    toNext = v3.xy - G;
    if (isRightTurn(toNext, v4.xy - G) &&
        isRightTurn(toNext, v4.xy - G)) {
        chEmit(v5);  chEmit(v3);  G = v3.xy;
    }

    // Vertex 4: check corner G45
    if (isRightTurn(v4.xy - G, v5.xy - G)) {
        chEmit(v5);  chEmit(v4);
    }

    EndPrimitive();
}

Follow the GLSL code that if all conditions are true then the output vertices will be 0 5 1 5 2 5 3 5 4. It means that the finally generated triangles are 051, 515, 152, 525, 253, 535, 354. Is that right?

Share this post


Link to post
Share on other sites
Advertisement

9 attributes, correct. Since you did not specify the location (with layout(location = x)) you need to ensure that you use the same names and order in the fragment shader. Are you sure that you want to use the flat qualifier that prohibits interpolation accross triangles during rasterization?

Your assertion about the generated triangles should also be right (given that your chEmit call EmitVertex()).

Share this post


Link to post
Share on other sites

Thanks for the reply, Wumpf. In this stochastic rasterization, the intersection test between a triangle and a ray is performed in view space, thus the addition attributes in the output vertices at GS must be flat (nointerpolation).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement