简体   繁体   中英

Drawing outside the viewport in Vulkan/Opengl

I have a viewport that is half of the screen size/framebuffer .

x, y, w, h = 0, 0, 512, 512

And my scissor region is the full framebuffer

x, y, w, h = 0, 0, 0 1024, 512

I am drawing a line, that is far outside of the viewport , from left to right. I am expecting the line to be drawn only inside the viewport. I have tested this on three different graphic cards, and on two of them, I get the result I am I expecting. However on the third one, the line is drawn outside the viewport , but inside the scissor region. Which one of the results is correct here? As far as I understand it, the lines' two vertices should be moved to outer viewport positions. It should not be drawn outside of it.

If you read pitfall nr 10 on this site: https://www.opengl.org/archives/resources/features/KilgardTechniques/oglpitfall/

They are talking about drawing outside the viewport , but that is just some special cases, for example where you have a really thick line, my line width is 1

EDIT: After a discussion in the KhronosGroup: From the spec Vulkan 1.0.68:

If either of a line segment's vertices lie outside of the clip volume, the line segment may be clipped, with new vertex coordinates computed for each vertex that lies outside the clip volume. A clipped line segment endpoint lies on both the original line segment and the boundary of the clip volume.

Nvidia:

We intentionally made this change for maintenance2, to allow for pop-free points and lines. Point clipping behavior is queriable but line clipping behavior is not, though I believe the "preferred" behavior for lines is to be pop-free. We changed the NVIDIA driver last year from tight clipping to pop-free, and even changed CTS tests to allow this new behavior. So this is all working as designed.

Old answer:

The viewport defines a transformation from normalized device coordinates to window coordinates. The viewport transformation does not do any clipping.

However, the clipping does happen before NDC space, the view frustum clipping does guarantee that no vertex can fall outside the viewport. And if you are using orthogonal projection, clip space and NDC space are the same. So everything outside [-1,1] will be clipped. And if you are not doing any of the special cases the opengl link talks about the vertices should be clipped.

If two of your graphics cards draws inside the viewport and one outside, it's probably a driver bug. If you are using Vulkan, which is fairly new, that is most likely the case.

Edit: My answer below is technically correct but not useful. The viewport transform itself doesn't define a clip volume or scissor. But because of clipping to the view frustum ([-w,+w] for x and y, [0,+w] for z), all the (x,y) values entering the viewport transform will be in [-1,1], and will not be transformed to fall outside of the rectangle that defined the viewport.

Like in GL, the viewport only defines a transform from normalized device coordinates to framebuffer coordinates. The transform is based on the width/height/depth/origin of the viewport volume, but that volume doesn't define a clipping volume. The math is described in section 23.5 Controlling the Viewport .

In Vulkan you can also specify a scissor rectangle in framebuffer coordinates for each viewport, in VkPipelineViewportStateCreateInfo:: pScissors or vkCmdSetScissor . Pixels outside this rectangle are dropped. But you have to set the scissor rectangle yourself, and it doesn't have to match the viewport volume.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM