occlusion query. content occlusion culling collision detection (convex) etc. fall 20132

19
Occlusion Query

Upload: della-parsons

Post on 03-Jan-2016

234 views

Category:

Documents


1 download

TRANSCRIPT

Occlusion Query

Content

• Occlusion culling

• Collision detection (convex)

• Etc.

Fall 2013 2

Fall 2013 3

Modern Occlusion Culling

• Support from hardware would be nice– Want an “occlusion test”: would this polygon

be visible if I rendered it?– How could you use such a test?

• Test portal polygons before rendering adjacent cell

• Test object bounding boxes before rendering object

hiddendon’t render

Fall 2013 4

Modern Occlusion Culling

• GL_ARB_OCCLUSION_QUERY is the solution– Non-blocking query

• “Is this occlusion query done yet?”• Multiple queries in flight

– Returns number of fragments visible

• Note: can actually render object or not• Still lots of issues for efficient culling

Fall 2013 5

Overview

• Main usage: determine visibility of an object– Render major occluders first; perform an

occlusion query for the bounding box of each detail object in the scene

– Encapsulate each query in a “query object” that allow applications to issue many queries before asking for the result of any one

Fall 2013 6

API• Query object

– Contain one piece of state (integer result)– Active query

• API Summary– GenQueries (n, *ids); DeleteQueries (n, *ids)– IsQuery (id)– BeginQuery (target,id); EndQuery (target)

• Target: SAMPLES_PASSED

– GetQueryObjectiv (id,QUERY_RESULT,*params)

– Asynchronous query: QUERY_RESULT_AVAILABLE

Fall 2013 7

Example

Asynchronous query; not “stop-and-wait”

Fall 2013 8

Occlusion Culling (ref)

1. Render every object's bounding mesh2. For every object:

a. Begin queryb. Re-render the bounding meshc. End queryd. Retrieve occlusion query data. If the pixels

visible are greater than zero, the object should be rendered. Otherwise, the object should be occluded from rendering.

Fall 2013 9

Demo Program

First pass: render scene into depth buffer

Second pass: render scene to queryDepth test: GL_LEQUAL

Get query results

Ex: Occlusion Culling

Fall 2013 10

Fall 2013 11

Fall 2013 12

What good is it to know the number of samples visible

• Objects that are visible but cover only a very small number of pixels can be skipped at a minimal reduction of image quality.

• Knowing exactly how many pixels an object might cover may help the application decide which level-of-detail model should be used. If only a few pixels are visible, a low-detail model may be acceptable.

• "Depth peeling" techniques, such as order-independent transparency, need to know when to stop rendering more layers; it is difficult to determine a priori how many layers are needed. A boolean result allows applications to stop when more layers will not affect the image at all, but this will likely result in unacceptable performance. Instead, it makes more sense to stop rendering when the number of pixels in each layer falls below a given threshold.

• Occlusion queries can replace glReadPixels of the depth buffer to determine whether (for example) a light source is visible for the purposes of a lens flare effect or a halo to simulate glare. Pixel counts allow you to compute the percentage of the light source that is visible, and the brightness of these effects can be modulated accordingly.

Other Uses for Occlusion Queries

– Approximate culling

– LOD size estimation

– Lens flare effects

– Collision detection (next page)

Fall 2013 13

GPUCD – Convex objects

Fall 2013 14

THE NINE CASES IN WHICH A RAY MAY INTERSECT TWO CONVEX OBJECTS, A AND B.

collision

Two-Pass Algorithm

• First pass:– Render A to depth buffer (less-equal)– Change depth test to greater-than– Render B with occlusion queryif nothing is visible, either B is fully in front of

A, or no B [cases 9 & 3 & 1]

• Second pass: – switch roles of A & B [cases 4 & 2]

• All other cases: A & B intersectFall 2013 15

Ex: Two-Pass Algorithm

Fall 2013 16

(a) Initial depth buffer

(b) Render A to depth buffer; test B

(c) Render B to depth buffer; test A

Fall 2013 17

Fall 2013 18

Result

Fall 2013 19