How to use 2 types of shaders in one application? For example, the first shader is responsible for drawing the locomotive (normal polygons, taking into account normals and textures), and the second is responsible for the smoke, while working with a particle system (pixel sprites). Do you need to do two shader programs in such cases and switch using UseProgram () or do you need to do branches in the shaders themselves?

  • It is possible and so. - Kromster

1 answer 1

Yes, you can switch between shaders using the glUseProgram(); command glUseProgram(); you create 2 or more shader programs and before drawing the shape you install the desired shader.
switch between the drawing algorithms in the shader itself is not necessary, it will slow down, because checks will be performed for each vertex, and even worse for each pixel.

  • @Kromster, the answer added. - Qwertiy 2:44 pm