guard band clipping
DESCRIPTION
Guard Band Clipping. Advanced D3D Programming Sim Dietrich [email protected]. Guard Band Clipping. What is Guard Band Clipping? Why would you want to use it? Using Guard Band Clipping 2D Clip Testing and Guard Band 3D Culling and Guard Band How to Detect it. - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/2.jpg)
Guard Band Clipping
• What is Guard Band Clipping?
• Why would you want to use it?
• Using Guard Band Clipping
• 2D Clip Testing and Guard Band
• 3D Culling and Guard Band
• How to Detect it
![Page 3: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/3.jpg)
What is Guard Band Clipping?
• The ability for hardware to accept screen coordinates outside of the current viewport range.
• The basic idea of guard band clipping is that the hardware can accept triangles that are partially or totally off-screen.
• Some graphics processors support 2D coordinates within the range [-2048,-2048 to 2047,2047].
![Page 4: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/4.jpg)
Viewport ( 1024x768 )
Guard Band( 4096x4096 )
Guard Band and Viewport
![Page 5: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/5.jpg)
Guard Band and Viewport
This triangle canbe trivially accepted or rejected
These triangles can be trivially accepted
This triangle mustbe clipped
![Page 6: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/6.jpg)
3D Frustum Clipping is Slow
• Requires dot products with 6 frustum planes for each vertex
• Produces extra vertices– Each value at vertex ( u,v, fog, alpha, diffuse
color, specular color ) requires interpolation– More bandwidth required for each new vertex– Breaks vertex cache coherency– Clipping can break up strips and fans
![Page 7: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/7.jpg)
Clip Testing is Faster
• 2D or 3D Clip testing combined with Guard band addresses these issues– Most triangles that normally require clipping
could be passed through to HW instead– Keeps more strips and fans intact– Maintain vertex cache coherency – Apps must still clip to near and far clip planes
![Page 8: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/8.jpg)
Guard Band Clipping
• Only in the rare case of a primitive crossing both the viewport and a Guard Band boundary is 3D frustum clipping necessary
• Either clip to the guard band boundary or the viewport boundary
• D3D clips triangles to the guard band
• Clipping to the viewport is preferred– It’s smaller than the guard band, so less pixels– Clipper will reject triangles outside viewport
![Page 9: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/9.jpg)
Using Guard Band Clipping
• Direct3D takes advantage of Guard Band clipping automatically if present and Direct3D performs clipping
• If the app performs own transforms– Detect the Guard Band extents– If found, use 3D cull testing or 2D clip testing after
culling and perspective transform– If apps pass 2D coordinates to D3D, they should perform
their own clipping, to keep Direct3D from de-projecting during its clipping
![Page 10: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/10.jpg)
2D Clip Testing– A version of Cohen-Sutherland clip-testing (FOLEY90)
– Generate outcodes for the viewport and the guard band’s borders for each vertex
– Outcode is a Bitfield : 0 means in, 1 means out
– Bitwise AND (&) and Bitwise OR ( | ) the outcodes in parallel to test various cases
• If primitive is within viewport accept• If primitive is outside of viewport on at least 1 side, reject• If primitive is in GB, accept• If primitive crosses a GB boundary, clip to viewport
![Page 11: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/11.jpg)
3D Culling and Guard Band
• An alternative to 2D clip testing is to use a second, larger frustum extending through the guard band borders for your 3D culling test.
• This eliminates the need to project the vertices to 2D before clip testing
• It is easily added to the end of your existing 3D culling
![Page 12: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/12.jpg)
Top View of Guard Band andView Frustums
Far Clip Plane
Near Clip Plane
View Frustum
Guard Band Frustum
Left Guard Band FrustumPlane
Right View Frustum Plane
Screen
![Page 13: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/13.jpg)
3D Culling and Guard Bands
• Create a 3D view frustum that passes through the guard band borders
• Cull boxes or spheres of objects to this frustum and the normal viewing frustum
• If the object is within the guard band frustum and crosses an edge of the view frustum, you can trivially accept it instead of clipping it to the view frustum
![Page 14: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/14.jpg)
3D Culling and Guard Bands
– For each object, calculate signed distance from the center of bounding sphere to each view frustum plane and compare to radius of sphere
– If it’s completely outside view frustum, reject– If it’s completely inside view frustum, accept – If it’s partially in, test against guard band frustum
• If completely in, accept it - This is where you save performance in avoiding clipping
• If it crosses a guard band frustum plane, clip it to view frustum as normal
![Page 15: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/15.jpg)
Top View of Guard Band and View Frustums, and Bounding Spheres
Far Clip Plane
Near Clip Plane View Frustum
Guard Band Frustum
A
C
BAccepted
Rejected
Clipped
Screen
![Page 16: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/16.jpg)
Trivially Accepting Polygons
• If you trivially accept a set of polygons, render them with – D3DDP_DONOTCLIP |
D3DDP_DONOTUPDATEEXTENTS
• If you omit this, Direct3D will clip test to guard band for you
• If you must clip a set of polygons that straddle both the view and guard band frustums, clip them to the view frustum
![Page 17: Guard Band Clipping](https://reader035.vdocument.in/reader035/viewer/2022062519/5681527d550346895dc0ab1e/html5/thumbnails/17.jpg)
Detecting a Guard Band
• Call the DIRECT3DDEVICE3 interface GetCaps method to get the guard band extents
• hr = device->GetCaps( &aD3DHWDevDesc, &aD3DSWDevDesc );
• aD3DHWDevDesc.dvGuardBandLeft;• aD3DHWDevDesc.dvGuardBandRight;• aD3DHWDevDesc.dvGuardBandTop;• aD3DHWDevDesc.dvGuardBandBottom;
• These extents will all be set to 0 to indicate no guard band support