Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Shader usage is large games

  1. #1
    Junior Member Newbie
    Join Date
    Aug 2012
    Posts
    4

    Shader usage is large games

    Hello,

    I have been learning the GLSL language recently and all the tutorials always contain one shader program, one vertex shader and one fragment shader. Now as a somewhat experience game dev (not so much opengl) I know that in complex games there is a need for more complex systems. Systems were different objects need different shaders. For example one object may have normal mapping another one may not and have transparency mapping and so on.

    I have worked with Unity and Unreal and both of them have a system were each material has a shader specific for it. In my mind things are getting more complicated because in a deferred shading situation there would be a need to have multiple shaders making each pass and then another combining all the passes. Then if post processing is required another shader needs to act upon the final renderbuffer.

    Now my little brain is very confused as to how this should all work together in unison.

    So my question, and I know its a bit broad, how are shaders used in large, complex games to render lots of different things lots of different ways? Are many different shaders used? Are many different programs used? I have been told that swapping shader programs at runtime is very costly so what other alternative is there?

    Thank you!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,109
    Your right it is a complex question - if you solve it well your game will run fast - if not it will run slow. That is why Unreal charge so much money for their engine

  3. #3
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,126
    Quote Originally Posted by Peripheralgames View Post
    Are many different programs used? I have been told that swapping shader programs at runtime is very costly so what other alternative is there?
    Yeah, it's costly if you do it hundreds or thousands of times (cost varies by CPU+GPU combination). So you try to minimize the number of different shader programs you need, and you try to render the stuff on the screen that uses the same shader program (and textures, etc.) together. The latter is called "state sorting" (websearch on it in combo with OpenGL or Direct3D). In general, you try to sort or bin objects with the same or similar "GL state" together to avoid wasting cycles reconfiguring the GPU rather than blasting triangles.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •