[Urgent] Depth buffer based occlusion queries?

Started by
21 comments, last by Leo_E_49 18 years, 7 months ago
Quote:What if I do it on a low resolution texture, say 1/4 the screen size, it would still give good results if done that way. Although, I'm sure it would be a lot slower than the hardware test, could it work real time? Would it be possible to tally the pixels with a pixel shader somehow?


It would still be slow and it would give you exactly the same results as if you did a hardware based occlusion query.

And you can't tally them in a PS.
Advertisement
Quote:Original post by Cypher19
Quote:Original post by superpig
No.


As hilariously rude as that was


What? He asked a question, I answered it. [grin]

Quote:And you can't tally them in a PS.
Sure you can. Render an 0x01010101 quad into a render target the same size as your source image, having it tested against the depth/stencil the way you want. Then render a textured quad using your MxN source image and a 4x4 render target. The rasterizer should generate 16 fragments to be run through the available pipelines, hopefully all at the same time. For each fragment, you run a program which loops over a subrectangle of the source image, reads from the source image and adds it to a running total. That total gets written out as the result. A quick second pass can turn that 4x4 render target into a single value.

Alternatively you could render a textured triangle for each source texel, blending them all additively (as a pixel that passed the test is 0x01 and a pixel that did not is 0x00) and you should get a tally.

You hit problems if the tallies exceed 255 though.

As far as doing this on the PS2 goes... I'm afraid I don't know enough about the PS2's hardware to really say, but from what little I know I think you're SOL. Reading the surface back from video memory and counting the results is probably your only option.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

Quote:Original post by superpig
Quote:And you can't tally them in a PS.
Sure you can. Render an 0x01010101 quad into a render target the same size as your source image, having it tested against the depth/stencil the way you want. Then render a textured quad using your MxN source image and a 4x4 render target. The rasterizer should generate 16 fragments to be run through the available pipelines, hopefully all at the same time. For each fragment, you run a program which loops over a subrectangle of the source image, reads from the source image and adds it to a running total. That total gets written out as the result. A quick second pass can turn that 4x4 render target into a single value.


Alternatively you could render a textured triangle for each source texel, blending them all additively (as a pixel that passed the test is 0x01 and a pixel that did not is 0x00) and you should get a tally.

okay, i guess that'll work. It's still shit slow compared to just getting an occlusion query though. *shrugs*
Quote:
As far as doing this on the PS2 goes... I'm afraid I don't know enough about the PS2's hardware to really say, but from what little I know I think you're SOL. Reading the surface back from video memory and counting the results is probably your only option.


I've heard some people describe the PS2 as a "software renderer with some good vertex calculators", so that seems like a plausible option.
Quote:Original post by Cypher19
Quote:Original post by superpig
Quote:And you can't tally them in a PS.
Sure you can. Render an 0x01010101 quad into a render target the same size as your source image, having it tested against the depth/stencil the way you want. Then render a textured quad using your MxN source image and a 4x4 render target. The rasterizer should generate 16 fragments to be run through the available pipelines, hopefully all at the same time. For each fragment, you run a program which loops over a subrectangle of the source image, reads from the source image and adds it to a running total. That total gets written out as the result. A quick second pass can turn that 4x4 render target into a single value.

Alternatively you could render a textured triangle for each source texel, blending them all additively (as a pixel that passed the test is 0x01 and a pixel that did not is 0x00) and you should get a tally.

okay, i guess that'll work. It's still shit slow compared to just getting an occlusion query though. *shrugs*
Oh, totally agreed. If you've got occlusion queries, use them.

Quote:
Quote:
As far as doing this on the PS2 goes... I'm afraid I don't know enough about the PS2's hardware to really say, but from what little I know I think you're SOL. Reading the surface back from video memory and counting the results is probably your only option.


I've heard some people describe the PS2 as a "software renderer with some good vertex calculators", so that seems like a plausible option.
The fillrate's insane though. Perhaps using the render-many-primitives approach would be fast enough... generate those primitives on VU1 and render them all into a single pixel which you read back. As noted though, you have that 255 limitation.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I did a search and someone here (Yann I think) wrote a software renderer to do the same job I want to do in real time. Surely a linear search of a texture for a pixel with a value of 1 would be faster than an entire software renderer? What if I wrote the search in asm? Or is the problem locking or rendering to the texture? Does that take up to much CPU time? What if I put the occlusion query function in another thread and only update the occlusion every 10 frames?
The problem is more going to be getting the image data to the processor that is doing the counting - if your image is in video ram and you're using the general CPU to process it, the image is going to need to be transferred back into memory that the general CPU can access (system RAM). That transfer could be very, very slow.

Richard "Superpig" Fine - saving pigs from untimely fates - Microsoft DirectX MVP 2006/2007/2008/2009
"Shaders are not meant to do everything. Of course you can try to use it for everything, but it's like playing football using cabbage." - MickeyMouse

I see your point.
I read somewhere it's possible to use shaders to create your own depth buffer, by returning the pixel's z component (or something, I only had a glance at the article)? (It was used in shadow map creation) I wonder, if this is true, can it be used for a per pixel occlusion cull in the abovementioned manner?
why can't you just do your query in software, by doing software z-buffer?
instead real geometry you can render just simplified occlusion geometry
should be fast.. if you insist on using hardware you can use trick
where you render bounding geometry with writting to stencil enabled
then test area of stencil where that bounding geometry should exist.
if there are any non zero values it's visible
of course you don't have to read back whole stencil
just portions, say blocks 16x16. if one of them is visible you don't read further and you know it's visible.
anyway, for now i think software solutions would be best.
and there is a way of doing approximate occlusions query without depth buffer but bitmap instead, all you need is properly sorting your geometry.
There! That's my problem! How do you read the stencil to check if it's non-zero (in DirectX and OpenGL)? If I know that, I can implement a per pixel solution!

This topic is closed to new replies.

Advertisement