• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Jessie Blair

Issues with Occlusion Queries

4 posts in this topic

Greetings!

I'm having trouble getting Occlusion Queries to work properly in XNA. I can't tell if it's because of the sheer number of potential queries, or if I'm doing something incorrectly. A typical scene in my current tests includes around 15k cubes.

With occlusion queries off, and using only frustum culling, I can get 60fps (limited by v-sync) when looking away from the scene, and about 12 fps when viewing all cubes at once.

When I start using occlusion queries in addition to frustum culling, my max fps is about 10fps no matter what is on the screen currently, and I have the additional problem of cubes disappearing permanently once they are occluded. If I sort the models by distance, the fps drops to about 5.

My Draw phase is as below:

[source lang="csharp"] //models.Sort(delegate(BasicModel m1, BasicModel m2) { return m1.Distance.CompareTo(m2.Distance); });

modelsDrawn = 0;
occluded = 0;
culled = 0;

lastOcclusionCheck++;

foreach (BasicModel m in models)
{
if (!firstDraw && m.Query.IsComplete)
m.IsOccluded = (m.Query.PixelCount == 0);

m.Query.Begin();
if (Game1.camera.IsInView(m.BoundingBox) && m.Distance < 65536)
{
m.IsCulled = false;

if (!m.IsOccluded)
{
GraphicsDevice.BlendState = BlendState.Opaque;
if (m.IsTranslucent)
GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;
else
GraphicsDevice.DepthStencilState = DepthStencilState.Default;

m.Draw(Game1.camera);
modelsDrawn++;
}
else
{
if (lastOcclusionCheck > 2)
{
lastOcclusionCheck = 0;
DrawTest(m.PrimitiveList);
}
occluded++;
}
}
else
{
m.IsCulled = true;
m.IsOccluded = false;
culled++;
}
m.Query.End();
}

if (firstDraw)
firstDraw = false;[/source]

The DrawTest() Method is this:
[source lang="csharp"] void DrawTest(VertexPositionColor[] primitiveList)
{
GraphicsDevice.BlendState = blendState;
GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead;

lineEffect.World = Matrix.Identity;
lineEffect.View = Game1.camera.View;
lineEffect.Projection = Game1.camera.Projection;
lineEffect.TextureEnabled = false;

foreach (EffectPass pass in lineEffect.CurrentTechnique.Passes)
{
pass.Apply();
this.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, primitiveList, 0, 8, boundingBoxIndices, 0, 12);
}
}[/source]

I have been failing at fixing this problem for over a week now, though I have managed to improve it. Previously, I was at a max FPS of 2, which makes me cry inside. My hardware is 2.8GHz i7, 16GB ram, radeon 6700 series 1GB vram.

Thank you for any help in advance.
0

Share this post


Link to post
Share on other sites
Are only the occlusion test models cubes or are the actual models cubes as well?

Speed wise, occlusion queries only really make sense if the cost of doing the query is a lot less than the cost of just drawing the thing(s) it represents in the first place. For example, doing an occlusion query where you draw a simple bounding box (very cheap) in order to check if you need to draw an entire city block (very expensive if the geometry is complicated) is probably a good trade-off. Doing an occlusion query where you draw a single cube in order to avoid drawing another single cube, all of the above repeated up to 15,000 times, is probably not going to be effective. Even if you have more complicated models the sheer overhead of executing thousands of occlusion queries could make the speed suffer.

If you are trying for speed when looking at the entire scene, I would first say to look into an instancing strategy to achieve better batching. 15,000 draw calls is going to be inherently slow even if you are drawing simple things. Getting occlusion queries right is tricky. If you still want to do the occlusion queries, it would probably be more worthwhile to do 1 occlusion query for a group of [i]many [/i]nearby models, by drawing the group's bounding box -- that way even if the cost of drawing a model is the same as the cost of a query you can potentially spend 1 draw to save 100 draws.

Some other miscellaneous thoughts:[list]
[*]Is there more to your drawing code? It looks like you draw your models inside the occlusion query Begin/End, which doesn't make much sense to me.
[*]You don't want to be making occlusion queries unless you know the object in question is within your view frustum, otherwise the query is doomed from the start.
[*]I'm confused why you are drawing a wireframe for your occlusion test object. You should probably be drawing a solid bounding volume or else you are going to get some cases where the occlusion query reports zero pixels when there really might be some. I can see why you would draw the final objects as wireframes though, just to see if the occlusion tests are actually working.
[*]Might be worth reading what Shawn Hargreaves says in this thread on the XNA forums: [url="http://forums.create.msdn.com/forums/p/6244/33016.aspx"]http://forums.create...6244/33016.aspx[/url]
[/list]
2

Share this post


Link to post
Share on other sites
Does 15k cubes mean there are 15k cube models in your "models" list/array? If so you are most likely limited by the amount of draw calls and not the geometry.
0

Share this post


Link to post
Share on other sites
@SHilbert
I was playing around with hardware instancing before occlusion, but ran into an issue with depth between differing textures. For instance, if I had an instance draw for grass, then for dirt, even if the dirt was occluded by grass, because I called the instance draw second it would draw on top of the grass.

So I moved on to occlusion culling. The idea was to use the bounding box (supposedly simpler than the texture cube) to check whether occlusion was still necessary every few frames, but only after assuming at first that the object is visible, then the actual occlusion would have a latency of 1 frame. I modeled my code after NVidia's example from GPU Gems 3.

I have also considered doing ray-casting from camera to each block, but hoped occlusion queries would be faster because it is native to XNA. Also, I didn't really know where to start with ray-casting.

I am interested in your suggestion for batching multiple cubes in one draw call, but I have found that hard to do using a model. Would it be wiser to just use primitives since I'm only using simple cubes?


@japro
Indeed it does mean I have 15k cubes. It pretty much varies from 10k to 20k with Simplex noise, usually I'm seeing closer to 15k-16k blocks in a 32x32x32 chunk. I am limiting the draw calls to what is visible in the viewing frustum, but with my current method, I'm far from ever achieving the complexity I would like to have, seeing as a single chunk makes the game nearly unplayable.


[Edit]

As an aside, I did move my query begin and end inside the frustum culling, and changed it from checking bounding box to the actual cube and definitely got better results on the accuracy of occlusion. And the framerate is now back up to 60fps when not looking at the chunk, but it's down to 4fps when looking at the entire chunk.

Any advice on instance/batching, or possibly meshing? And do you think ray-casting would be worth a shot? Edited by Jessie Blair
0

Share this post


Link to post
Share on other sites
Forget about occlusion queries in that case. You are limited by draw calls so most likely by the cpu. Adding occlusion queries actually increases the amount of draw calls so is even counterproductive. If you use minecraftesque chunks don't render every single cube. Only render the surface. For that you only insert quads on solid-air interfaces into a vertex buffer. You then get one vertex buffer per chunk and can render it in a single draw call.
1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0