1
\$\begingroup\$

I have some experience with Blender, but now I am using Xcode 9.2 and OpenGL 4.1 on MacBook Pro. I am also attending a couple of online courses on edX.

I am developing (for fun and as an exercise) a very simple FPS game. I haven't handled collisions, yet, and I am thinking of how to implement projectiles.The question I have about projectiles, when they are actual object and several of them are present simultaneously in the scene, is the following. Is it better, performance-wise, to generate an object for each active projectile or simply reuse the same object but redrawing it several times and with different transformation matrix (passed to the same shader via uniform mat4)?

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

In first-person shooters, ranged weapons are typically divided into at least two categories:

Hitscan - an instantaneous raycast collision test

Projectile - a dynamic object with a finite speed that is updated every frame until collision

Hitscans (what you mean by "abstraction") offer better performance, especially if there are a lot of weapons being used, since the calculation happens immediately and requires no additional objects in the scene. Projectiles on the other hand offer better accuracy at the cost of some performance (for example, some AAA games make use of extremely long range sniper rifles that take things like drag and the bullet trajectory into consideration).

So to answer your question--yes, a common implementation of projectiles is having N number of objects in the scene, and each frame they are moved forward, and a ray from it's previous position is tested to its current position for collision.

And regarding your other question, for projectiles you can improve performance by having the same vertex buffer, shader, and material data, and then binding that and drawing each projectile using a transform matrix passed to the shader.

I recommend you start with a hitscan weapon and also try projectile weapons, it's pretty fun :)

\$\endgroup\$
3
  • \$\begingroup\$ Thanks a lot! I imagine that avoiding to duplicate objects, in general, improves performance. However, in the few videos I have watched on youtube it seemed they use the other approach and I couldn't understand why. Maybe because the were using older versions of OpenGL. If you could suggest any updated tutorial I would appreciate. Thank you again. \$\endgroup\$
    – Antonio_IT
    Mar 18, 2018 at 13:47
  • \$\begingroup\$ When you want to improve performance, just keep in mind you should reduce the number of times you bind new shaders and textures (e.g., sort your objects by shader/texture data and draw every object instance that uses that "material" data in a loop, hence reducing the number of times you swap the GPU resources). This site is without a doubt the best OpenGL tutorial around: learnopengl.com \$\endgroup\$ Mar 19, 2018 at 2:37
  • \$\begingroup\$ Thank you. I have learnt already a lot on that website, although I couldn't use the same libraries. For instance, I didn't manage to install SOIL, and I use "eigen" for math, just to follow what I am learning on edX as well. And I agree it is the best tutorial. \$\endgroup\$
    – Antonio_IT
    Mar 19, 2018 at 21:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .