Hardware Instancing GLSL snippet

Dear all -

As far as I know, there was no complete GLSL sample in the P3D forum showing how to use Hardware Instancing with texture / lighting / culling with Panda.

Hardware Instancing allows to dramatically increase the number of models displayed at the same time (the model is sent only once to the graphics card). Unfortunately, this method requires you to disable the native panda culling system and to implement your own, if you want to benefit from the HW instancing speed.

For those who may be interested, here is a complete sample including:

  • the Python code
  • the Vertex and Fragment shaders
  • the Interrogate module that can be used for culling through C++ by pressing F1 - this is compiled with VS2015 through the tobspr’s tool P3DModuleBuilder. As you’ll notice, the speed is x2 with C++.
  • the corresponding C++ source code for culling

This code has been tested with Panda3D 1.9.2. It has been adapted from teedee’s original code - [url]Hardware instancing problem with Panda 1.8]- and wezu’s for the fog formula in the FS.

Please feel free to improve that code (there are certainly ways of optimization).
HardwareInstancing_SourceCode.zip (20.5 KB)