Pomnico
2008-06-28 08:36:00 UTC
Hi,
Recently while implementing my GFX engine (D3D9, PS 3.0, VS 3.0) I came to
the point where I'm stuck and can not figure out what to do.
I wanted to perform picking 2D / 3D objects by 2D space coordinates using
the GPU (both picking by point or by a rectangular area).
At first my idea was to render each element that has not been discarded by
simple CPU calculations to the original render target (the one that is tested
for picking / hit) with clipping rectangle set to pint or input area of
picking.
The pixel shader used to this operation was to check if output pixel color's
alpha value is non-zero (to discard situations where someone is hitting a
point on a transparent area of 2D surface - to handle properly tests for 2D
buttons with irregular shapes for example) and write some information to
parameters (so they can be retrieved later) about:
- if hit has succeeded
- distance from eye-point (for 3D tests)
- position of hit in object space)
Next, after rendering is performed, I wanted to read this data and based on
it decide if further search has to be done, or not, but that doesn't matter
right now.
I though that this is ideal solution - pixel shader will not be run for
elements outside the clip plane (and even if I could clamp them inside the
pixel shader), I could use the same pixel shader for testing single point
picking and area picking.
Unfortunately, I've discovered, that there is no way to retrieve data
calculated inside the pixel shader other than by target render target.
Is there any way to perform above operations inside the GPU, or should I
give up this idea and use CPU only. I would like to use the GPU however, as
even if counting hit by single point can be easy performed inside the CPU,
performing this for whole area will be devastating for performance.
Maybe there is a way to perform such operation and write result to some
buffer treated as render target? I'd really apreciate any comment on this,
even saying that it is not possible.
Recently while implementing my GFX engine (D3D9, PS 3.0, VS 3.0) I came to
the point where I'm stuck and can not figure out what to do.
I wanted to perform picking 2D / 3D objects by 2D space coordinates using
the GPU (both picking by point or by a rectangular area).
At first my idea was to render each element that has not been discarded by
simple CPU calculations to the original render target (the one that is tested
for picking / hit) with clipping rectangle set to pint or input area of
picking.
The pixel shader used to this operation was to check if output pixel color's
alpha value is non-zero (to discard situations where someone is hitting a
point on a transparent area of 2D surface - to handle properly tests for 2D
buttons with irregular shapes for example) and write some information to
parameters (so they can be retrieved later) about:
- if hit has succeeded
- distance from eye-point (for 3D tests)
- position of hit in object space)
Next, after rendering is performed, I wanted to read this data and based on
it decide if further search has to be done, or not, but that doesn't matter
right now.
I though that this is ideal solution - pixel shader will not be run for
elements outside the clip plane (and even if I could clamp them inside the
pixel shader), I could use the same pixel shader for testing single point
picking and area picking.
Unfortunately, I've discovered, that there is no way to retrieve data
calculated inside the pixel shader other than by target render target.
Is there any way to perform above operations inside the GPU, or should I
give up this idea and use CPU only. I would like to use the GPU however, as
even if counting hit by single point can be easy performed inside the CPU,
performing this for whole area will be devastating for performance.
Maybe there is a way to perform such operation and write result to some
buffer treated as render target? I'd really apreciate any comment on this,
even saying that it is not possible.