• Advertisement

Jessie Blair

  • Content count

  • Joined

  • Last visited

Community Reputation

106 Neutral

About Jessie Blair

  • Rank
  1. Issues with Occlusion Queries

    @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?
  2. 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.
  • Advertisement