DrawIndexedPrimitives takes 20 to 40 FPS to draw

Started by
27 comments, last by LemonBiscuit 10 years, 1 month ago

Thank you very much for this idea!

I tried to create chunks for my terrain, but it doesn't render the exact way I want. It works pretty great, except for one thing: there are lines between every chunks...

Screen:

http://puu.sh/6MD7M.jpg

Code:

http://pastebin.com/i8i0ajn9

It's been 7 hours I'm on it, and I just can't find it. Help ! sad.png

I see that it's not coming from distance between them, but missing vertices..

Advertisement

Can you fix your code link?

How large are your chunks? If you're using 32x32 chunks, for instance, you'll need each chunk to have 33x33 vertices.

Another option - instead of having to deal with discrete chunks - is to instead have a fixed grid that is just large enough to cover the viewable area, and which moves along with the camera. Then (assuming a heightmap texture) use vertex texture fetch, and calculate the height of the vertex in the vertex shader, sampling from the appropriate point in the heightmap.

Thank you for your answer, I updated my link.

I indeed set 33x33 vertices, but the problem come from getHeights() function I guess.

As you can see I loop to length-1 and width-1 otherwise it crashes (overflow).

What should I do?


As you can see I loop to length-1 and width-1 otherwise it crashes (overflow).

Yeah, that's probably the problem. You need length X width heights in each chunk height data, not (length - 1) X (width - 1).

So of course if your entire map is 512x512 (composed of 32x32 chunks, which is 33x33 vertices), then you'll need 513x513 height points. You can just "clamp" the last row/column of your height map to accommodate for this. So loop to length/width, and then this:

  1. // Get color value (0 - 255)
  2. float amt = heightMapData[(y + offsetX) * oWidth + x + offsetY].R;

becomes

  1. // Get color value (0 - 255)
  2. float amt = heightMapData[Math.Min(y + offsetX, oHeight - 1) * oWidth + Math.Min(x + offsetY, oWidth - 1)].R;

Also note that you don't need a separate index buffer for each chunk. Every chunk's index buffer will be identical, so you just need one.

Aaaaand it works! Thank you very much for your help!

I think I'll manage to get all the things working the way I want now :)

I'm still stuck on one point and I'll need your help, again sad.png

I managed to divide my weightmap (colors associated to textures) for every chunks, but I still have a tiling offset:

http://i.imgur.com/NLmNczt.png

(It is the seperation between two chunks)

Here is the shader: http://pastebin.com/05N7nqSZ

Do you know how I could fix it?

Thank you

Is one of your sampler states not set to wrap or something? I can't tell you how to fix it, but I can tell you how to start diagnosing it. Just have your shader directly output one of your 5 input textures and see which ones have that discontinuity.

Thank you for your always fast answers.

Here are my samplers:

http://pastebin.com/0nCE4nzL

I tried to remove each one one-per-one, but nothing seems to change.

I have to say I followed a tutorial for this part of texturing (as I said before, I'm a newbie with HLSL :( )

If you just output your weightmap, it still has that obvious discontinuity? Then your UV coordinates are wrong.

I can't get them correct, but anyway, now even the normals in the side of the chunks are incorrect (I should get vertices from other chunks to get the normal, etc.) It's getting a little too complex for the little optimization I want to do.. sad.png

I have another idea to optimize my things.

I generate a few bounding boxes all over my map (16 or 32 for instance).

Then I check at each frame which boxes are in view, and I then adapt the amount of vertices to show.

For instance:

If the boundingbox containing the last vertices of my terrain is not in view, then the amount of primitives to draw is the amount of vertices - the amount of vertices contained in the box.

Same thing for the first ones.

This topic is closed to new replies.

Advertisement