0

(C++) The title pretty much sums up it all;

I want to let a texture (or a sprite, or whatever) of a light be rendered in front of everything if a certain point in the 3D space is not hidden behind something else.

How do I do that? I can render it over everything by disabling the Zbuffer temporarily during the drawing process, but I don't know how to check if the point is being hidden.

Do I have to calculate some sort of collision between the point and the camera? Or will some kind of sprite setup make the trick?

4

1 回答 1

1

If I understand your question, you want to render a 2D image in 3D space - with all the appropriate depth buffering.

I would use a "billboard". Just render a simple quad in 3D space - making sure it's pointed at the viewer - and apply the "light" texture to it. You'll want to enable alpha blending, otherwise you'll just see a big square with a picture plastered on it - presumably not what you are looking for.

Another approach - that would probably be more work, but give more control - would be manually rendering or not rendering each pixel on the back buffer using a pixel shader. This kind of "blending" is explained pretty simply in Frank Luna's DirectX 9 book.

Sorry, I see now the crux of your problem was about calculating visibility, not how to render a billboard.

If your scene is simple enough, "manually calculating visibility" might just be comparing the distance from the camera of your test point and one or two other objects.

Otherwise, I think your on the right track with the ZBuffer. Manually calculate the depth of the test point (normalizing from 0.0 to 1.0 based on how the View Frustum is defined), project it onto screen space and compare that value to the value in the ZBuffer (at the same projected screen space coordinates). If your calculated depth value is less than the value in the ZBuffer, it's visible.

That's really the only general way I can think of to determine the visibility of a single 3D point.

Hope that helps.

于 2012-09-26T17:43:53.490 回答