1
\$\begingroup\$

My (simple) game engine has one big fragment shader for the whole scene. Right now, with multiple objects, collision detection and bloom post-processing (4 linear passes) I get frame times of ~18ms at 1080p on my AMD RX550 (2GB) - which is quite okay for me.

But I think that I can squeeze more fps out of my setup. Since increasing the window size dramatically influences the frame times, I figure that the issue might be the fragment shader.

It works a little bit like this:

main()
{
    outputcolor = objectbasecolor; // from uniform
    if(switchForTextureDiffuse > 0) // >0 means "use a texture"
    {
        outputcolor *= texture(uniformTexture, vTextureCoords);
    }

    // the same goes for normal map, specular map and emissive map
    // with the needed calculations only being done if a switch
    // (i.e. switchForNormalMapping > 0) is set to 1.

    for(int i = 0; i < lightcount; i++) // lightcount is a uniform as well
    {
        // do light calculations (dot product, use light color, calculate falloff, etc.)
        // and add the illumination to the color output
    }
}

Now, I know that if/else is no good idea, especially in a fragment shader. But I do not want to rebuild this shader completely from scratch only to find out that the ifs/elses did no harm to my frame times at all.

From your experiences, what really makes the frame times be better?

  1. Use texture compression (like DXT1, DXT5) instead of just uncompressed bitmaps?
  2. Get rid of all ifs and elses by creating a lot of different shaders (like one for only diffuse and normal maps and another shader for using diffuse, normal and specular maps?
  3. Reduce the number of frame buffers for bloom effect (right now I have the normal framebuffer, one for vertical blur and one for horizontal blur) by creating more texture attachments for only one framebuffer?

Point 2 would be a really great heap of work, so I need to be sure that this really has an effect on my frame times. Also, I would have to switch GL programs a lot, because not all of my models have normal or specular maps. And I read that switching render programs also takes a lot of time.

Cheers and thanks for your inputs!

P.S.: I know deferred lighting would also be a huge performance increase if there are many light sources in the scene, but the number of lights will not be > 3.

\$\endgroup\$
  • 2
    \$\begingroup\$ The details of your light calculation are important as well, \$\endgroup\$ – ratchet freak Feb 14 at 9:28