Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I was wondering. Suppose I have a 1000 grass meshes. They all have the same material, but I create them separately, because they look slightly different, because they have different heights.

Does my GPU speed up if I only draw one mesh over and over again? Or is only the material switching and uniform setting the main problem?

So: Should I consider going to only one mesh a 1000 times, or is it ok to have a lot of different meshes with only the same material?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

If you are using OpenGL, you can use DrawInstanced. This is useful for cases, where you have one model and want to draw it many times (for example grass). In vertex shader you will get unique ID, and according to this ID you can set per model transformation (for example take it from big array of transformation).

It's really fast and useful. I think in DirectX there will be something similar.

If you want to draw separate (but similar) models with different materials, it will slow your application down. Material switching is not too cheap operation (again - I'm talking about OpenGL).

share|improve this answer
    
@zachamarz: I'm using jMonkeyEngine, which uses LWJGL, which uses OpenGL. I'm not sure if I can call this function. –  Marnix Jun 5 '11 at 19:46
    
@Marnix: It likely encapsulates the call for you. –  DeadMG Jun 5 '11 at 19:58
    
Another option, which may perform even better (given some benchmarks I've seen of how poorly both the ATI and NVIDIA drivers handle instancing in OpenGL) is to just stream all the grass meshes into a single streaming vertex buffer, and making a single draw call. That method will have higher CPU load and more pressure on bus, but may be faster none the less. As always, profile and test any optimization techniques you try. :) –  Sean Middleditch Jun 6 '11 at 21:08
    
If you will try to render lot of meshes in one draw call, you can split these meshes with primitive restart index. It's really easy to use. It's also more effective than lot of drawElements commands. (but I don't know if you can use it with jmonkeyengine :( ) –  zacharmarz Jun 6 '11 at 21:21

You should re-use the same geometry wherever possible. GPUs have hardware support for re-drawing the same meshes with different parameters. Re-using the same geometry means that you don't have to, for example, move the new geometry into the hardware registers, and that sort of thing, and it fundamentally reduces the number of calls to the GPU, which is a big bonus.

share|improve this answer

I'm not sure how it's done but I know you can send material data once for GPU and then ask GPU to draw multiple mesh using it. I know this because GameEngines usually have a flag or group which you can spicify every thing under that group has same texture and this speeds up your game(I'm saying this as written inside the manual) since you pass the material data once for as you say 1000 objects and it seems to be faster.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.