15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    NV_fragment_shader_barycentric
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_NV_fragment_shader_barycentric
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Pat Brown, NVIDIA (pbrown 'at' nvidia.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Ashwin Lele, NVIDIA
165bd8deadSopenharmony_ci    Jeff Bolz, NVIDIA
175bd8deadSopenharmony_ci    Michael Chock, NVIDIA
185bd8deadSopenharmony_ci
195bd8deadSopenharmony_ciStatus
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ci    Shipping
225bd8deadSopenharmony_ci
235bd8deadSopenharmony_ciVersion
245bd8deadSopenharmony_ci
255bd8deadSopenharmony_ci    Last Modified:      April 8, 2018
265bd8deadSopenharmony_ci    Revision:           2
275bd8deadSopenharmony_ci
285bd8deadSopenharmony_ciNumber
295bd8deadSopenharmony_ci
305bd8deadSopenharmony_ci    OpenGL Extension #526
315bd8deadSopenharmony_ci    OpenGL ES Extension #316
325bd8deadSopenharmony_ci
335bd8deadSopenharmony_ciDependencies
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ci    This extension is written against the OpenGL 4.6 Specification
365bd8deadSopenharmony_ci    (Compatibility Profile), dated July 30, 2017.
375bd8deadSopenharmony_ci
385bd8deadSopenharmony_ci    OpenGL 4.5 or OpenGL ES 3.2 is required.
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    This extension requires support for the OpenGL Shading Language (GLSL)
415bd8deadSopenharmony_ci    extension "NV_fragment_shader_barycentric", which can be found at the
425bd8deadSopenharmony_ci    Khronos Group Github site here:
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci        https://github.com/KhronosGroup/GLSL
455bd8deadSopenharmony_ci
465bd8deadSopenharmony_ciOverview
475bd8deadSopenharmony_ci
485bd8deadSopenharmony_ci    This extension advertises OpenGL support for the OpenGL Shading Language
495bd8deadSopenharmony_ci    (GLSL) extension "NV_fragment_shader_barycentric", which provides fragment
505bd8deadSopenharmony_ci    shader built-in variables holding barycentric weight vectors that identify
515bd8deadSopenharmony_ci    the location of the fragment within its primitive.  Additionally, the GLSL
525bd8deadSopenharmony_ci    extension allows fragment the ability to read raw attribute values for
535bd8deadSopenharmony_ci    each of the vertices of the primitive that produced the fragment.
545bd8deadSopenharmony_ci
555bd8deadSopenharmony_ciNew Procedures and Functions
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ci    None
585bd8deadSopenharmony_ci
595bd8deadSopenharmony_ciNew Tokens
605bd8deadSopenharmony_ci
615bd8deadSopenharmony_ci    None
625bd8deadSopenharmony_ci
635bd8deadSopenharmony_ciModifications to the OpenGL 4.6 Specification (Compatibility Profile)
645bd8deadSopenharmony_ci
655bd8deadSopenharmony_ci    Modify Section 15.2.2, Shader Inputs (p. 586)
665bd8deadSopenharmony_ci
675bd8deadSopenharmony_ci    (insert new paragraphs after the first paragraph, p. 589)
685bd8deadSopenharmony_ci
695bd8deadSopenharmony_ci    Fragment shader input variables can be declared as per-vertex inputs using
705bd8deadSopenharmony_ci    the GLSL interpolation qualifier "pervertexNV".  Such inputs are not
715bd8deadSopenharmony_ci    produced by attribute interpolation, but are instead taken directly from
725bd8deadSopenharmony_ci    corresponding output variables written by the previous shader stage, prior
735bd8deadSopenharmony_ci    to primitive clipping and rasterization.  When reading per-vertex inputs,
745bd8deadSopenharmony_ci    a fragment shader specifies a vertex number (0, 1, or 2) that identifies a
755bd8deadSopenharmony_ci    specific vertex in the point, line, or triangle primitive that produced
765bd8deadSopenharmony_ci    the vertex.
775bd8deadSopenharmony_ci
785bd8deadSopenharmony_ci    When no tessellation or geometry shader is active, the vertices passed to
795bd8deadSopenharmony_ci    each draw call are arranged into point, line, or triangle primitives as
805bd8deadSopenharmony_ci    described in Section 10.1.  If the <n> vertices passed to a draw call are
815bd8deadSopenharmony_ci    numbered 0 through <n>-1, and the point, line, and triangle primitives
825bd8deadSopenharmony_ci    produced by the draw call are numbered with consecutive integers beginning
835bd8deadSopenharmony_ci    with zero, Table X.1 and Table X.2 indicate the original vertex numbers
845bd8deadSopenharmony_ci    used as vertex 0, vertex 1, and vertex 2 when sourcing per-vertex
855bd8deadSopenharmony_ci    attributes for fragments produced by the primitive numbered <i>.  Table
865bd8deadSopenharmony_ci    X.1 applies when the provoking vertex convention is
875bd8deadSopenharmony_ci    FIRST_VERTEX_CONVENTION, while Table X.2 applies when the provoking vertex
885bd8deadSopenharmony_ci    convention is LAST_VERTEX_CONVENTION.
895bd8deadSopenharmony_ci
905bd8deadSopenharmony_ci        Primitive Type                  Vertex 0    Vertex 1    Vertex 2
915bd8deadSopenharmony_ci        ------------------------        --------    --------    --------
925bd8deadSopenharmony_ci        POINTS                          i           -           -
935bd8deadSopenharmony_ci        LINES                           2i          2i+1        -
945bd8deadSopenharmony_ci        LINE_STRIP                      i           i+1         -
955bd8deadSopenharmony_ci        LINE_LOOP                       i           i+1         -
965bd8deadSopenharmony_ci        LINE_LOOP (last segment)        n-1         0           -
975bd8deadSopenharmony_ci        TRIANGLES                       3i          3i+1        3i+2
985bd8deadSopenharmony_ci        TRIANGLE_STRIP (even)           i           i+1         i+2
995bd8deadSopenharmony_ci        TRIANGLE_STRIP (odd)            i           i+2         i+1
1005bd8deadSopenharmony_ci        TRIANGLE_FAN                    i+1         i+2         0
1015bd8deadSopenharmony_ci        POLYGON                         0           i           i+1
1025bd8deadSopenharmony_ci        LINES_ADJACENCY                 4i+1        4i+2        -
1035bd8deadSopenharmony_ci        LINES_STRIP_ADJACENCY           i+1         i+2         -
1045bd8deadSopenharmony_ci        TRIANGLES_ADJACENCY             6i          6i+2        6i+4
1055bd8deadSopenharmony_ci        TRIANGLE_STRIP_ADJACENCY (even) 2i          2i+2        2i+4
1065bd8deadSopenharmony_ci        TRIANGLE_STRIP_ADJACENCY (odd)  2i          2i+4        2i+2
1075bd8deadSopenharmony_ci
1085bd8deadSopenharmony_ci        Table X.1, Vertex Order for per-vertex attributes, using the provoking
1095bd8deadSopenharmony_ci        vertex convention FIRST_VERTEX_CONVENTION.
1105bd8deadSopenharmony_ci
1115bd8deadSopenharmony_ci        Primitive Type                  Vertex 0    Vertex 1    Vertex 2
1125bd8deadSopenharmony_ci        ------------------------        --------    --------    --------
1135bd8deadSopenharmony_ci        POINTS                          i           -           -
1145bd8deadSopenharmony_ci        LINES                           2i          2i+1        -
1155bd8deadSopenharmony_ci        LINE_STRIP                      i           i+1         -
1165bd8deadSopenharmony_ci        LINE_LOOP                       i           i+1         -
1175bd8deadSopenharmony_ci        LINE_LOOP (last segment)        n-1         0           -
1185bd8deadSopenharmony_ci        TRIANGLES                       3i          3i+1        3i+2
1195bd8deadSopenharmony_ci        TRIANGLE_STRIP (even)           i           i+1         i+2
1205bd8deadSopenharmony_ci        TRIANGLE_STRIP (odd)            i+1         i           i+2
1215bd8deadSopenharmony_ci        TRIANGLE_FAN                    0           i+1         i+2
1225bd8deadSopenharmony_ci        POLYGON                         0           i           i+1
1235bd8deadSopenharmony_ci        LINES_ADJACENCY                 4i+1        4i+2
1245bd8deadSopenharmony_ci        LINES_STRIP_ADJACENCY           i+1         i+2
1255bd8deadSopenharmony_ci        TRIANGLES_ADJACENCY             6i          6i+2        6i+4
1265bd8deadSopenharmony_ci        TRIANGLE_STRIP_ADJACENCY (even) 2i          2i+2        2i+4
1275bd8deadSopenharmony_ci        TRIANGLE_STRIP_ADJACENCY (odd)  2i+2        2i          2i+4
1285bd8deadSopenharmony_ci
1295bd8deadSopenharmony_ci        Table X.2, Vertex Order for per-vertex attributes, using the provoking
1305bd8deadSopenharmony_ci        vertex convention LAST_VERTEX_CONVENTION.
1315bd8deadSopenharmony_ci
1325bd8deadSopenharmony_ci    When using geometry shaders, vertices used for per-vertex fragment shader
1335bd8deadSopenharmony_ci    inputs are determined using Table X.1 or X.2 by treating the primitive(s)
1345bd8deadSopenharmony_ci    produced by the geometry shader as though they were passed to a DrawArrays
1355bd8deadSopenharmony_ci    calls.  When using a tessellation evaluation shader, or when using QUADS
1365bd8deadSopenharmony_ci    or QUAD_STRIP primitives, the vertices used for reading per-vertex
1375bd8deadSopenharmony_ci    fragment shader inputs are assigned in an implementation-dependent order.
1385bd8deadSopenharmony_ci
1395bd8deadSopenharmony_ci    The built-in variables gl_BaryCoordNV and gl_BaryCoordNoPerspNV are
1405bd8deadSopenharmony_ci    three-component floating-point vectors holding barycentric coordinates for
1415bd8deadSopenharmony_ci    the fragment.  These built-ins are computed by clipping (Section 13.6.1)
1425bd8deadSopenharmony_ci    and interpolating (Sections 14.5.1 and 14.6.1) a three-component vector
1435bd8deadSopenharmony_ci    attribute.  The vertices that are numbered 0, 1, and 2 for the purposes of
1445bd8deadSopenharmony_ci    reading per-vertex fragment shader inputs are assigned values of (1,0,0),
1455bd8deadSopenharmony_ci    (0,1,0), and (0,0,1), respectively.  For gl_BaryCoordNV, these values are
1465bd8deadSopenharmony_ci    clipped and interpolated using perspective correction.  For
1475bd8deadSopenharmony_ci    gl_BaryCoordNoPerspNV, these values are clipped and interpolated without
1485bd8deadSopenharmony_ci    perspective correction, like other fragment shader inputs qualified with
1495bd8deadSopenharmony_ci    "noperspective".
1505bd8deadSopenharmony_ci
1515bd8deadSopenharmony_ci
1525bd8deadSopenharmony_ciAdditions to the AGL/GLX/WGL Specifications
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci    None
1555bd8deadSopenharmony_ci
1565bd8deadSopenharmony_ciInteractions with OpenGL ES
1575bd8deadSopenharmony_ci
1585bd8deadSopenharmony_ci    Vertex order always corresponds to provoking vertex convention
1595bd8deadSopenharmony_ci    LAST_VERTEX_CONVENTION.
1605bd8deadSopenharmony_ci
1615bd8deadSopenharmony_ci    Ignore references to unsupported primitive types QUADS, QUAD_STRIP, and
1625bd8deadSopenharmony_ci    POLYGON.
1635bd8deadSopenharmony_ci
1645bd8deadSopenharmony_ciErrors
1655bd8deadSopenharmony_ci
1665bd8deadSopenharmony_ci    None
1675bd8deadSopenharmony_ci
1685bd8deadSopenharmony_ciNew State
1695bd8deadSopenharmony_ci
1705bd8deadSopenharmony_ci    None
1715bd8deadSopenharmony_ci
1725bd8deadSopenharmony_ciNew Implementation Dependent State
1735bd8deadSopenharmony_ci
1745bd8deadSopenharmony_ci    None
1755bd8deadSopenharmony_ci
1765bd8deadSopenharmony_ciIssues
1775bd8deadSopenharmony_ci
1785bd8deadSopenharmony_ci    (1) Can applications use the original order of vertices in a draw call to
1795bd8deadSopenharmony_ci        determine the order of the three vertices used when reading per-vertex
1805bd8deadSopenharmony_ci        fragment shader inputs?
1815bd8deadSopenharmony_ci
1825bd8deadSopenharmony_ci      RESOLVED:  Yes, in most cases.
1835bd8deadSopenharmony_ci
1845bd8deadSopenharmony_ci      This extension allows fragment shaders to read inputs qualified with
1855bd8deadSopenharmony_ci      "pervertexNV" using a vertex number 0, 1, or 2.  For most primitive
1865bd8deadSopenharmony_ci      types, the OpenGL Specification already specifies how the original
1875bd8deadSopenharmony_ci      vertices passed to a draw call are assigned to individual point, line,
1885bd8deadSopenharmony_ci      or triangle primitives.  The extension extends that language to define a
1895bd8deadSopenharmony_ci      specific vertex order that will be used for sourcing per-vertex
1905bd8deadSopenharmony_ci      attributes.  In some cases, this vertex order depends on the provoking
1915bd8deadSopenharmony_ci      vertex convention.
1925bd8deadSopenharmony_ci
1935bd8deadSopenharmony_ci      When using a tessellation evaluation shader, QUADS primitives, or
1945bd8deadSopenharmony_ci      QUAD_STRIP primitives, the OpenGL Specification already indicates that
1955bd8deadSopenharmony_ci      patches or quadrilaterals can be decomposed into finer primitives in an
1965bd8deadSopenharmony_ci      implementation-dependent order.  In these cases, we do not guarantee a
1975bd8deadSopenharmony_ci      specific vertex order.  However, we still guarantee that the vertices
1985bd8deadSopenharmony_ci      numbered 0, 1, 2 have corresponding barycentric weights (gl_BaryCoordNV)
1995bd8deadSopenharmony_ci      of (1,0,0), (0,1,0), and (0,0,1), respectively.  With this guarantee,
2005bd8deadSopenharmony_ci      interpolating attributes manually in a fragment shader with code like:
2015bd8deadSopenharmony_ci
2025bd8deadSopenharmony_ci        float value = (gl_BaryCoordNV.x * v[0].attrib +
2035bd8deadSopenharmony_ci                       gl_BaryCoordNV.y * v[1].attrib +
2045bd8deadSopenharmony_ci                       gl_BaryCoordNV.z * v[2].attrib);
2055bd8deadSopenharmony_ci
2065bd8deadSopenharmony_ci      should produce results approximately equal to those that would be
2075bd8deadSopenharmony_ci      obtained via conventional attribute interpolation.
2085bd8deadSopenharmony_ci
2095bd8deadSopenharmony_ci    (2) How are clipped primitives handled when using "pervertexNV"
2105bd8deadSopenharmony_ci        fragment shader inputs?
2115bd8deadSopenharmony_ci
2125bd8deadSopenharmony_ci      RESOLVED:  In the OpenGL pipeline, clipped primitives are normally
2135bd8deadSopenharmony_ci      handled by having the clipper remove one of the original vertices,
2145bd8deadSopenharmony_ci      introduce one or more new vertices, and process the result as an
2155bd8deadSopenharmony_ci      unclipped primitive.  In this model, the provoking vertex still needs to
2165bd8deadSopenharmony_ci      be maintained because inputs qualified with "flat" use the values from
2175bd8deadSopenharmony_ci      that vertex even if the provoking vertex is clipped.
2185bd8deadSopenharmony_ci
2195bd8deadSopenharmony_ci      In this extension, we guarantee that the three sets of per-vertex values
2205bd8deadSopenharmony_ci      available as fragment shader inputs are those of the original primitive
2215bd8deadSopenharmony_ci      vertices prior to clipping.  To ensure consistent attribute handling,
2225bd8deadSopenharmony_ci      the barycentric weights are computed relative to the original primitive,
2235bd8deadSopenharmony_ci      not the clipped one.  For example, if the left half of triangle ABC
2245bd8deadSopenharmony_ci      below is clipped away, the clipper introduces a new vertex D and
2255bd8deadSopenharmony_ci      rasterizes triangle DBC instead.
2265bd8deadSopenharmony_ci
2275bd8deadSopenharmony_ci                          + B (0,1,0)
2285bd8deadSopenharmony_ci                         /|\
2295bd8deadSopenharmony_ci                        / | \
2305bd8deadSopenharmony_ci                       /  |  \
2315bd8deadSopenharmony_ci                      /   |   \
2325bd8deadSopenharmony_ci                     /    |    \
2335bd8deadSopenharmony_ci                    /     |     \
2345bd8deadSopenharmony_ci         (1,0,0) A +------+------+ C (0,0,1)
2355bd8deadSopenharmony_ci                          D
2365bd8deadSopenharmony_ci
2375bd8deadSopenharmony_ci      When we process the clipped triangle, the three vertices available for
2385bd8deadSopenharmony_ci      "pervertexNV" inputs are actually A, B, and C (in undefined order).
2395bd8deadSopenharmony_ci      If vertices "v[0]", "v[1]", and "v[2]" are assigned to A, B, and C,
2405bd8deadSopenharmony_ci      respectively, fragments at A, B, and C will have barycentric coordinates
2415bd8deadSopenharmony_ci      of (1,0,0), (0,1,0), and (0,0,1), respectively.  A fragment at the
2425bd8deadSopenharmony_ci      vertex D introduced by the clipper will have a weight like (0.5, 0.0,
2435bd8deadSopenharmony_ci      0.5) -- exactly the same value it would have if ABC were unclipped.
2445bd8deadSopenharmony_ci
2455bd8deadSopenharmony_ci    (3) Should we have any program interface query API support where
2465bd8deadSopenharmony_ci        application code can inspect the active fragment shader inputs and
2475bd8deadSopenharmony_ci        determine which ones were declared with "pervertexNV"?
2485bd8deadSopenharmony_ci
2495bd8deadSopenharmony_ci      RESOLVED:  No.  We don't have this for other interpolation qualifiers
2505bd8deadSopenharmony_ci      like "flat" or "noperspective".
2515bd8deadSopenharmony_ci
2525bd8deadSopenharmony_ci    Also, please refer to issues in the GLSL extension specification.
2535bd8deadSopenharmony_ci
2545bd8deadSopenharmony_ciRevision History
2555bd8deadSopenharmony_ci
2565bd8deadSopenharmony_ci    Revision 2 (mchock)
2575bd8deadSopenharmony_ci    - Add support for OpenGL ES.
2585bd8deadSopenharmony_ci
2595bd8deadSopenharmony_ci    Revision 1 (pbrown)
2605bd8deadSopenharmony_ci    - Internal revisions.
261