Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Christoph

Occlusion Culling

This topic is 5216 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Aloha, I'm using an occlusion query on my terrain engine to decide whether the sun billboard is visible or not. This is the important code:
Query = New Query(d3dDev, QueryType.Occlusion)

Query.Issue(IssueFlags.Begin)
d3dDev.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Sun)
Dim i As Integer = Query.GetOcclusionData(False)
Query.Issue(IssueFlags.End)
The return value (i) is always 125372944, except for the first frame, when it's 1238784. There is no difference between a sun which is totally covered by terrain and one which is completely visible. What is more, the query result doesn't even react on settings like
d3dDev.RenderState.ZBufferFunction = Compare.Always
or
d3dDev.RenderState.ZBufferFunction = Compare.Never
Also no change when I use Query.GetOcclusionData(True)... Does anybody have an idea? Thanks a lot. [edited by - Christoph on June 1, 2004 11:44:09 AM]

Share this post


Link to post
Share on other sites
Advertisement
I have now tried about four hours to fix the problem.
But I can change whatever I want (for example the z-buffer settings or the amount of rendered triangles) - the query always returns the same value (12547944). Why doesn''t this work?

Share this post


Link to post
Share on other sites
Aha! An occlusion query topic! Check out this site. There, you will find an article on hardware occlusion culling.

Your problem lies in the fact that occlusion queries are asyncronous, meaning the call actually returns before the hardware is finshed. This is to maintain parallelism and to avoid stalling the CPU, waiting for the GPU.

However, in some cases (like yours, perhaps), you need the data right away. You need to stall the CPU. So, just throw the GetData() call into a while loop, like this:
 while (d3dQuery->GetData((void *) &pixelsVisible, sizeof(DWORD),D3DGETDATA_FLUSH) == S_FALSE); 
Note that this is C++, but it should be pretty much the same.


Dustin Franklin
Mircrosoft DirectX MVP

Share this post


Link to post
Share on other sites
Thanks a lot for your answer. But I don't find an equivalent for GetData in .NET. This is what I'm doing:


Query = New Query(d3dDev, QueryType.Occlusion)
Query.Issue(IssueFlags.Begin)
d3dDev.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, Sun)Query.Issue(IssueFlags.End)


Now should come a while loop which checks if the query is ready.
But the .NET query object only supplies me with these functions which could be useful:

GetEventData (Boolean)
GetOcclusionData (Integer)

GetEventData is always FALSE. And GetOcclusionData is a static value. As I consider it, I have no chance of using the query properly... However, I suppose that GetEvent should work.
Has anybody had the same problem?


[edited by - Christoph on June 1, 2004 4:40:12 PM]

Share this post


Link to post
Share on other sites
I don''t have the Managed 2003 Docset, so right now I''m looking at the Summer Update 2004 Beta docs. Check out the GetData( Type *returnDataType, bool flush, bool *dataReturned) function. It looks as if the last parameter will hold if the query has returned valid data or not. If the 2003 sdk doesn''t have this particular function, the 2004 sdk will.

However, there is probably another way. The occlusion query should return the number of pixels that are visible. You may be able to determine if this value is valid or not by checking if it''s less that the possible pixels on screen, depending on your resolution. For example:
Resolution - 1024x768 = 786,432 total pixels
If the query spits out a negative value or a value greater than that, then you know it isn''t ready yet. In that case, keep looping. Eventually (most likely < 1ms), it will give you a valid result.

Share this post


Link to post
Share on other sites
hm, the problem is that the query always returns a gigantic value or else (if I don''t use Issue_Begin) a negative one. So it never seems to be ready.

Share this post


Link to post
Share on other sites
Yes, that is not the problem (I have a Radeon 9800). I think the SDK doesn''t really support queries in the 2003 version, because I have heard of other people having problems with them. But there is no solution on the whole internet...

Share this post


Link to post
Share on other sites
quote:
Original post by Christoph
I think the SDK doesn''t really support queries in the 2003 version.
The 2003 Summer Update SDK definetly supports occlusion queries

At least the unmanaged runtimes do. However, to check, go to that website (this one) and download the occlusion query demo. If it works, then it''s either a problem with your code or the managed runtime. If it doesn''t work, then it''s a problem with your card (it shouldn''t be, I have both a 9600xt and 9800xt, and it works on both)

Share this post


Link to post
Share on other sites
I really appreciate your attempts to help me...
But your demo is running perfectly and my code isn''t wrong. I have implemented a simple query in the BasicD3D-Demo for VB.NET by Jack Hoxley. Yet, it doesn''t work here, either.
Take a look at the following post:

http://www.flipcode.com/cgi-bin/msg.cgi?showThread=00009874&forum=3dtheory&id=-1

The 2. and 4. answer by Chromex describe exactly my problem. He seems to have solved it by using GetEventData (which keeps on returning false). But I don''t know how he has realized it in detail....

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!