15bd8deadSopenharmony_ciName
25bd8deadSopenharmony_ci
35bd8deadSopenharmony_ci    NV_clip_space_w_scaling
45bd8deadSopenharmony_ci
55bd8deadSopenharmony_ciName Strings
65bd8deadSopenharmony_ci
75bd8deadSopenharmony_ci    GL_NV_clip_space_w_scaling
85bd8deadSopenharmony_ci
95bd8deadSopenharmony_ciContact
105bd8deadSopenharmony_ci
115bd8deadSopenharmony_ci    Kedarnath Thangudu, NVIDIA Corporation (kthangudu 'at' nvidia.com)
125bd8deadSopenharmony_ci
135bd8deadSopenharmony_ciContributors
145bd8deadSopenharmony_ci
155bd8deadSopenharmony_ci    Eric Werness, NVIDIA Corporation
165bd8deadSopenharmony_ci    Ingo Esser, NVIDIA Corporation
175bd8deadSopenharmony_ci    Pat Brown, NVIDIA Corporation
185bd8deadSopenharmony_ci    Mark Kilgard, NVIDIA Corporation
195bd8deadSopenharmony_ci    Jason Schmidt, NVIDIA Corporation
205bd8deadSopenharmony_ci
215bd8deadSopenharmony_ciStatus
225bd8deadSopenharmony_ci
235bd8deadSopenharmony_ci    Shipping in NVIDIA release 367.XX drivers and up.
245bd8deadSopenharmony_ci
255bd8deadSopenharmony_ciVersion
265bd8deadSopenharmony_ci
275bd8deadSopenharmony_ci    Last Modified Date:         November 25, 2017
285bd8deadSopenharmony_ci    Revision:                   4
295bd8deadSopenharmony_ci
305bd8deadSopenharmony_ciNumber
315bd8deadSopenharmony_ci
325bd8deadSopenharmony_ci    OpenGL Extension #486
335bd8deadSopenharmony_ci    OpenGL ES Extension #295
345bd8deadSopenharmony_ci
355bd8deadSopenharmony_ciDependencies
365bd8deadSopenharmony_ci
375bd8deadSopenharmony_ci    This extension is written against OpenGL 4.5 Specification
385bd8deadSopenharmony_ci    (Compatibility Profile).
395bd8deadSopenharmony_ci
405bd8deadSopenharmony_ci    This extension interacts with the OpenGL ES 3.1 Specification.
415bd8deadSopenharmony_ci
425bd8deadSopenharmony_ci    This extension requires NV_viewport_array2.
435bd8deadSopenharmony_ci
445bd8deadSopenharmony_ci    If implemented in OpenGL ES, one of NV_viewport_array or OES_viewport_array
455bd8deadSopenharmony_ci    is required.
465bd8deadSopenharmony_ci
475bd8deadSopenharmony_ciOverview
485bd8deadSopenharmony_ci
495bd8deadSopenharmony_ci    Virtual Reality (VR) applications often involve a post-processing step to
505bd8deadSopenharmony_ci    apply a "barrel" distortion to the rendered image to correct the
515bd8deadSopenharmony_ci    "pincushion" distortion introduced by the optics in a VR device. The
525bd8deadSopenharmony_ci    barrel distorted image has lower resolution along the edges compared to
535bd8deadSopenharmony_ci    the center.  Since the original image is rendered at high resolution,
545bd8deadSopenharmony_ci    which is uniform across the complete image, a lot of pixels towards the
555bd8deadSopenharmony_ci    edges do not make it to the final post-processed image.
565bd8deadSopenharmony_ci
575bd8deadSopenharmony_ci    This extension also provides a mechanism to render VR scenes at a
585bd8deadSopenharmony_ci    non-uniform resolution, in particular a resolution that falls linearly
595bd8deadSopenharmony_ci    from the center towards the edges.  This is achieved by scaling the "w"
605bd8deadSopenharmony_ci    coordinate of the vertices in the clip space before perspective divide.
615bd8deadSopenharmony_ci    The clip space "w" coordinate of the vertices may be offset as of a
625bd8deadSopenharmony_ci    function of "x" and "y" coordinates as follows:
635bd8deadSopenharmony_ci
645bd8deadSopenharmony_ci            w' = w + Ax + By
655bd8deadSopenharmony_ci
665bd8deadSopenharmony_ci    In the intended use case for viewport position scaling, an application
675bd8deadSopenharmony_ci    should use a set of 4 viewports, one for each of the 4 quadrants of a
685bd8deadSopenharmony_ci    Cartesian coordinate system.  Each viewport is set to the dimension of the
695bd8deadSopenharmony_ci    image, but is scissored to the quadrant it represents.  The application
705bd8deadSopenharmony_ci    should specify A and B coefficients of the w-scaling equation above,
715bd8deadSopenharmony_ci    that have the same value, but different signs, for each of the viewports.
725bd8deadSopenharmony_ci    The signs of A and B should match the signs of X and Y for the quadrant
735bd8deadSopenharmony_ci    that they represent such that the value of "w'" will always be greater
745bd8deadSopenharmony_ci    than or equal to the original "w" value for the entire image. Since the
755bd8deadSopenharmony_ci    offset to "w", (Ax + By), is always positive and increases with the
765bd8deadSopenharmony_ci    absolute values of "x" and "y", the effective resolution will fall off
775bd8deadSopenharmony_ci    linearly from the center of the image to its edges.
785bd8deadSopenharmony_ci
795bd8deadSopenharmony_ciNew Procedures and Functions
805bd8deadSopenharmony_ci
815bd8deadSopenharmony_ci    void ViewportPositionWScaleNV(uint index, float xcoeff, float ycoeff)
825bd8deadSopenharmony_ci
835bd8deadSopenharmony_ciNew Tokens
845bd8deadSopenharmony_ci
855bd8deadSopenharmony_ci    Accepted by the <cap> parameter of Enable, Disable, IsEnabled:
865bd8deadSopenharmony_ci
875bd8deadSopenharmony_ci        VIEWPORT_POSITION_W_SCALE_NV            0x937C
885bd8deadSopenharmony_ci
895bd8deadSopenharmony_ci    Accepted by the <pname> parameter of GetBooleani_v, GetDoublei_v,
905bd8deadSopenharmony_ci    GetIntegeri_v, GetFloati_v, and GetInteger64i_v:
915bd8deadSopenharmony_ci
925bd8deadSopenharmony_ci        VIEWPORT_POSITION_W_SCALE_X_COEFF_NV    0x937D
935bd8deadSopenharmony_ci        VIEWPORT_POSITION_W_SCALE_Y_COEFF_NV    0x937E
945bd8deadSopenharmony_ci
955bd8deadSopenharmony_ciAdditions to Chapter 13 of the OpenGL 4.5 (Compatibility Profile)
965bd8deadSopenharmony_ciSpecification (Fixed-Function Vertex Post-Processing)
975bd8deadSopenharmony_ci
985bd8deadSopenharmony_ci    Modify Section 13.2 (Transform Feedback), p. 453 [section 12.1 in OpenGL ES]
995bd8deadSopenharmony_ci
1005bd8deadSopenharmony_ci    Modify the first paragraph:
1015bd8deadSopenharmony_ci
1025bd8deadSopenharmony_ci    ...The vertices are fed back after vertex color clamping, but before
1035bd8deadSopenharmony_ci    viewport mask expansion, w coordinate warping, flat-shading, and clipping...
1045bd8deadSopenharmony_ci
1055bd8deadSopenharmony_ci    Add a new Section 13.X (Viewport W Coordinate Scaling)
1065bd8deadSopenharmony_ci
1075bd8deadSopenharmony_ci    If VIEWPORT_POSITION_W_SCALE_NV is enabled, the w coordinates for each
1085bd8deadSopenharmony_ci    primitive sent to a given viewport will be scaled as a function of
1095bd8deadSopenharmony_ci    its x and y coordinates using the following equation:
1105bd8deadSopenharmony_ci
1115bd8deadSopenharmony_ci        w' = xcoeff * x + ycoeff * y + w;
1125bd8deadSopenharmony_ci
1135bd8deadSopenharmony_ci    The coefficients for "x" and "y" used in the above equation depend on the
1145bd8deadSopenharmony_ci    viewport index, and are controlled by the command
1155bd8deadSopenharmony_ci
1165bd8deadSopenharmony_ci        void ViewportPositionWScaleNV(uint index, float xcoeff, float ycoeff);
1175bd8deadSopenharmony_ci
1185bd8deadSopenharmony_ci    The viewport specified by <index> has its coefficients for "x" and "y"
1195bd8deadSopenharmony_ci    set to the <xcoeff> and <ycoeff> values.  Specifying these coefficients
1205bd8deadSopenharmony_ci    enables rendering images at a non-uniform resolution, in particular a
1215bd8deadSopenharmony_ci    resolution that falls off linearly from the center towards the edges,
1225bd8deadSopenharmony_ci    which is useful for VR applications. VR applications often involve a
1235bd8deadSopenharmony_ci    post-processing step to apply a "barrel" distortion to the rendered image
1245bd8deadSopenharmony_ci    to correct the "pincushion" distortion introduced by the optics in a VR
1255bd8deadSopenharmony_ci    device. The barrel distorted image, has lower resolution along the edges
1265bd8deadSopenharmony_ci    compared to the center.  Since the original image is rendered at high
1275bd8deadSopenharmony_ci    resolution, which is uniform across the complete image, a lot of pixels
1285bd8deadSopenharmony_ci    towards the edges do not make it to the final post-processed image.
1295bd8deadSopenharmony_ci    VR applications may use the w-scaling to minimize the processing of unused
1305bd8deadSopenharmony_ci    fragments. To achieve the intended effect, applications should use a set of
1315bd8deadSopenharmony_ci    4 viewports one for each of the 4 quadrants of a Cartesian coordinate
1325bd8deadSopenharmony_ci    system.  Each viewport is set to the dimension of the image, but is
1335bd8deadSopenharmony_ci    scissored to the quadrant it represents.  The application should specify
1345bd8deadSopenharmony_ci    the x and y coefficients of the w-scaling equation above, that have the
1355bd8deadSopenharmony_ci    same value, but different signs, for each of the viewports.  The signs of
1365bd8deadSopenharmony_ci    <xcoeff> and <ycoeff> should match the signs of X and Y for the quadrant
1375bd8deadSopenharmony_ci    that they represent such that the value of "w'" will always be greater
1385bd8deadSopenharmony_ci    than or equal to the original "w" value for the entire image. Since the
1395bd8deadSopenharmony_ci    offset to "w", (Ax + By), is always positive and increases with the
1405bd8deadSopenharmony_ci    absolute values of "x" and "y", the effective resolution will fall off
1415bd8deadSopenharmony_ci    linearly from the center of the image to its edges.
1425bd8deadSopenharmony_ci
1435bd8deadSopenharmony_ci    Errors:
1445bd8deadSopenharmony_ci
1455bd8deadSopenharmony_ci    - The error INVALID_VALUE is generated if <index> is greater than or equal
1465bd8deadSopenharmony_ci      to the value of MAX_VIEWPORTS.
1475bd8deadSopenharmony_ci
1485bd8deadSopenharmony_ciNew Implementation Dependent State
1495bd8deadSopenharmony_ci
1505bd8deadSopenharmony_ci    None.
1515bd8deadSopenharmony_ci
1525bd8deadSopenharmony_ciNew State
1535bd8deadSopenharmony_ci
1545bd8deadSopenharmony_ci                                                                 Initial
1555bd8deadSopenharmony_ci    Get Value                             Get Command    Type    Value     Description                  Sec.    Attribute
1565bd8deadSopenharmony_ci    ------------------------------------  -----------    ----    -------   -----------                  ----    ---------
1575bd8deadSopenharmony_ci    VIEWPORT_POSITION_W_SCALE_NV          IsEnabled      B       FALSE     Enable W coordinate Scaling  13.X    enable
1585bd8deadSopenharmony_ci    VIEWPORT_POSITION_W_SCALE_X_COEFF_NV  GetFloati_v    R       0         x coefficient for the w      13.X    viewport
1595bd8deadSopenharmony_ci                                                                           coordinate scaling equation
1605bd8deadSopenharmony_ci    VIEWPORT_POSITION_W_SCALE_Y_COEFF_NV  GetFloati_v    R       0         y coefficient for the w      13.X    viewport
1615bd8deadSopenharmony_ci                                                                           coordinate scaling equation
1625bd8deadSopenharmony_ci
1635bd8deadSopenharmony_ciAdditions to the AGL/GLX/WGL/EGL Specifications
1645bd8deadSopenharmony_ci
1655bd8deadSopenharmony_ci    None.
1665bd8deadSopenharmony_ci
1675bd8deadSopenharmony_ciGLX Protocol
1685bd8deadSopenharmony_ci
1695bd8deadSopenharmony_ci    None.
1705bd8deadSopenharmony_ci
1715bd8deadSopenharmony_ciErrors
1725bd8deadSopenharmony_ci
1735bd8deadSopenharmony_ci    None.
1745bd8deadSopenharmony_ci
1755bd8deadSopenharmony_ciInteractions with OpenGL ES 3.1
1765bd8deadSopenharmony_ci
1775bd8deadSopenharmony_ci    If implemented in OpenGL ES, remove all references to GetDoublei_v.
1785bd8deadSopenharmony_ci    If NV_viewport_array is supported, replace all references to MAX_VIEWPORTS
1795bd8deadSopenharmony_ci    and GetFloati_v with MAX_VIEWPORTS_NV and GetFloati_vNV respectively.
1805bd8deadSopenharmony_ci    If OES_viewport_array is supported, replace all references to MAX_VIEWPORTS
1815bd8deadSopenharmony_ci    and GetFloati_v with MAX_VIEWPORTS_OES and GetFloati_vOES respectively.
1825bd8deadSopenharmony_ci
1835bd8deadSopenharmony_ciIssues
1845bd8deadSopenharmony_ci
1855bd8deadSopenharmony_ci    (1) Does this extension provide any functionality to convert the w-scaled
1865bd8deadSopenharmony_ci        image to the barrel distorted image used in VR?
1875bd8deadSopenharmony_ci
1885bd8deadSopenharmony_ci      RESOLVED: No. VR applications would still require a post-processing step to
1895bd8deadSopenharmony_ci      generate a barrel distorted image to compensate for the lens distortion.
1905bd8deadSopenharmony_ci      The following vertex and fragment shader pair un-warps a w-scaled image.
1915bd8deadSopenharmony_ci      It can be incorporated into an existing post-processing shader to directly
1925bd8deadSopenharmony_ci      convert a w-scaled image to the barrel distorted image.
1935bd8deadSopenharmony_ci
1945bd8deadSopenharmony_ci        // Vertex Shader
1955bd8deadSopenharmony_ci        // Draw a triangle that covers the whole screen
1965bd8deadSopenharmony_ci        const vec4 positions[3] = vec4[3](vec4(-1, -1, 0, 1),
1975bd8deadSopenharmony_ci                                          vec4( 3, -1, 0, 1),
1985bd8deadSopenharmony_ci                                          vec4(-1,  3, 0, 1));
1995bd8deadSopenharmony_ci        out vec2 uv;
2005bd8deadSopenharmony_ci        void main()
2015bd8deadSopenharmony_ci        {
2025bd8deadSopenharmony_ci          vec4 pos = positions[ gl_VertexID ];
2035bd8deadSopenharmony_ci          gl_Position = pos;
2045bd8deadSopenharmony_ci          uv = pos.xy;
2055bd8deadSopenharmony_ci        }
2065bd8deadSopenharmony_ci
2075bd8deadSopenharmony_ci        // Fragment Shader
2085bd8deadSopenharmony_ci        uniform sampler2D tex;
2095bd8deadSopenharmony_ci        uniform float xcoeff;
2105bd8deadSopenharmony_ci        uniform float ycoeff;
2115bd8deadSopenharmony_ci        out vec4 Color;
2125bd8deadSopenharmony_ci        in vec2 uv;
2135bd8deadSopenharmony_ci
2145bd8deadSopenharmony_ci        void main()
2155bd8deadSopenharmony_ci        {
2165bd8deadSopenharmony_ci          // Handle uv as if upper right quadrant
2175bd8deadSopenharmony_ci          vec2 uvabs = abs(uv);
2185bd8deadSopenharmony_ci
2195bd8deadSopenharmony_ci          // unscale: transform w-scaled image into an unscaled image
2205bd8deadSopenharmony_ci          //   scale: transform unscaled image int a w-scaled image
2215bd8deadSopenharmony_ci          float unscale = 1.0 / (1 + xcoeff * uvabs.x + xcoeff * uvabs.y);
2225bd8deadSopenharmony_ci          //float scale = 1.0 / (1 - xcoeff * uvabs.x - xcoeff * uvabs.y);
2235bd8deadSopenharmony_ci
2245bd8deadSopenharmony_ci          vec2 P = vec2(unscale * uvabs.x, unscale * uvabs.y);
2255bd8deadSopenharmony_ci
2265bd8deadSopenharmony_ci          // Go back to the right quadrant
2275bd8deadSopenharmony_ci          P *= sign(uv);
2285bd8deadSopenharmony_ci
2295bd8deadSopenharmony_ci          Color = texture(tex, P * 0.5 + 0.5);
2305bd8deadSopenharmony_ci        }
2315bd8deadSopenharmony_ci
2325bd8deadSopenharmony_ci    (2) In the standard use case a application sets up 4 viewports, one for
2335bd8deadSopenharmony_ci        each quadrant. Does each primitive have to be broadcast to all the 4
2345bd8deadSopenharmony_ci        viewports?
2355bd8deadSopenharmony_ci
2365bd8deadSopenharmony_ci      RESOLVED: No. Applications may see a better performance if the viewport
2375bd8deadSopenharmony_ci      mask for each primitive is limited to the viewports corresponding
2385bd8deadSopenharmony_ci      to the quadrants it falls in.
2395bd8deadSopenharmony_ci
2405bd8deadSopenharmony_ci
2415bd8deadSopenharmony_ciRevision History
2425bd8deadSopenharmony_ci
2435bd8deadSopenharmony_ci    Revision 1
2445bd8deadSopenharmony_ci      - Internal revisions.
2455bd8deadSopenharmony_ci    Revision 2
2465bd8deadSopenharmony_ci      - Add _NV suffixes to _COEFF tokens
2475bd8deadSopenharmony_ci    Revision 3
2485bd8deadSopenharmony_ci      - Add ES interactions.
2495bd8deadSopenharmony_ci      - Add requirement for NV_viewport_array2
2505bd8deadSopenharmony_ci    Revision 4, 2017/11/25 (pbrown)
2515bd8deadSopenharmony_ci      - Add to the OpenGL ES Extension Registry
252